2 * Test of COSS Relationship Service for MICO
3 * Copyright (C) 1998-99 Karel Gardas
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.
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.
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.
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
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"
40 int main( int argc, char *argv[] )
43 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "mico-local-orb");
45 cout << "Runing all tests\n" << flush;
47 CORBA::Boolean exception = FALSE;
48 CORBA::Boolean exception2 = FALSE;
49 CORBA::Boolean exception3 = FALSE;
50 CORBA::Boolean state_good = TRUE;
54 cout << "Binding to ContainsRoleFactory ..." << flush;
55 CORBA::ORB::ObjectTag_var
56 tag2 = CORBA::ORB::string_to_tag ("ContainsRole_impl");
58 obj10 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
65 cout << "ERROR!\n" << flush;
67 cout << "Binding to ContainedInRoleFactory ..." << flush;
68 CORBA::ORB::ObjectTag_var
69 tag3 = CORBA::ORB::string_to_tag ("ContainedInRole_impl");
71 obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
78 cout << "ERROR!\n" << flush;
81 cout << "Binding to ContainmentFactory ..." << flush;
82 CORBA::ORB::ObjectTag_var
83 tag11 = CORBA::ORB::string_to_tag ("Containment_impl");
85 obj30 = orb->bind ("IDL:omg.org/CosRelationships/RelationshipFactory:1.0",
87 assert (!CORBA::is_nil (obj30));
88 CosRelationships::RelationshipFactory_var containment_factory;
89 if (containment_factory = CosRelationships::RelationshipFactory::_narrow
91 cout << "done.\n" << flush;
93 cout << "ERROR!\n" << flush;
97 cout << "Binding to ReferencesRoleFactory ..." << flush;
98 //CORBA::ORB::ObjectTag_var
99 tag2 = CORBA::ORB::string_to_tag ("ReferencesRole_impl");
101 obj10 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
108 cout << "ERROR!\n" << flush;
110 cout << "Binding to ReferencedByRoleFactory ..." << flush;
111 //CORBA::ORB::ObjectTag_var
112 tag3 = CORBA::ORB::string_to_tag ("ReferencedByRole_impl");
114 obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
121 cout << "ERROR!\n" << flush;
124 cout << "Binding to ReferenceFactory ..." << flush;
125 //CORBA::ORB::ObjectTag_var
126 tag11 = CORBA::ORB::string_to_tag ("Reference_impl");
128 obj30 = orb->bind ("IDL:omg.org/CosRelationships/RelationshipFactory:1.0",
130 assert (!CORBA::is_nil (obj30));
131 CosRelationships::RelationshipFactory_var reference_factory;
132 if (reference_factory = CosRelationships::RelationshipFactory::_narrow
134 cout << "done.\n" << flush;
136 cout << "ERROR!\n" << flush;
140 cout << "Binding to NodeFactory ..." << flush;
141 //CORBA::ORB::ObjectTag_var
142 tag11 = CORBA::ORB::string_to_tag ("Node_impl");
144 obj30 = orb->bind ("IDL:omg.org/CosGraphs/NodeFactory:1.0",
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;
151 cout << "ERROR!\n" << flush;
153 // figure and text factory
154 cout << "Binding to TextFactory ..." << flush;
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;
162 cout << "ERROR!\n" << flush;
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;
171 cout << "ERROR!\n" << flush;
174 // binding to factories which are need for tests
176 cout << "Binding to BaseRoleFactory ..." << flush;
177 //CORBA::ORB::ObjectTag_var
178 tag2 = CORBA::ORB::string_to_tag ("BaseRole_impl");
180 obj10 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
187 cout << "ERROR!\n" << flush;
189 cout << "Binding to DerivedRoleFactory 1..." << flush;
190 //CORBA::ORB::ObjectTag_var
191 tag3 = CORBA::ORB::string_to_tag ("DerivedRole1_impl");
193 obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
200 cout << "ERROR!\n" << flush;
202 cout << "Binding to DerivedRoleFactory 2..." << flush;
203 //CORBA::ORB::ObjectTag_var
204 tag3 = CORBA::ORB::string_to_tag ("DerivedRole2_impl");
206 obj11 = orb->bind ("IDL:omg.org/CosRelationships/RoleFactory:1.0",
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;
213 cout << "ERROR!\n" << flush;
216 cout << "Binding to TestRelationshipFactory ..." << flush;
217 //CORBA::ORB::ObjectTag_var
218 tag11 = CORBA::ORB::string_to_tag ("TestRelationship_impl");
220 obj30 = orb->bind ("IDL:omg.org/CosRelationships/RelationshipFactory:1.0",
222 assert (!CORBA::is_nil (obj30));
223 CosRelationships::RelationshipFactory_var test_relationship_factory;
224 if (test_relationship_factory = CosRelationships::RelationshipFactory::
226 cout << "done.\n" << flush;
228 cout << "ERROR!\n" << flush;
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;
238 cout << "ERROR!\n" << flush;
241 cout << "Binding to GenericCriteriaFactory ..." << flush;
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
248 cout << "done.\n" << flush;
250 cout << "ERROR!\n" << flush;
253 cout << "Checking first level\n";
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;
263 cout << "error.\n" << flush;
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;
273 cout << "error.\n" << flush;
277 cout << "Checking RoleFactory::create_role () ..." << flush;
278 CORBA::Boolean right_role = TRUE;
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
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
296 catch (CosRelationships::RoleFactory::RelatedObjectTypeError_catch &ex1)
298 cout << "RelatedObjectTypeError!\n" << flush;
302 if (!CORBA::is_nil (role1)) {
303 cout << "ok.\n" << flush;
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;
314 cout << "failed.\n" << flush;
319 cout << "Checking Role::destroy () ..." << flush;
321 #ifdef HAVE_EXCEPTIONS
324 CORBA::Object_var x = role1->related_object ();
325 #ifdef HAVE_EXCEPTIONS
327 catch (CORBA::SystemException_catch &ex) {
332 cout << "ok.\n" << flush;
334 cout << "failed.\n" << flush;
338 cout << "Checking RoleFactory::RelatedObjectTypeError exception ..."
340 #ifdef HAVE_EXCEPTIONS
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) {
353 cout << "ok.\n" << flush;
355 cout << "failed.\n" << flush;
358 cout << "Checking RoleFactory::NilRelatedObject exception ..." << flush;
361 #ifdef HAVE_EXCEPTIONS
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) {
373 cout << "ok.\n" << flush;
375 cout << "failed.\n" << flush;
379 #ifdef HAVE_EXCEPTIONS
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
389 role1 = CosContainment::ContainsRole::_narrow
390 (contains_factory->create_role
393 #ifdef HAVE_EXCEPTIONS
394 } catch (CosRelationships::RoleFactory::RelatedObjectTypeError_catch &ex1) {
395 cout << "RelatedObjectTypeError!\n" << flush;
399 assert (!CORBA::is_nil (role1));
400 assert (!CORBA::is_nil (role2));
403 cout << "Checking RelationshipFactory::create () ..." << flush;
404 CosRelationships::NamedRoles nr;
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);
411 #ifdef HAVE_EXCEPTIONS
414 relship1 = CosContainment::Relationship::_narrow
415 (containment_factory->create (nr));
416 #ifdef HAVE_EXCEPTIONS
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 ();
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;
429 relship1 = CosContainment::Relationship::_nil ();
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;
437 relship1 = CosContainment::Relationship::_nil ();
438 cout << "End of catch statement!\n" << flush;
441 if (!CORBA::is_nil (relship1)) {
442 cout << "ok.\n" << flush;
450 cout << "Checking RelationshipFactory::UnknownRoleName exception ..."
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);
458 #ifdef HAVE_EXCEPTIONS
461 relship1 = CosContainment::Relationship::_narrow
462 (containment_factory->create (nr));
463 #ifdef HAVE_EXCEPTIONS
465 catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
466 cout << "DegreeError exception!!!\n" << flush;
467 cout << "Required degree is " << ex->required_degree << "\n" << flush;
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;
478 catch (CosRelationships::RelationshipFactory::UnknownRoleName_catch &ex) {
479 // cout << "UnknownRoleName exception!!!\n" << flush;
480 // cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n"
482 // for (int i=0; i< (ex->culprits).length (); i++) {
483 // cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
489 cout << "ok.\n" << flush;
492 cout << "failed.\n" << flush;
497 cout << "Checking RelationshipFactory::DuplicateRoleName exception ..."
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);
505 #ifdef HAVE_EXCEPTIONS
508 relship1 = CosContainment::Relationship::_narrow
509 (containment_factory->create (nr));
510 #ifdef HAVE_EXCEPTIONS
512 catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
513 cout << "DegreeError exception!!!\n" << flush;
514 cout << "Required degree is " << ex->required_degree << "\n" << flush;
517 catch (CosRelationships::RelationshipFactory::DuplicateRoleName_catch &ex) {
518 // cout << "DuplicateRoleName exception!!!\n" << flush;
519 // cout << "ex->culprits.length () = " << (ex->culprits).length () << "\n"
521 // for (int i=0; i<(ex->culprits).length () ; i++) {
522 // cout << i << ". name: " << (ex->culprits[i]).name << "\n" << flush;
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;
533 cout << "End of catch statement!\n" << flush;
537 cout << "ok.\n" << flush;
539 cout << "failed.\n" << flush;
544 cout << "Checking RelationshipFactory::DegreeError exception ..." << flush;
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);
553 #ifdef HAVE_EXCEPTIONS
556 relship1 = CosContainment::Relationship::_narrow
557 (containment_factory->create (nr));
558 #ifdef HAVE_EXCEPTIONS
560 catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
561 // cout << "DegreeError exception!!!\n" << flush;
562 // cout << "Required degree is " << ex->required_degree << "\n" << flush;
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;
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;
580 cout << "End of catch statement!\n" << flush;
585 cout << "ok.\n" << flush;
587 cout << "failed\n" << flush;
592 cout << "Checking RelationshipFactory::RoleTypeError exception ..."
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
600 #ifdef HAVE_EXCEPTIONS
603 relship1 = CosContainment::Relationship::_narrow
604 (containment_factory->create (nr));
605 #ifdef HAVE_EXCEPTIONS
607 catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
608 cout << "DegreeError exception!!!\n" << flush;
609 cout << "Required degree is " << ex->required_degree << "\n" << flush;
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;
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;
627 cout << "End of catch statement!\n" << flush;
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;
640 cout << "ok.\n" << flush;
642 cout << "failed.\n" << flush;
647 cout << "Checking RelationshipFactory::MaxCardinalityExceeded exception ..."
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);
655 #ifdef HAVE_EXCEPTIONS
658 relship1 = CosContainment::Relationship::_narrow
659 (containment_factory->create (nr));
660 #ifdef HAVE_EXCEPTIONS
662 catch (CosRelationships::RelationshipFactory::DegreeError_catch &ex) {
663 cout << "DegreeError exception!!!\n" << flush;
664 cout << "Required degree is " << ex->required_degree << "\n" << flush;
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;
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;
682 cout << "End of catch statement!\n" << flush;
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;
695 cout << "ok.\n" << flush;
697 cout << "failed.\n" << flush;
700 cout << "Checking Role::get_relationships () ..." << flush;
701 CosRelationships::RelationshipIterator_var
702 iterator = CosRelationships::RelationshipIterator::_nil ();
703 CosRelationships::RelationshipHandles* rel_handles;
705 role1->get_relationships (3, rel_handles, iterator);
706 if ((rel_handles != NULL) && (CORBA::is_nil (iterator))) {
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;
714 cout << "error3!\n" << flush;
716 cout << "error2!\n" << flush;
719 cout << "error!\n" << flush;
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;
727 cout << "error!\n" << flush;
728 iterator->destroy ();
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;
737 cout << "error!\n" << flush;
739 // testing second level of MICO RS
740 cout << "Checking second level\n";
742 assert (!CORBA::is_nil (text_factory));
743 assert (!CORBA::is_nil (figure_factory));
745 Documents::Text_var text = text_factory->create_with_file
746 (CORBA::string_dup ("MICO Relationship Service."),
747 CORBA::string_dup ("thesis.tex"));
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"));
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"));
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))
774 cout << "Checking Node::related_object () ..." << flush;
777 #ifdef HAVE_EXCEPTIONS
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 ()))
787 #ifdef HAVE_EXCEPTIONS
788 } catch (CORBA::SystemException_catch &e) {
790 } catch (CORBA::UserException &e) {
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;
801 #ifdef HAVE_EXCEPTIONS
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;
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;
822 #ifdef HAVE_EXCEPTIONS
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));
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;
850 assert (!CORBA::is_nil (contains));
853 #ifdef HAVE_EXCEPTIONS
856 node_text->add_role (contains);
857 #ifdef HAVE_EXCEPTIONS
858 } catch (CORBA::SystemException_catch &e) {
863 if (node_text->roles_of_node ()->length () == 1 && !exception)
869 cout << "Checking Node::roles_of_node () ..." << flush;
871 CosGraphs::Node::Roles_var node_roles;
873 #ifdef HAVE_EXCEPTIONS
876 node_roles = node_text->roles_of_node ();
877 node_roles = node_text->roles_of_node ();
878 node_roles = node_text->roles_of_node ();
880 #ifdef HAVE_EXCEPTIONS
881 } catch (CORBA::SystemException_catch &e) {
886 if (node_roles->length () == 1 && !exception)
892 cout << "Checking Node::remove_role () ..." << flush;
894 #ifdef HAVE_EXCEPTIONS
897 ::CORBA::InterfaceDef_var type = contains->_get_interface ();
898 node_text->remove_role (type);
900 #ifdef HAVE_EXCEPTIONS
901 } catch (CORBA::SystemException_catch &e) {
902 cout << "system exception\n";
903 } catch (CORBA::UserException &e) {
908 if (node_text->roles_of_node ()->length () == 0 && !exception)
913 assert (!CORBA::is_nil (node_text));
915 cout << "Checking Node::roles_of_type () ..." << flush;
917 // in this time is role_of_types buggy
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 ();
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 ();
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 ();
938 #ifdef HAVE_EXCEPTIONS
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]))))
951 node_roles = node_text->roles_of_type (derived2_role_type);
952 if (node_roles->length () == 1
953 && (Test::DerivedRole2::_narrow ((*node_roles)[0])))
959 node_roles = node_text->roles_of_type (base_role_type);
960 if (node_roles->length () == 2)
966 node_text->remove_role (base_role_type);
968 #ifdef HAVE_EXCEPTIONS
969 } catch (CORBA::SystemException_catch &e) {
971 } catch (CORBA::UserException &e) {
976 if (state_good && !exception2 && !exception)
981 cout << "failed2.\n";
986 cout << "Checking Node::DuplicateRoleType exception ..." << flush;
989 #ifdef HAVE_EXCEPTIONS
992 node_text->add_role (contains);
993 node_text->add_role (contains);
995 #ifdef HAVE_EXCEPTIONS
996 } catch (CosGraphs::Node::DuplicateRoleType_catch &e) {
1007 cout << "Checking Node::NoSuchRole exception ..." << flush;
1012 #ifdef HAVE_EXCEPTIONS
1014 CORBA::InterfaceDef_var type;
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) {
1025 #ifdef HAVE_EXCEPTIONS
1027 CORBA::InterfaceDef_var type;
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) {
1038 #ifdef HAVE_EXCEPTIONS
1040 CORBA::InterfaceDef_var type;
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) {
1052 if (exception && !exception2 && exception3)
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);
1068 cout << "." << flush;
1070 nr[0].name = CORBA::string_dup ("ContainsRole");
1071 nr[1].name = CORBA::string_dup ("ContainedInRole");
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;
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;
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;
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;
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;
1105 CosGraphs::Edges* edges;
1106 CosGraphs::EdgeIterator_ptr edge_iterator;
1107 contains->get_edges (1, edges, edge_iterator);
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)
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)
1122 if (CORBA::is_nil (edge_iterator))
1125 edge_iterator->destroy ();
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)
1141 edge_iterator->next_one (edge);
1142 if (edge_iterator->next_one (edge))
1148 edge_iterator->destroy ();
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)
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)
1165 edge_iterator->next_one (edge);
1166 if (edge_iterator->next_one (edge))
1169 edge_iterator->destroy ();
1174 contains->get_edges (3, edges, edge_iterator);
1175 if (!CORBA::is_nil (edge_iterator)) {
1176 if (edge_iterator->next_one (edge))
1179 edge_iterator->destroy ();
1184 contains->get_edges (30, edges, edge_iterator);
1185 if (!CORBA::is_nil (edge_iterator)) {
1186 if (edge_iterator->next_one (edge))
1189 edge_iterator->destroy ();
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)
1209 edge_iterator->next_one (edge);
1210 edge_iterator->next_one (edge);
1211 if (edge_iterator->next_one (edge))
1214 edge_iterator->destroy ();
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)
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)
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)
1240 if (edge_iterator->next_one (edge))
1243 edge_iterator->destroy ();
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)
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)
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)
1269 if (edge_iterator->next_one (edge))
1272 edge_iterator->destroy ();
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))
1282 if (!edge_iterator->next_one (edge))
1284 if (!edge_iterator->next_one (edge))
1286 if (edge_iterator->next_one (edge))
1289 edge_iterator->destroy ();
1301 cout << "Checking TraversalFactory_impl::create_traversal_on () ..."
1304 CosGraphs::TraversalCriteria_ptr criteria = criteria_factory->create
1306 if (CORBA::is_nil (criteria))
1309 CosGraphs::NodeHandle node_text_handle;
1310 CosGraphs::Traversal::ScopedEdge* scoped_edge;
1312 node_text_handle.the_node = CosGraphs::Node::_duplicate (node_text);
1313 node_text_handle.constant_random_id = node_text->constant_random_id ();
1315 CosGraphs::Traversal_ptr traversal = traversal_factory->create_traversal_on
1316 //(node_text_handle, criteria, CosGraphs::breadthFirst);
1317 (node_text_handle, criteria, CosGraphs::depthFirst);
1319 if (CORBA::is_nil (traversal))
1327 cout << "Checking traversing graphs of related objects - depthFirst\n";
1329 assert (!CORBA::is_nil (traversal));
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";
1340 traversal->destroy ();
1342 CosGraphs::TraversalCriteria_ptr criteria2 = criteria_factory->create
1344 assert (!CORBA::is_nil (criteria2));
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 ();
1351 CosGraphs::Traversal_ptr traversal2 = traversal_factory->create_traversal_on
1352 (node_text_handle, criteria2, CosGraphs::breadthFirst);
1355 assert (!CORBA::is_nil (traversal2));
1357 cout << "Checking traversing graphs of related objects - breadthFirst\n";
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";
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;
1397 //traversal->destroy ();
1398 traversal2->destroy ();
1399 cout << "." << flush;
1402 criteria->destroy ();
1403 cout << "." << flush;
1405 if (!CORBA::is_nil (iterator)) {
1406 iterator->destroy ();
1407 cout << "." << flush;
1409 if (!CORBA::is_nil (relship1)) {
1410 relship1->destroy ();
1411 cout << "." << flush;
1413 if (!CORBA::is_nil (role1)) {
1415 cout << "." << flush;
1417 if (!CORBA::is_nil (role2)) {
1419 cout << "." << flush;
1422 cout << "done.\n" << flush;