OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / doc / mico / examples / services / relship / simple-test.cc
1 /*
2  *  Test of COSS Relationship Service for MICO
3  *  Copyright (C) 1998-99 Karel Gardas
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *  Send comments and/or bug reports to:
20  *                 mico@informatik.uni-frankfurt.de
21  *  or to my private e-mail:
22  *                 gardask@alpha.inf.upol.cz
23  */
24
25 #include <CORBA.h>
26 #include <time.h>
27 #include <string.h>
28
29 #include <coss/CosRelationships.h>
30 #include <coss/CosGraphs.h>
31 #include <coss/CosContainment.h>
32 #include <coss/CosReference.h>
33 #include <coss/CosGraphsExtension.h>
34 #include "Documents.h"
35 #include "Test.h"
36
37
38 using namespace std;
39
40 int main( int argc, char *argv[] )
41 {
42   //ORB initialization
43   CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "mico-local-orb");
44
45   cout << "Runing all tests\n" << flush;
46
47   CORBA::Boolean exception = FALSE;
48   CORBA::Boolean exception2 = FALSE;
49   CORBA::Boolean exception3 = FALSE;
50   CORBA::Boolean state_good = TRUE;
51   state_good = TRUE;
52
53   // containment
54   cout << "Binding to ContainsRoleFactory ..." << flush;
55   CORBA::ORB::ObjectTag_var 
56     tag2 = CORBA::ORB::string_to_tag ("ContainsRole_impl");
57   CORBA::Object_var 
58   obj10 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
59                      tag2.in());
60   assert (!CORBA::is_nil (obj10));
61   CosRelationships::RoleFactory_var contains_factory; 
62   if (contains_factory = CosRelationships::RoleFactory::_narrow (obj10))
63     cout << "done.\n" << flush;
64   else
65     cout << "ERROR!\n" << flush;
66
67   cout << "Binding to ContainedInRoleFactory ..." << flush;
68   CORBA::ORB::ObjectTag_var 
69     tag3 = CORBA::ORB::string_to_tag ("ContainedInRole_impl");
70   CORBA::Object_var 
71     obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
72                        tag3.in());
73   assert (!CORBA::is_nil (obj11));
74   CosRelationships::RoleFactory_var containedin_factory; 
75   if (containedin_factory = CosRelationships::RoleFactory::_narrow (obj11))
76     cout << "done.\n" << flush;
77   else
78     cout << "ERROR!\n" << flush;
79   
80
81   cout << "Binding to ContainmentFactory ..." << flush;
82   CORBA::ORB::ObjectTag_var 
83     tag11 = CORBA::ORB::string_to_tag ("Containment_impl");
84   CORBA::Object_var 
85     obj30 = orb->bind ("IDL:omg.org/CosRelationships/RelationshipFactory:1.0",
86                        tag11.in());
87   assert (!CORBA::is_nil (obj30));
88   CosRelationships::RelationshipFactory_var containment_factory;
89   if (containment_factory = CosRelationships::RelationshipFactory::_narrow 
90       (obj30))
91     cout << "done.\n" << flush;
92   else
93     cout << "ERROR!\n" << flush;
94    
95
96   // reference
97   cout << "Binding to ReferencesRoleFactory ..." << flush;
98   //CORBA::ORB::ObjectTag_var 
99   tag2 = CORBA::ORB::string_to_tag ("ReferencesRole_impl");
100   //CORBA::Object_var
101   obj10 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
102                      tag2.in());
103   assert (!CORBA::is_nil (obj10));
104   CosRelationships::RoleFactory_var references_factory; 
105   if (references_factory = CosRelationships::RoleFactory::_narrow (obj10))
106     cout << "done.\n" << flush;
107   else
108     cout << "ERROR!\n" << flush;
109
110   cout << "Binding to ReferencedByRoleFactory ..." << flush;
111   //CORBA::ORB::ObjectTag_var 
112   tag3 = CORBA::ORB::string_to_tag ("ReferencedByRole_impl");
113   //CORBA::Object_var 
114   obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
115                      tag3.in());
116   assert (!CORBA::is_nil (obj11));
117   CosRelationships::RoleFactory_var referencedby_factory; 
118   if (referencedby_factory = CosRelationships::RoleFactory::_narrow (obj11))
119     cout << "done.\n" << flush;
120   else
121     cout << "ERROR!\n" << flush;
122   
123
124   cout << "Binding to ReferenceFactory ..." << flush;
125   //CORBA::ORB::ObjectTag_var 
126   tag11 = CORBA::ORB::string_to_tag ("Reference_impl");
127   //CORBA::Object_var 
128   obj30 = orb->bind ("IDL:omg.org/CosRelationships/RelationshipFactory:1.0", 
129                      tag11.in());
130   assert (!CORBA::is_nil (obj30));
131   CosRelationships::RelationshipFactory_var reference_factory;
132   if (reference_factory = CosRelationships::RelationshipFactory::_narrow
133       (obj30))
134     cout << "done.\n" << flush;
135   else
136     cout << "ERROR!\n" << flush;
137
138   
139   // node factory
140   cout << "Binding to NodeFactory ..." << flush;
141   //CORBA::ORB::ObjectTag_var 
142   tag11 = CORBA::ORB::string_to_tag ("Node_impl");
143   //CORBA::Object_var 
144   obj30 = orb->bind ("IDL:omg.org/CosGraphs/NodeFactory:1.0", 
145                      tag11.in());
146   assert (!CORBA::is_nil (obj30));
147   CosGraphs::NodeFactory_var node_factory;
148   if (node_factory = CosGraphs::NodeFactory::_narrow (obj30))
149     cout << "done.\n" << flush;
150   else
151     cout << "ERROR!\n" << flush;
152
153   // figure and text factory
154   cout << "Binding to TextFactory ..." << flush;
155   //CORBA::Object_var 
156   obj30 = orb->bind ("IDL:Documents/TextFactory:1.0");
157   assert (!CORBA::is_nil (obj30));
158   Documents::TextFactory_var text_factory;
159   if (text_factory = Documents::TextFactory::_narrow (obj30))
160     cout << "done.\n" << flush;
161   else
162     cout << "ERROR!\n" << flush;
163
164   cout << "Binding to FigureFactory ..." << flush;
165   obj30 = orb->bind ("IDL:Documents/FigureFactory:1.0");
166   assert (!CORBA::is_nil (obj30));
167   Documents::FigureFactory_var figure_factory;
168   if (figure_factory = Documents::FigureFactory::_narrow (obj30))
169     cout << "done.\n" << flush;
170   else
171     cout << "ERROR!\n" << flush;
172   
173
174   // binding to factories which are need for tests
175
176   cout << "Binding to BaseRoleFactory ..." << flush;
177   //CORBA::ORB::ObjectTag_var 
178   tag2 = CORBA::ORB::string_to_tag ("BaseRole_impl");
179   //CORBA::Object_var 
180   obj10 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
181                      tag2.in());
182   assert (!CORBA::is_nil (obj10));
183   CosRelationships::RoleFactory_var base_factory; 
184   if (base_factory = CosRelationships::RoleFactory::_narrow (obj10))
185     cout << "done.\n" << flush;
186   else
187     cout << "ERROR!\n" << flush;
188
189   cout << "Binding to DerivedRoleFactory 1..." << flush;
190   //CORBA::ORB::ObjectTag_var 
191   tag3 = CORBA::ORB::string_to_tag ("DerivedRole1_impl");
192   //CORBA::Object_var 
193   obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
194                      tag3.in());
195   assert (!CORBA::is_nil (obj11));
196   CosRelationships::RoleFactory_var derived_factory1; 
197   if (derived_factory1 = CosRelationships::RoleFactory::_narrow (obj11))
198     cout << "done.\n" << flush;
199   else
200     cout << "ERROR!\n" << flush;
201   
202   cout << "Binding to DerivedRoleFactory 2..." << flush;
203   //CORBA::ORB::ObjectTag_var 
204   tag3 = CORBA::ORB::string_to_tag ("DerivedRole2_impl");
205   //CORBA::Object_var 
206   obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0", 
207                      tag3.in());
208   assert (!CORBA::is_nil (obj11));
209   CosRelationships::RoleFactory_var derived_factory2; 
210   if (derived_factory2 = CosRelationships::RoleFactory::_narrow (obj11))
211     cout << "done.\n" << flush;
212   else
213     cout << "ERROR!\n" << flush;
214   
215
216   cout << "Binding to TestRelationshipFactory ..." << flush;
217   //CORBA::ORB::ObjectTag_var 
218   tag11 = CORBA::ORB::string_to_tag ("TestRelationship_impl");
219   //CORBA::Object_var 
220   obj30 = orb->bind ("IDL:omg.org/CosRelationships/RelationshipFactory:1.0",
221                      tag11.in());
222   assert (!CORBA::is_nil (obj30));
223   CosRelationships::RelationshipFactory_var test_relationship_factory;
224   if (test_relationship_factory = CosRelationships::RelationshipFactory::
225       _narrow (obj30))
226     cout << "done.\n" << flush;
227   else
228     cout << "ERROR!\n" << flush;   
229
230
231   cout << "Binding to TraversalFactory ..." << flush;
232   CORBA::Object_var obj3 = orb->bind ("IDL:omg.org/CosGraphs/TraversalFactory:1.0");
233   assert (!CORBA::is_nil (obj3));
234   CosGraphs::TraversalFactory_var traversal_factory;
235   if (traversal_factory = CosGraphs::TraversalFactory::_narrow (obj3))
236     cout << "done.\n" << flush;
237   else
238     cout << "ERROR!\n" << flush;
239
240
241   cout << "Binding to GenericCriteriaFactory ..." << flush;
242   obj3 = orb->bind 
243     ("IDL:gnu.org/CosGraphsExtension/GenericCriteriaFactory:1.0");
244   assert (!CORBA::is_nil (obj3));
245   CosGraphsExtension::GenericCriteriaFactory_var criteria_factory;
246   if (criteria_factory = CosGraphsExtension::GenericCriteriaFactory::_narrow 
247       (obj3))
248     cout << "done.\n" << flush;
249   else
250     cout << "ERROR!\n" << flush;
251
252
253   cout << "Checking first level\n";
254
255   cout << "Checking RoleFactory::role_type ()  ..." << flush;
256   //CORBA::InterfaceDef_ptr interface = owner_factory->role_type ();
257   CORBA::InterfaceDef_ptr interface = contains_factory->role_type ();
258   if (!CORBA::is_nil (interface)) {
259     //interface->destroy ();
260     cout << "ok.\n" << flush;
261   }
262   else
263     cout << "error.\n" << flush;
264
265   cout << "Checking RelationshipFactory::relationship_type ()  ..." << flush;
266   //CORBA::InterfaceDef_ptr interface2 = ownership_factory->relationship_type ();
267   CORBA::InterfaceDef_ptr interface2 = containment_factory->relationship_type ();
268   if (!CORBA::is_nil (interface2)) {
269     //interface2->destroy ();
270     cout << "ok.\n" << flush;
271   }
272   else
273     cout << "error.\n" << flush;
274
275   //sleep (1);
276
277   cout << "Checking RoleFactory::create_role ()  ..." << flush;
278   CORBA::Boolean right_role = TRUE;
279
280   CosContainment::ContainsRole_var role1;
281   CosContainment::ContainedInRole_var role2;
282   CosContainment::Relationship_var relship1;
283   Documents::Figure_var fig1;
284   Documents::Figure_var fig2;
285   CosGraphs::Node_var node1;
286   CosGraphs::Node_var node2;
287 #ifdef HAVE_EXCEPTIONS
288   try {
289 #endif
290     fig1 = Documents::Figure::_narrow (figure_factory->create ("fig1.png"));
291     node1 = CosGraphs::Node::_duplicate (node_factory->create_node (fig1));
292     role1 = CosContainment::ContainsRole::_narrow 
293       (contains_factory->create_role (node1));
294 #ifdef HAVE_EXCEPTIONS
295   }  
296   catch (CosRelationships::RoleFactory::RelatedObjectTypeError_catch &ex1)
297     {
298       cout << "RelatedObjectTypeError!\n" << flush;
299       right_role = FALSE;
300     }
301 #endif
302   if (!CORBA::is_nil (role1)) {
303     cout << "ok.\n" << flush;
304   }
305   else
306     cout << "failed.\n";
307
308
309   cout << "Checking Role::related_object ()  ..." << flush;
310   CosGraphs::Node_var tmp_node = CosGraphs::Node::_narrow (role1->related_object ());
311   if (!CORBA::is_nil (tmp_node))
312     cout << "ok.\n" << flush;
313   else {
314     cout << "failed.\n" << flush;
315   }
316
317
318   exception = FALSE;
319   cout << "Checking Role::destroy ()  ..." << flush;
320   role1->destroy ();
321 #ifdef HAVE_EXCEPTIONS
322   try {
323 #endif
324     CORBA::Object_var x = role1->related_object ();
325 #ifdef HAVE_EXCEPTIONS
326   }
327   catch (CORBA::SystemException_catch &ex) {
328     exception = TRUE;
329   }
330 #endif
331   if (exception)
332     cout << "ok.\n" << flush;
333   else {
334     cout << "failed.\n" << flush;
335   }
336
337   exception = FALSE;
338   cout << "Checking RoleFactory::RelatedObjectTypeError exception  ..." 
339        << flush;
340 #ifdef HAVE_EXCEPTIONS
341   try {
342 #endif
343     role1 = CosContainment::ContainsRole::_narrow 
344       (contains_factory->create_role 
345        (Documents::Figure::_duplicate (fig1)));
346 #ifdef HAVE_EXCEPTIONS
347   } catch (CosRelationships::RoleFactory::RelatedObjectTypeError_catch &ex1) {
348     exception = TRUE;
349   }
350 #endif
351
352   if (exception)
353     cout << "ok.\n" << flush;
354   else {
355     cout << "failed.\n" << flush;
356   }
357
358   cout << "Checking RoleFactory::NilRelatedObject exception  ..." << flush;
359   exception = FALSE;
360
361 #ifdef HAVE_EXCEPTIONS
362   try {
363 #endif
364     role1 = CosContainment::ContainsRole::_narrow 
365       (contains_factory->create_role 
366        (CosGraphs::Node::_nil ()));
367 #ifdef HAVE_EXCEPTIONS
368   } catch (CosRelationships::RoleFactory::NilRelatedObject_catch &ex1) {
369     exception = TRUE;
370   }
371 #endif
372   if (exception)
373     cout << "ok.\n" << flush;
374   else {
375     cout << "failed.\n" << flush;
376   }
377   
378
379 #ifdef HAVE_EXCEPTIONS
380   try {
381 #endif
382     fig2 = Documents::Figure::_narrow (figure_factory->create ("fig2.jpg"));
383     node2 = CosGraphs::Node::_narrow 
384       (node_factory->create_node (fig2));
385     role2 = CosContainment::ContainedInRole::_narrow 
386       (containedin_factory->create_role 
387        (node2));
388     
389     role1 = CosContainment::ContainsRole::_narrow
390       (contains_factory->create_role
391        (node1));
392
393 #ifdef HAVE_EXCEPTIONS
394   } catch (CosRelationships::RoleFactory::RelatedObjectTypeError_catch &ex1) {
395     cout << "RelatedObjectTypeError!\n" << flush;
396   }
397 #endif
398
399   assert (!CORBA::is_nil (role1));
400   assert (!CORBA::is_nil (role2));
401   exception = FALSE;
402   
403   cout << "Checking RelationshipFactory::create () ..." << flush;
404   CosRelationships::NamedRoles nr;
405   nr.length (2);
406   nr[0].name = CORBA::string_dup ("ContainsRole");
407   nr[0].aRole = CosRelationships::Role::_duplicate (role1);
408   nr[1].name = CORBA::string_dup ("ContainedInRole");
409   nr[1].aRole = CosRelationships::Role::_duplicate (role2);
410   
411 #ifdef HAVE_EXCEPTIONS
412   try {
413 #endif
414     relship1 = CosContainment::Relationship::_narrow
415       (containment_factory->create (nr));
416 #ifdef HAVE_EXCEPTIONS
417   } 
418   catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
419     cout << "DegreeError exception!!!\n" << flush;
420     cout << "Required degree is " << ex->required_degree << "\n" << flush;
421     relship1 = CosContainment::Relationship::_nil ();
422   } 
423   catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
424     cout << "DuplicateRoleName exception!!!\n" << flush;
425     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
426     for (unsigned int i=0; i<(ex->culprits).length () ; i++) {
427       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
428     }
429     relship1 = CosContainment::Relationship::_nil ();
430   } 
431   catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
432     cout << "UnknownRoleName exception!!!\n" << flush;
433     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
434     for (unsigned int i=0; i< (ex->culprits).length (); i++) {
435       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
436     }
437     relship1 = CosContainment::Relationship::_nil ();
438     cout << "End of catch statement!\n" << flush;
439   }
440 #endif
441   if (!CORBA::is_nil (relship1)) {
442     cout << "ok.\n" << flush;
443   }
444   else {
445     cout << "failed.\n";
446   }
447
448   exception = FALSE;
449   state_good = FALSE;
450   cout << "Checking RelationshipFactory::UnknownRoleName exception  ..." 
451        << flush;
452   nr.length (2);
453   nr[0].name = strdup ("Ha");
454   nr[0].aRole = CosRelationships::Role::_duplicate (role1);
455   nr[1].name = strdup ("ConatinedInRole");
456   nr[1].aRole = CosRelationships::Role::_duplicate (role2);
457   
458 #ifdef HAVE_EXCEPTIONS
459   try {
460 #endif
461     relship1 = CosContainment::Relationship::_narrow 
462       (containment_factory->create (nr));
463 #ifdef HAVE_EXCEPTIONS
464   } 
465   catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
466     cout << "DegreeError exception!!!\n" << flush;
467     cout << "Required degree is " << ex->required_degree << "\n" << flush;
468     exception = TRUE;
469   } 
470   catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
471     cout << "DuplicateRoleName exception!!!\n" << flush;
472     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
473     for (unsigned int i=0; i<(ex->culprits).length () ; i++) {
474       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
475     }
476     exception = TRUE;
477   } 
478   catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
479     //       cout << "UnknownRoleName exception!!!\n" << flush;
480     //       cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" 
481     //       << flush;
482     //       for (int i=0; i< (ex->culprits).length (); i++) {
483     //         cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
484     //       }
485     state_good = TRUE;
486   }
487 #endif
488   if (state_good) {
489     cout << "ok.\n" << flush;
490   }
491   else 
492     cout << "failed.\n" << flush;
493
494
495   exception = FALSE;
496   state_good = FALSE;
497   cout << "Checking RelationshipFactory::DuplicateRoleName exception  ..." 
498        << flush;
499   nr.length (2);
500   nr[0].name = CORBA::string_dup ("ContainsRole");
501   nr[0].aRole = CosRelationships::Role::_duplicate (role1);
502   nr[1].name = CORBA::string_dup ("ContainsRole");
503   nr[1].aRole = CosRelationships::Role::_duplicate (role1);
504  
505 #ifdef HAVE_EXCEPTIONS
506   try {
507 #endif
508     relship1 = CosContainment::Relationship::_narrow
509       (containment_factory->create (nr));
510 #ifdef HAVE_EXCEPTIONS
511   } 
512   catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
513     cout << "DegreeError exception!!!\n" << flush;
514     cout << "Required degree is " << ex->required_degree << "\n" << flush;
515     exception = TRUE;
516   } 
517   catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
518     //       cout << "DuplicateRoleName exception!!!\n" << flush;
519     //       cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n"
520     //            << flush;
521     //       for (int i=0; i<(ex->culprits).length () ; i++) {
522     //         cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
523     //       }
524     state_good = TRUE;
525   } 
526   catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
527     cout << "UnknownRoleName exception!!!\n" << flush;
528     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
529     for (unsigned int i=0; i< (ex->culprits).length (); i++) {
530       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
531     }
532     exception = TRUE;
533     cout << "End of catch statement!\n" << flush;
534   }
535 #endif
536   if (state_good) 
537     cout << "ok.\n" << flush;
538   else
539     cout << "failed.\n" << flush;
540
541
542   exception = FALSE;
543   state_good = FALSE;
544   cout << "Checking RelationshipFactory::DegreeError exception  ..." << flush;
545   nr.length (3);
546   nr[0].name = CORBA::string_dup ("ContainsRole");
547   nr[0].aRole = CosRelationships::Role::_duplicate (role1);
548   nr[1].name = CORBA::string_dup ("ContainedInRole");
549   nr[1].aRole = CosRelationships::Role::_duplicate (role2);
550   nr[2].name = CORBA::string_dup ("ContainedInRole");
551   nr[2].aRole = CosRelationships::Role::_duplicate (role2);
552
553 #ifdef HAVE_EXCEPTIONS
554   try {
555 #endif
556     relship1 = CosContainment::Relationship::_narrow 
557       (containment_factory->create (nr));
558 #ifdef HAVE_EXCEPTIONS
559   } 
560   catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
561     //       cout << "DegreeError exception!!!\n" << flush;
562     //       cout << "Required degree is " << ex->required_degree << "\n" << flush;
563     state_good = TRUE;
564   } 
565   catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
566     cout << "DuplicateRoleName exception!!!\n" << flush;
567     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
568     for (unsigned int i=0; i<(ex->culprits).length () ; i++) {
569       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
570     }
571     exception = TRUE;
572   } 
573   catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
574     cout << "UnknownRoleName exception!!!\n" << flush;
575     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
576     for (unsigned int i=0; i< (ex->culprits).length (); i++) {
577       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
578     }
579     exception = TRUE;
580     cout << "End of catch statement!\n" << flush;
581   }
582 #endif
583
584   if (state_good) 
585     cout << "ok.\n" << flush;
586   else
587     cout << "failed\n" << flush;
588
589
590   exception = FALSE;
591   state_good = FALSE;
592   cout << "Checking RelationshipFactory::RoleTypeError exception  ..." 
593        << flush;
594   nr.length (2);
595   nr[0].name = CORBA::string_dup ("ContainsRole");
596   nr[0].aRole = CosRelationships::Role::_duplicate (role1);
597   nr[1].name = CORBA::string_dup ("ContainedInRole");
598   nr[1].aRole = CosRelationships::Role::_duplicate (role1);  // ContainedInRole
599
600 #ifdef HAVE_EXCEPTIONS 
601   try {
602 #endif
603     relship1 = CosContainment::Relationship::_narrow
604       (containment_factory->create (nr));
605 #ifdef HAVE_EXCEPTIONS
606   } 
607   catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
608     cout << "DegreeError exception!!!\n" << flush;
609     cout << "Required degree is " << ex->required_degree << "\n" << flush;
610     exception = TRUE;
611   } 
612   catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
613     cout << "DuplicateRoleName exception!!!\n" << flush;
614     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
615     for (unsigned int i=0; i<(ex->culprits).length () ; i++) {
616       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
617     }
618     exception = TRUE;
619   } 
620   catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
621     cout << "UnknownRoleName exception!!!\n" << flush;
622     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
623     for (unsigned int i=0; i< (ex->culprits).length (); i++) {
624       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
625     }
626     exception = TRUE;
627     cout << "End of catch statement!\n" << flush;
628   }
629   catch (CosRelationships::RelationshipFactory::RoleTypeError_catch &ex) {
630     //      cout << "RoleTypeError exception!!!\n" << flush;
631     //      cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
632     //      for (int i=0; i< (ex->culprits).length (); i++) {
633     //        cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
634     //      }
635     state_good = TRUE;
636   }
637 #endif
638
639   if (state_good)
640     cout << "ok.\n" << flush;
641   else
642     cout << "failed.\n" << flush;
643
644
645   exception = FALSE;
646   state_good = FALSE;
647   cout << "Checking RelationshipFactory::MaxCardinalityExceeded exception  ..."
648        << flush;
649   nr.length (2);
650   nr[0].name = CORBA::string_dup ("ContainsRole");
651   nr[0].aRole = CosRelationships::Role::_duplicate (role1);
652   nr[1].name = CORBA::string_dup ("ContainedInRole");  // will be twice
653   nr[1].aRole = CosRelationships::Role::_duplicate (role2);
654
655 #ifdef HAVE_EXCEPTIONS
656   try {
657 #endif
658     relship1 = CosContainment::Relationship::_narrow 
659       (containment_factory->create (nr));
660 #ifdef HAVE_EXCEPTIONS
661   } 
662   catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
663     cout << "DegreeError exception!!!\n" << flush;
664     cout << "Required degree is " << ex->required_degree << "\n" << flush;
665     exception = TRUE;
666   } 
667   catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
668     cout << "DuplicateRoleName exception!!!\n" << flush;
669     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
670     for (unsigned int i=0; i<(ex->culprits).length () ; i++) {
671       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
672     }
673     exception = TRUE;
674   } 
675   catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
676     cout << "UnknownRoleName exception!!!\n" << flush;
677     cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
678     for (unsigned int i=0; i< (ex->culprits).length (); i++) {
679       cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
680     }
681     exception = TRUE;
682     cout << "End of catch statement!\n" << flush;
683   }
684   catch (CosRelationships::RelationshipFactory::MaxCardinalityExceeded_catch &ex) {
685     //       cout << "MaxCardinalityExceeded exception!!!\n" << flush;
686     //       cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n" << flush;
687     //       for (int i=0; i< (ex->culprits).length (); i++) {
688     //         cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
689     //       }
690     state_good = TRUE;
691   }
692 #endif
693
694   if (state_good)
695     cout << "ok.\n" << flush;
696   else
697     cout << "failed.\n" << flush;
698
699
700   cout << "Checking Role::get_relationships ()  ..." << flush;
701   CosRelationships::RelationshipIterator_var 
702     iterator = CosRelationships::RelationshipIterator::_nil ();
703   CosRelationships::RelationshipHandles* rel_handles;
704   rel_handles = NULL;
705   role1->get_relationships (3, rel_handles, iterator);
706   if ((rel_handles != NULL) && (CORBA::is_nil (iterator))) {
707     rel_handles = NULL;
708     iterator = CosRelationships::RelationshipIterator::_nil ();
709     role1->get_relationships (0, rel_handles, iterator);
710     if (rel_handles->length () == 0) 
711       if (!CORBA::is_nil (iterator))
712         cout << "ok.\n" << flush;
713       else
714         cout << "error3!\n" << flush;
715     else
716       cout << "error2!\n" << flush;
717   }
718   else
719     cout << "error!\n" << flush;
720
721   cout << "Checking RelationshipIterator::next_n ()  ..." << flush;
722   iterator->next_n (10, rel_handles);
723   if (rel_handles->length () == 1 && 
724       ( (*rel_handles)[0].the_relationship->is_identical (relship1)))
725     cout << "ok.\n" << flush;
726   else
727     cout << "error!\n" << flush;
728   iterator->destroy ();
729
730   cout << "Checking RelationshipIterator::next_one ()  ..." << flush;
731   CosRelationships::RelationshipHandle* rel_handle;
732   role1->get_relationships (0, rel_handles, iterator);
733   iterator->next_one (rel_handle);
734   if (rel_handle->the_relationship->is_identical (relship1))
735     cout << "ok.\n" << flush;
736   else
737     cout << "error!\n" << flush;
738
739   // testing second level of MICO RS
740   cout << "Checking second level\n";
741
742   assert (!CORBA::is_nil (text_factory));
743   assert (!CORBA::is_nil (figure_factory));
744
745   Documents::Text_var text = text_factory->create_with_file 
746     (CORBA::string_dup ("MICO Relationship Service."), 
747      CORBA::string_dup ("thesis.tex"));
748
749   Documents::Figure_var obr1 = figure_factory->create_with_file 
750     (CORBA::string_dup ("obr1"), CORBA::string_dup ("obr1.eps"));
751   Documents::Figure_var obr2 = figure_factory->create_with_file 
752     (CORBA::string_dup ("obr2"), CORBA::string_dup ("obr2.eps")); 
753   Documents::Figure_var obr3 = figure_factory->create_with_file 
754     (CORBA::string_dup ("obr3"), CORBA::string_dup ("obr3.eps"));
755
756   Documents::Figure_var obr4 = figure_factory->create_with_file 
757     (CORBA::string_dup ("obr4"), CORBA::string_dup ("obr4.eps"));
758   Documents::Figure_var obr5 = figure_factory->create_with_file 
759     (CORBA::string_dup ("obr5"), CORBA::string_dup ("obr5.eps"));
760   
761
762   assert (!CORBA::is_nil (text));
763   assert (!CORBA::is_nil (obr1));
764   assert (!CORBA::is_nil (obr2));
765   assert (!CORBA::is_nil (obr3));
766   assert (strcmp (text->file (), "thesis.tex") == 0);
767   cout << "Checking NodeFactory::create_node () ..." << flush;
768   CosGraphs::Node_var node_text = node_factory->create_node (text);
769   if (!CORBA::is_nil (node_text))
770     cout << "ok.\n";
771   else
772     cout << "error.\n";
773
774   cout << "Checking Node::related_object () ..." << flush;
775   exception = FALSE;
776
777 #ifdef HAVE_EXCEPTIONS
778   try {
779 #endif
780     node_text->related_object ();
781     node_text->related_object ();
782     if (!CORBA::is_nil (node_text->related_object ()))
783       if (Documents::Text::_narrow (node_text->related_object ()))
784         if ((Documents::Text::_narrow (node_text->related_object ()))
785             ->name () != NULL)
786           cout << "ok.\n";
787 #ifdef HAVE_EXCEPTIONS
788   } catch (CORBA::SystemException_catch &e) {
789     cout << "failed.\n";
790   } catch (CORBA::UserException &e) {
791     cout << "error.\n";
792   }
793 #endif
794   cout << "Checking Node::add_role () ..." << flush;
795   CosGraphs::Node_var node_obr1;   
796   CosGraphs::Node_var node_obr2;
797   CosGraphs::Node_var node_obr3;
798   CosGraphs::Node_var node_obr4;
799   CosGraphs::Node_var node_obr5;
800
801 #ifdef HAVE_EXCEPTIONS
802   try {
803 #endif
804     node_obr1 = node_factory->create_node (obr1);
805     node_obr2 = node_factory->create_node (obr2);
806     node_obr3 = node_factory->create_node (obr3);
807     node_obr4 = node_factory->create_node (obr4);
808     node_obr5 = node_factory->create_node (obr5);
809 #ifdef HAVE_EXCEPTIONS
810   } catch (CORBA::Exception &e) {
811     cout << "can't create nodes!!! " << flush;
812   }
813 #endif
814   CosGraphs::Role_var contains;
815   CosGraphs::Role_var containedin1;
816   CosGraphs::Role_var containedin2;
817   CosGraphs::Role_var containedin3;
818   CosGraphs::Role_var contains_obr1;
819   CosGraphs::Role_var containedin4;
820   CosGraphs::Role_var containedin5;
821   
822 #ifdef HAVE_EXCEPTIONS
823   try {
824 #endif
825     contains = CosGraphs::Role::_narrow 
826       (contains_factory->create_role (node_text));
827     containedin1 = CosGraphs::Role::_narrow
828       (containedin_factory->create_role (node_obr1));
829     containedin2 = CosGraphs::Role::_narrow
830       (containedin_factory->create_role (node_obr2));
831     containedin3 = CosGraphs::Role::_narrow
832       (containedin_factory->create_role (node_obr3));
833     contains_obr1 = CosGraphs::Role::_narrow 
834       (contains_factory->create_role (node_obr1));
835     containedin4 = CosGraphs::Role::_narrow
836       (containedin_factory->create_role (node_obr4));
837     containedin5 = CosGraphs::Role::_narrow
838       (containedin_factory->create_role (node_obr5));
839
840 #ifdef HAVE_EXCEPTIONS
841   } catch (CosRelationships::RoleFactory::NilRelatedObject_catch &e) {
842     cout << "can't create roles - nil related object\n";
843   } catch (CosRelationships::RoleFactory::RelatedObjectTypeError_catch &e) {
844     cout << "can't create roles - related object type error\n";
845   } catch (::CORBA::SystemException_catch &e) {
846     cout << "can't create roles!!! system exception\n" << flush;
847   }
848 #endif
849
850   assert (!CORBA::is_nil (contains));
851   exception = FALSE;
852
853 #ifdef HAVE_EXCEPTIONS
854   try {
855 #endif
856     node_text->add_role (contains);
857 #ifdef HAVE_EXCEPTIONS
858   } catch (CORBA::SystemException_catch &e) {
859     exception = TRUE;
860   }
861 #endif
862
863   if (node_text->roles_of_node ()->length () == 1 && !exception)
864     cout << "ok.\n";
865   else
866     cout << "error.\n";
867
868
869   cout << "Checking Node::roles_of_node () ..." << flush;
870   exception = FALSE;
871   CosGraphs::Node::Roles_var node_roles;
872
873 #ifdef HAVE_EXCEPTIONS
874   try {
875 #endif
876     node_roles = node_text->roles_of_node ();
877     node_roles = node_text->roles_of_node ();
878     node_roles = node_text->roles_of_node ();
879
880 #ifdef HAVE_EXCEPTIONS
881   } catch (CORBA::SystemException_catch &e) {
882     exception = TRUE;
883   }
884 #endif
885
886   if (node_roles->length () == 1 && !exception)
887     cout << "ok.\n";
888   else
889     cout << "error.\n"; 
890
891
892   cout << "Checking Node::remove_role () ..." << flush;
893
894 #ifdef HAVE_EXCEPTIONS
895   try {
896 #endif
897     ::CORBA::InterfaceDef_var type = contains->_get_interface ();
898     node_text->remove_role (type);
899
900 #ifdef HAVE_EXCEPTIONS
901   } catch (CORBA::SystemException_catch &e) {
902     cout << "system exception\n";
903   } catch (CORBA::UserException &e) {
904     exception = TRUE;
905   }
906 #endif
907
908   if (node_text->roles_of_node ()->length () == 0 && !exception)
909     cout << "ok.\n";
910   else
911     cout << "error.\n";
912
913   assert (!CORBA::is_nil (node_text));
914
915   cout << "Checking Node::roles_of_type () ..." << flush;
916
917   // in this time is role_of_types buggy
918
919   exception = FALSE;
920   Test::BaseRole_ptr base_role = Test::BaseRole::_narrow 
921     (base_factory->create_role (node_text));
922   CORBA::InterfaceDef_var base_role_type = base_role->_get_interface ();
923
924   Test::DerivedRole1_ptr derived1_role = Test::DerivedRole1::_narrow 
925     (derived_factory1->create_role (node_text));
926   CORBA::InterfaceDef_var derived1_role_type 
927     = derived1_role->_get_interface ();
928
929   Test::DerivedRole2_ptr derived2_role = Test::DerivedRole2::_narrow 
930     (derived_factory2->create_role (node_text));
931   CORBA::InterfaceDef_var derived2_role_type 
932     = derived2_role->_get_interface ();
933
934   state_good = TRUE;
935   exception = FALSE;
936   exception2 = FALSE;
937
938 #ifdef HAVE_EXCEPTIONS
939   try {
940 #endif
941     node_text->add_role (derived1_role);
942     node_text->add_role (derived2_role);
943     node_roles = node_text->roles_of_type (derived1_role_type);
944     if (node_roles->length () == 1 
945         && (!CORBA::is_nil (Test::DerivedRole1::_narrow ((*node_roles)[0]))))
946       state_good = TRUE;
947     else
948       state_good = FALSE;
949     
950     if (state_good) {
951       node_roles = node_text->roles_of_type (derived2_role_type);
952       if (node_roles->length () == 1 
953           && (Test::DerivedRole2::_narrow ((*node_roles)[0])))
954         state_good = TRUE;
955       else
956         state_good = FALSE;
957     }
958     if (state_good) {
959       node_roles = node_text->roles_of_type (base_role_type);
960       if (node_roles->length () == 2)
961         state_good = TRUE;
962       else
963         state_good = FALSE;
964     }
965     // cleaning up
966     node_text->remove_role (base_role_type);
967
968 #ifdef HAVE_EXCEPTIONS
969   } catch (CORBA::SystemException_catch &e) {
970     exception = TRUE;
971   } catch (CORBA::UserException &e) {
972     exception2 = TRUE;
973   }
974 #endif  
975
976   if (state_good && !exception2 && !exception)
977     cout << "ok.\n";
978   if (!state_good)
979     cout << "failed.\n";
980   if (exception)
981     cout << "failed2.\n";
982   if (exception2)
983     cout << "error.\n";
984   
985
986   cout << "Checking Node::DuplicateRoleType exception ..." << flush;
987   exception = FALSE;
988
989 #ifdef HAVE_EXCEPTIONS
990   try {
991 #endif
992     node_text->add_role (contains);
993     node_text->add_role (contains);
994
995 #ifdef HAVE_EXCEPTIONS
996   } catch (CosGraphs::Node::DuplicateRoleType_catch &e) {
997     exception = TRUE;
998   }
999 #endif
1000
1001   if (exception)
1002     cout << "ok.\n";
1003   else
1004     cout << "error.\n";
1005
1006   
1007   cout << "Checking Node::NoSuchRole exception ..." << flush;
1008   exception = FALSE;
1009   exception2 = FALSE;
1010   exception3 = FALSE;
1011
1012 #ifdef HAVE_EXCEPTIONS
1013   try {
1014     CORBA::InterfaceDef_var type;
1015 #endif
1016     type = containedin1->_get_interface ();
1017     node_text->remove_role (type);
1018 #ifdef HAVE_EXCEPTIONS
1019   } catch (CORBA::SystemException_catch &e) {
1020     cout << "system exception\n";
1021   } catch (CosGraphs::Node::NoSuchRole_catch &e) {
1022     exception = TRUE;
1023   }
1024 #endif
1025 #ifdef HAVE_EXCEPTIONS
1026   try {
1027     CORBA::InterfaceDef_var type;
1028 #endif
1029     type = contains->_get_interface ();
1030     node_text->remove_role (type);
1031 #ifdef HAVE_EXCEPTIONS
1032   } catch (CORBA::SystemException_catch &e) {
1033     cout << "system exception\n";
1034   } catch (CosGraphs::Node::NoSuchRole_catch &e) {
1035     exception2 = TRUE;
1036   }
1037 #endif
1038 #ifdef HAVE_EXCEPTIONS
1039   try {
1040     CORBA::InterfaceDef_var type;
1041 #endif
1042     type = contains->_get_interface ();
1043     node_text->remove_role (type);
1044 #ifdef HAVE_EXCEPTIONS
1045   } catch (CORBA::SystemException_catch &e) {
1046     cout << "system exception\n";
1047   } catch (CosGraphs::Node::NoSuchRole_catch &e) {
1048     exception3 = TRUE;
1049   }
1050 #endif    
1051
1052   if (exception && !exception2 && exception3) 
1053     cout << "ok.\n";
1054   else
1055     cout << "error.\n";
1056
1057
1058   cout << "Checking Role::get_edges () " << flush;
1059   assert (node_text->roles_of_node ()->length () == 0);
1060   node_text->add_role (contains);
1061   node_obr1->add_role (containedin1);
1062   node_obr1->add_role (contains_obr1);
1063   node_obr2->add_role (containedin2);
1064   node_obr3->add_role (containedin3);
1065   node_obr4->add_role (containedin4);
1066   node_obr5->add_role (containedin5);
1067   
1068   cout << "." << flush;
1069   nr.length (2);
1070   nr[0].name = CORBA::string_dup ("ContainsRole");
1071   nr[1].name = CORBA::string_dup ("ContainedInRole");
1072
1073   nr[0].aRole = CosRelationships::Role::_duplicate (contains);
1074   nr[1].aRole = CosRelationships::Role::_duplicate (containedin3);
1075   CosContainment::Relationship_ptr containment3 
1076     = CosContainment::Relationship::_narrow (containment_factory->create (nr));
1077   cout << "." << flush;
1078
1079   nr[0].aRole = CosGraphs::Role::_duplicate (contains);
1080   nr[1].aRole = CosGraphs::Role::_duplicate (containedin1);
1081   CosContainment::Relationship_ptr containment1 
1082     = CosContainment::Relationship::_narrow (containment_factory->create (nr));
1083   cout << "." << flush;
1084
1085   nr[0].aRole = CosRelationships::Role::_duplicate (contains);
1086   nr[1].aRole = CosRelationships::Role::_duplicate (containedin2);
1087   CosContainment::Relationship_ptr containment2 
1088     = CosContainment::Relationship::_narrow (containment_factory->create (nr));
1089   cout << "." << flush;
1090
1091
1092   nr[0].aRole = CosRelationships::Role::_duplicate (contains_obr1);
1093   nr[1].aRole = CosRelationships::Role::_duplicate (containedin4);
1094   CosContainment::Relationship_ptr containment4 
1095     = CosContainment::Relationship::_narrow (containment_factory->create (nr));
1096   cout << "." << flush;
1097
1098   nr[0].aRole = CosRelationships::Role::_duplicate (contains_obr1);
1099   nr[1].aRole = CosRelationships::Role::_duplicate (containedin5);
1100   CosContainment::Relationship_ptr containment5 
1101     = CosContainment::Relationship::_narrow (containment_factory->create (nr));
1102   cout << "." << flush;
1103
1104   state_good = true;
1105   CosGraphs::Edges* edges;
1106   CosGraphs::EdgeIterator_ptr edge_iterator;
1107   contains->get_edges (1, edges, edge_iterator);
1108
1109   Documents::Text_ptr tmp_text 
1110     = Documents::Text::_narrow 
1111     (CosGraphs::Node::_narrow ((*edges)[0].from.the_role.the_role
1112                                ->related_object ())->related_object ()); 
1113   if (strcmp (tmp_text->name (), text->name ()) != 0)
1114     state_good = false;
1115   Documents::Figure_ptr tmp_obr 
1116     = Documents::Figure::_narrow 
1117     (CosGraphs::Node::_narrow ((*edges)[0].relatives[0].the_role.the_role
1118                                ->related_object ())->related_object ()); 
1119   if (strcmp (tmp_obr->name (), obr3->name ()) != 0)
1120     state_good = false;
1121
1122   if (CORBA::is_nil (edge_iterator))
1123     state_good = false;
1124   else 
1125     edge_iterator->destroy ();
1126   if (state_good)
1127     cout << "ok.\n";
1128   else
1129     cout <<"failed.\n";
1130
1131   cout << "Checking EdgeIterator::next_one () ..." << flush;
1132   contains->get_edges (1, edges, edge_iterator);
1133   CosGraphs::Edge* edge;
1134   if (!CORBA::is_nil (edge_iterator)) {
1135     edge_iterator->next_one (edge);
1136     tmp_obr = Documents::Figure::_narrow 
1137       (CosGraphs::Node::_narrow (edge->relatives[0].the_role.the_role
1138                                  ->related_object ())->related_object ()); 
1139     if (strcmp (tmp_obr->name (), obr1->name ()) != 0)
1140       state_good = false;
1141     edge_iterator->next_one (edge);
1142     if (edge_iterator->next_one (edge))
1143       state_good = false;
1144   }
1145   else
1146     state_good = false;
1147
1148   edge_iterator->destroy ();
1149
1150   // for get_edges (0, edges, edge_iterator);
1151   contains->get_edges (0, edges, edge_iterator);
1152   if (!CORBA::is_nil (edge_iterator)) {
1153     edge_iterator->next_one (edge);
1154     tmp_obr = Documents::Figure::_narrow 
1155       (CosGraphs::Node::_narrow (edge->relatives[0].the_role.the_role
1156                                ->related_object ())->related_object ()); 
1157     if (strcmp (tmp_obr->name (), obr3->name ()) != 0)
1158       state_good = false;
1159     edge_iterator->next_one (edge);
1160     tmp_obr = Documents::Figure::_narrow 
1161       (CosGraphs::Node::_narrow (edge->relatives[0].the_role.the_role
1162                                  ->related_object ())->related_object ()); 
1163     if (strcmp (tmp_obr->name (), obr1->name ()) != 0)
1164       state_good = false;
1165     edge_iterator->next_one (edge);
1166     if (edge_iterator->next_one (edge))
1167       state_good = false;
1168
1169     edge_iterator->destroy ();
1170   }
1171   else
1172     state_good = false;
1173   
1174   contains->get_edges (3, edges, edge_iterator);
1175   if (!CORBA::is_nil (edge_iterator)) {
1176     if (edge_iterator->next_one (edge))
1177       state_good = false;
1178
1179     edge_iterator->destroy ();
1180   }
1181   else
1182     state_good = false;
1183
1184   contains->get_edges (30, edges, edge_iterator);
1185   if (!CORBA::is_nil (edge_iterator)) {
1186     if (edge_iterator->next_one (edge))
1187       state_good = false;
1188
1189     edge_iterator->destroy ();
1190   }
1191   else
1192     state_good = false;
1193   
1194   if (state_good)
1195     cout << "ok.\n";
1196   else
1197     cout <<"failed.\n";
1198   
1199
1200   cout << "Checking EdgeIterator::next_n () ..." << flush;
1201   contains->get_edges (0, edges, edge_iterator);
1202   if (!CORBA::is_nil (edge_iterator)) {
1203     edge_iterator->next_n (1, edges);
1204     tmp_obr = Documents::Figure::_narrow 
1205       (CosGraphs::Node::_narrow ((*edges)[0].relatives[0].the_role.the_role
1206                                  ->related_object ())->related_object ()); 
1207     if (strcmp (tmp_obr->name (), obr3->name ()) != 0)
1208       state_good = false;
1209     edge_iterator->next_one (edge);
1210     edge_iterator->next_one (edge);
1211     if (edge_iterator->next_one (edge))
1212       state_good = false;
1213
1214     edge_iterator->destroy ();
1215   }
1216   else
1217     state_good = false;
1218
1219   contains->get_edges (0, edges, edge_iterator);
1220   if (!CORBA::is_nil (edge_iterator)) {
1221     edge_iterator->next_n (3, edges);
1222     tmp_obr = Documents::Figure::_narrow 
1223       (CosGraphs::Node::_narrow ((*edges)[0].relatives[0].the_role.the_role
1224                                  ->related_object ())->related_object ()); 
1225     if (strcmp (tmp_obr->name (), obr3->name ()) != 0)
1226       state_good = false;
1227
1228     tmp_obr = Documents::Figure::_narrow 
1229       (CosGraphs::Node::_narrow ((*edges)[1].relatives[0].the_role.the_role
1230                                  ->related_object ())->related_object ()); 
1231     if (strcmp (tmp_obr->name (), obr1->name ()) != 0)
1232       state_good = false;
1233
1234     tmp_obr = Documents::Figure::_narrow 
1235       (CosGraphs::Node::_narrow ((*edges)[2].relatives[0].the_role.the_role
1236                                  ->related_object ())->related_object ()); 
1237     if (strcmp (tmp_obr->name (), obr2->name ()) != 0)
1238       state_good = false;
1239
1240     if (edge_iterator->next_one (edge))
1241       state_good = false;
1242
1243     edge_iterator->destroy ();
1244   }
1245   else
1246     state_good = false;
1247
1248   contains->get_edges (0, edges, edge_iterator);
1249   if (!CORBA::is_nil (edge_iterator)) {
1250     edge_iterator->next_n (30, edges);
1251     tmp_obr = Documents::Figure::_narrow 
1252       (CosGraphs::Node::_narrow ((*edges)[0].relatives[0].the_role.the_role
1253                                  ->related_object ())->related_object ()); 
1254     if (strcmp (tmp_obr->name (), obr3->name ()) != 0)
1255       state_good = false;
1256
1257     tmp_obr = Documents::Figure::_narrow 
1258       (CosGraphs::Node::_narrow ((*edges)[1].relatives[0].the_role.the_role
1259                                  ->related_object ())->related_object ()); 
1260     if (strcmp (tmp_obr->name (), obr1->name ()) != 0)
1261       state_good = false;
1262
1263     tmp_obr = Documents::Figure::_narrow 
1264       (CosGraphs::Node::_narrow ((*edges)[2].relatives[0].the_role.the_role
1265                                  ->related_object ())->related_object ()); 
1266     if (strcmp (tmp_obr->name (), obr2->name ()) != 0)
1267       state_good = false;
1268
1269     if (edge_iterator->next_one (edge))
1270       state_good = false;
1271
1272     edge_iterator->destroy ();
1273   }
1274   else
1275     state_good = false;
1276
1277   contains->get_edges (0, edges, edge_iterator);
1278   if (!CORBA::is_nil (edge_iterator)) {
1279     edge_iterator->next_n (0, edges);
1280     if (!edge_iterator->next_one (edge))
1281       state_good = false;
1282     if (!edge_iterator->next_one (edge))
1283       state_good = false;
1284     if (!edge_iterator->next_one (edge))
1285       state_good = false;
1286     if (edge_iterator->next_one (edge))
1287       state_good = false;
1288
1289     edge_iterator->destroy ();
1290   }
1291   else
1292     state_good = false;
1293
1294   if (state_good)
1295     cout << "ok.\n";
1296   else
1297     cout <<"failed.\n";
1298   
1299   
1300   state_good = true;
1301   cout << "Checking TraversalFactory_impl::create_traversal_on () ..." 
1302        << flush;
1303
1304   CosGraphs::TraversalCriteria_ptr criteria = criteria_factory->create 
1305     (CosGraphs::deep);
1306   if (CORBA::is_nil (criteria))
1307     state_good = false;
1308
1309   CosGraphs::NodeHandle node_text_handle;
1310   CosGraphs::Traversal::ScopedEdge* scoped_edge;
1311
1312   node_text_handle.the_node = CosGraphs::Node::_duplicate (node_text);
1313   node_text_handle.constant_random_id = node_text->constant_random_id ();
1314
1315   CosGraphs::Traversal_ptr traversal = traversal_factory->create_traversal_on 
1316     //(node_text_handle, criteria, CosGraphs::breadthFirst);
1317     (node_text_handle, criteria, CosGraphs::depthFirst);
1318
1319   if (CORBA::is_nil (traversal))
1320     state_good = false;
1321   
1322   if (state_good)
1323     cout << "ok.\n";
1324   else
1325     cout <<"failed.\n";
1326
1327   cout << "Checking traversing graphs of related objects - depthFirst\n";
1328   
1329   assert (!CORBA::is_nil (traversal));
1330   
1331   while (traversal->next_one (scoped_edge)) {
1332     cout << "from: " << Documents::AbstractDocument::_narrow (scoped_edge->from.point.the_node.the_node->related_object ())->name () << "\n";
1333     cout << "role: " << scoped_edge->from.point.the_role.the_name << "\n";
1334     cout << "to: " << Documents::AbstractDocument::_narrow (scoped_edge->relatives[0].point.the_node.the_node->related_object ())->name () << "\n";
1335     cout << "role: " << scoped_edge->relatives[0].point.the_role.the_name << "\n";
1336     cout << "\n";
1337   }
1338   
1339   state_good = true;
1340   traversal->destroy ();
1341
1342   CosGraphs::TraversalCriteria_ptr criteria2 = criteria_factory->create 
1343     (CosGraphs::deep);
1344   assert (!CORBA::is_nil (criteria2));
1345
1346   
1347   CosGraphs::NodeHandle node_obr1_handle;
1348   node_obr1_handle.the_node = CosGraphs::Node::_duplicate (node_obr1);
1349   node_obr1_handle.constant_random_id = node_obr1->constant_random_id ();
1350   
1351   CosGraphs::Traversal_ptr traversal2 = traversal_factory->create_traversal_on 
1352     (node_text_handle, criteria2, CosGraphs::breadthFirst);
1353
1354   
1355   assert (!CORBA::is_nil (traversal2));
1356   
1357   cout << "Checking traversing graphs of related objects - breadthFirst\n";
1358
1359   
1360   CosGraphs::Traversal::ScopedEdge* scoped_edge2;
1361   while (traversal2->next_one (scoped_edge2)) {
1362     assert (scoped_edge2 != NULL);
1363     assert (!CORBA::is_nil (scoped_edge2->from.point.the_node.the_node));
1364     cout << "from: " << Documents::AbstractDocument::_narrow (scoped_edge2->from.point.the_node.the_node->related_object ())->name () << "\n";
1365     cout << "role: " << scoped_edge2->from.point.the_role.the_name << "\n";
1366     cout << "to: " << Documents::AbstractDocument::_narrow (scoped_edge2->relatives[0].point.the_node.the_node->related_object ())->name () << "\n";
1367     cout << "role: " << scoped_edge2->relatives[0].point.the_role.the_name << "\n";
1368     cout << "\n";
1369
1370   }
1371
1372   state_good = true;
1373
1374   cout << "Destroing objects" << flush;
1375   // containment relationships..
1376   containment1->destroy ();
1377   cout << "." << flush;
1378   containment2->destroy ();
1379   cout << "." << flush;
1380   containment3->destroy ();
1381   cout << "." << flush;
1382   containment4->destroy ();
1383   cout << "." << flush;
1384   containment5->destroy ();
1385   cout << "." << flush;
1386   // containment roles
1387   contains->destroy ();
1388   cout << "." << flush;
1389   containedin1->destroy ();
1390   cout << "." << flush;
1391   containedin2->destroy ();
1392   cout << "." << flush;
1393   containedin3->destroy ();
1394   cout << "." << flush;
1395   
1396   // traversals
1397   //traversal->destroy ();
1398   traversal2->destroy ();
1399   cout << "." << flush;
1400   
1401   // criterias
1402   criteria->destroy ();
1403   cout << "." << flush;
1404
1405   if (!CORBA::is_nil (iterator)) {
1406     iterator->destroy ();
1407     cout << "." << flush;  
1408   }
1409   if (!CORBA::is_nil (relship1)) {
1410     relship1->destroy ();
1411     cout << "." << flush;  
1412   }
1413   if (!CORBA::is_nil (role1)) {
1414     role1->destroy ();
1415     cout << "." << flush;  
1416   }
1417   if (!CORBA::is_nil (role2)) {
1418     role2->destroy ();
1419     cout << "." << flush;  
1420   }
1421   
1422   cout << "done.\n" << flush;
1423   return 0;
1424 }
1425
1426