changed: gcc8 base update
[opensg.git] / Source / System / FieldContainer / Misc / OSGContainerCollectionTest.cpp
blob1da7f084f40e8a47a5c83b3f91eab7debc943ec5
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
6 * *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
8 * *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
11 * License *
12 * *
13 * This library is free software; you can redistribute it and/or modify it *
14 * under the terms of the GNU Library General Public License as published *
15 * by the Free Software Foundation, version 2. *
16 * *
17 * This library is distributed in the hope that it will be useful, but *
18 * WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
20 * Library General Public License for more details. *
21 * *
22 * You should have received a copy of the GNU Library General Public *
23 * License along with this library; if not, write to the Free Software *
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
25 * *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
28 * Changes *
29 * *
30 * *
31 * *
32 * *
33 * *
34 * *
35 \*---------------------------------------------------------------------------*/
37 #include <UnitTest++.h>
39 // Unit tests for the ContainerCollection container
41 #include "OSGContainerCollection.h"
42 #include "OSGNode.h"
43 #include "OSGGroup.h"
44 #include "OSGBlendChunk.h"
46 #include "OSGNameAttachment.h"
48 SUITE(ContainerCollectionTests)
51 TEST(CreatePool)
53 OSG::ContainerCollectionUnrecPtr cc = OSG::ContainerCollection::create();
54 CHECK(cc != NULL);
57 TEST(SettingName)
59 OSG::ContainerCollectionUnrecPtr cc1(OSG::ContainerCollection::create()),
60 cc2(OSG::ContainerCollection::create()),
61 cc3(OSG::ContainerCollection::create());
63 CHECK(cc1 != NULL);
64 CHECK(cc2 != NULL);
65 CHECK(cc3 != NULL);
67 CHECK(cc1 != cc2);
68 CHECK(cc1 != cc3);
69 CHECK(cc2 != cc3);
71 cc1->setName("cc1");
72 cc2->setName("cc2");
73 cc3->setName("cc3");
75 CHECK(cc1->getName() == "cc1");
76 CHECK(cc2->getName() == "cc2");
77 CHECK(cc3->getName() == "cc3");
79 CHECK(cc1->getName() != "cc2");
80 CHECK(cc1->getName() != "cc3");
84 TEST(UsePool)
86 OSG::ContainerCollectionUnrecPtr cc = OSG::ContainerCollection::create();
87 CHECK(cc != NULL);
89 OSG::GroupUnrecPtr t = OSG::Group ::create();
90 OSG::NodeUnrecPtr n = OSG::Node ::create();
91 OSG::BlendChunkUnrecPtr bc = OSG::BlendChunk::create();
93 cc->setName("cc container");
94 cc->addContainer(t);
95 cc->addContainer(n);
96 cc->addContainer(bc);
98 CHECK_EQUAL(3, cc->getNContainers());
99 CHECK_EQUAL(3, cc->getMFContainers()->size());
101 OSG::FieldContainerUnrecPtr t_ptr = cc->getContainers(0);
102 OSG::FieldContainerUnrecPtr n_ptr = cc->getContainers(1);
103 OSG::FieldContainerUnrecPtr bc_ptr = cc->getContainers(2);
105 CHECK(true);
107 // Test removal
108 cc->subContainer(t);
109 CHECK_EQUAL(2, cc->getNContainers());
111 cc->subContainer(n);
112 CHECK_EQUAL(1, cc->getNContainers());
114 cc->subContainer(bc);
115 CHECK_EQUAL(0, cc->getNContainers());
117 // Try it as an attachment
118 OSG::NodeUnrecPtr root_node = OSG::Node::create();
120 OSG::ContainerCollectionUnrecPtr cc2;
121 CHECK(root_node->findAttachment(OSG::ContainerCollection::getClassType()) == NULL);
123 root_node->addAttachment(cc);
125 // now find it
126 cc2 = dynamic_cast<OSG::ContainerCollection::ObjCPtr>(
127 root_node->findAttachment(OSG::ContainerCollection::getClassType()));
128 CHECK(cc2 != NULL);
129 CHECK(cc2 == cc);
131 // Name it and find it by name
132 OSG::ContainerCollectionUnrecPtr named_cc = OSG::ContainerCollection::create();
133 named_cc->setName("MyPool");
135 for(unsigned i=0;i<10;i++)
137 if(i%2)
139 OSG::ContainerCollectionUnrecPtr new_cc =
140 OSG::ContainerCollection::create();
142 root_node->addAttachment(new_cc, i);
145 root_node->addAttachment(named_cc, 7);
147 unsigned x = 0;
148 OSG::ContainerCollectionUnrecPtr cc3(NULL);
150 while(NULL == cc3)
152 OSG::ContainerCollectionUnrecPtr temp_cc;
153 temp_cc = dynamic_cast<OSG::ContainerCollection::ObjCPtr>(
154 root_node->findAttachment(OSG::ContainerCollection::getClassType(), x));
155 if((NULL != temp_cc) && (temp_cc->getName() == "MyPool"))
157 cc3 = temp_cc;
158 CHECK(cc3 == named_cc);
159 break;
161 x++;
164 CHECK_EQUAL(7, x);
165 CHECK_EQUAL("MyPool", cc3->getName());
168 } // SUITE