1 // Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 * Check all methods of SALOMEDS_AttributeTreeNode
23 * Use code of SALOMEDS_AttributeTreeNode.cxx
25 #define SALOMEDS_ALL_TESTS
26 void SALOMEDSTest::testAttributeTreeNode()
28 //Create or find the Study manager
29 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
34 _PTR(Study) study = sm->NewStudy("Test");
36 CPPUNIT_ASSERT(study);
38 //Create Study Builder
39 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
41 CPPUNIT_ASSERT(studyBuilder);
43 //Create a SObject with entry 0:1:1
44 _PTR(SObject) so = study->CreateObjectID("0:1:1");
48 //Create an attribute AttributeTreeNode
49 _PTR(AttributeTreeNode) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNode");
51 //Check the attribute creation
52 CPPUNIT_ASSERT(_attr);
54 string TreeNodeID = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
56 _PTR(SObject) so1 = study->CreateObjectID("0:1:2");
58 _PTR(AttributeTreeNode) _attr1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeTreeNode");
60 //Check the attribute creation
61 CPPUNIT_ASSERT(_attr1);
64 CPPUNIT_ASSERT(_attr1->Label() == "0:1:2");
66 _PTR(SObject) so2 = study->CreateObjectID("0:1:3");
68 _PTR(AttributeTreeNode) _attr2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeTreeNode");
70 //Check the attribute creation
71 CPPUNIT_ASSERT(_attr2);
73 //Check method SetFather
74 _attr1->SetFather(_attr);
76 //Check method HasFather
77 CPPUNIT_ASSERT(_attr1->HasFather());
79 #ifdef SALOMEDS_ALL_TESTS
80 //Check method GetFather
81 CPPUNIT_ASSERT(_attr1->GetFather()->Label() == _attr->Label());
84 _attr->Append(_attr1);
86 //Check possibility to Append to itself
87 bool isRaised = false;
93 CPPUNIT_ASSERT(isRaised);
95 _attr->Append(_attr2);
97 //Check method HasNext
98 CPPUNIT_ASSERT(_attr1->HasNext());
100 //Check method GetNext
101 CPPUNIT_ASSERT(_attr1->GetNext()->Label() == _attr2->Label());
103 //Check method HasPrevious
104 CPPUNIT_ASSERT(_attr2->HasPrevious());
106 //Check method GetPrevious
107 CPPUNIT_ASSERT(_attr2->GetPrevious()->Label() == _attr1->Label());
110 CPPUNIT_ASSERT(_attr->Depth() == 1 && _attr1->Depth() == 2);
112 //Check method IsRoot
113 CPPUNIT_ASSERT(_attr->IsRoot());
115 //Check method IsFather
116 CPPUNIT_ASSERT(_attr->IsFather(_attr1));
118 //Check method IsDescendant
119 CPPUNIT_ASSERT(_attr2->IsDescendant(_attr));
121 //Check method GetFirst
122 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
126 //Check method Prepend
127 _attr->Prepend(_attr2);
129 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
131 //Check possibility to Prepend to itself
134 _attr->Prepend(_attr);
138 CPPUNIT_ASSERT(isRaised);
142 //Check method InsertBefore
143 _attr2->InsertBefore(_attr1);
145 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
147 //Check possibility to InsertBefore to itself
150 _attr->InsertBefore(_attr);
154 CPPUNIT_ASSERT(isRaised);
158 //Check method InsertAfter
159 _attr2->InsertAfter(_attr1);
161 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
163 //Check possibility to InsertAfter to itself
166 _attr->InsertAfter(_attr);
170 CPPUNIT_ASSERT(isRaised);
172 //Check method Remove
175 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
177 //Check method SetTreeID and GetTreeID
178 _attr2->SetTreeID(TreeNodeID);
180 CPPUNIT_ASSERT(_attr2->GetTreeID() == TreeNodeID);
182 cout << endl << "THE TEST IS NOT COMPLETE !!!" << endl;
186 //Try to create the attribute with given TreeID
187 string value = "0e1c36e6-1111-4d90-ab3b-18a14310e648";
188 _PTR(AttributeTreeNode) _attr_guid = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNodeGUID"+value);
189 CPPUNIT_ASSERT(_attr_guid && _attr_guid->GetTreeID() == value);
193 #undef SALOMEDS_ALL_TESTS