1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 by the OpenSG Forum *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
35 \*---------------------------------------------------------------------------*/
37 #include <UnitTest++.h>
39 // Unit tests for the ContainerCollection container
41 #include "OSGContainerCollection.h"
44 #include "OSGBlendChunk.h"
46 #include "OSGNameAttachment.h"
48 SUITE(ContainerCollectionTests
)
53 OSG::ContainerCollectionUnrecPtr cc
= OSG::ContainerCollection::create();
59 OSG::ContainerCollectionUnrecPtr
cc1(OSG::ContainerCollection::create()),
60 cc2(OSG::ContainerCollection::create()),
61 cc3(OSG::ContainerCollection::create());
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");
86 OSG::ContainerCollectionUnrecPtr cc
= OSG::ContainerCollection::create();
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");
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);
109 CHECK_EQUAL(2, cc
->getNContainers());
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
);
126 cc2
= dynamic_cast<OSG::ContainerCollection::ObjCPtr
>(
127 root_node
->findAttachment(OSG::ContainerCollection::getClassType()));
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
++)
139 OSG::ContainerCollectionUnrecPtr new_cc
=
140 OSG::ContainerCollection::create();
142 root_node
->addAttachment(new_cc
, i
);
145 root_node
->addAttachment(named_cc
, 7);
148 OSG::ContainerCollectionUnrecPtr
cc3(NULL
);
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"))
158 CHECK(cc3
== named_cc
);
165 CHECK_EQUAL("MyPool", cc3
->getName());