1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Check all methods of SALOMEDS_AttributeTreeNode
24 * Use code of SALOMEDS_AttributeTreeNode.cxx
26 #define SALOMEDS_ALL_TESTS
27 void SALOMEDSTest::testAttributeTreeNode()
29 //Create or find the Study manager
30 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
35 _PTR(Study) study = sm->NewStudy("Test");
37 CPPUNIT_ASSERT(study);
39 //Create Study Builder
40 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
42 CPPUNIT_ASSERT(studyBuilder);
44 //Create a SObject with entry 0:1:1
45 _PTR(SObject) so = study->CreateObjectID("0:1:1");
49 //Create an attribute AttributeTreeNode
50 _PTR(AttributeTreeNode) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNode");
52 //Check the attribute creation
53 CPPUNIT_ASSERT(_attr);
55 string TreeNodeID = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
57 _PTR(SObject) so1 = study->CreateObjectID("0:1:2");
59 _PTR(AttributeTreeNode) _attr1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeTreeNode");
61 //Check the attribute creation
62 CPPUNIT_ASSERT(_attr1);
65 CPPUNIT_ASSERT(_attr1->Label() == "0:1:2");
67 _PTR(SObject) so2 = study->CreateObjectID("0:1:3");
69 _PTR(AttributeTreeNode) _attr2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeTreeNode");
71 //Check the attribute creation
72 CPPUNIT_ASSERT(_attr2);
74 //Check method SetFather
75 _attr1->SetFather(_attr);
77 //Check method HasFather
78 CPPUNIT_ASSERT(_attr1->HasFather());
80 #ifdef SALOMEDS_ALL_TESTS
81 //Check method GetFather
82 CPPUNIT_ASSERT(_attr1->GetFather()->Label() == _attr->Label());
85 _attr->Append(_attr1);
87 //Check possibility to Append to itself
88 bool isRaised = false;
94 CPPUNIT_ASSERT(isRaised);
96 _attr->Append(_attr2);
98 //Check method HasNext
99 CPPUNIT_ASSERT(_attr1->HasNext());
101 //Check method GetNext
102 CPPUNIT_ASSERT(_attr1->GetNext()->Label() == _attr2->Label());
104 //Check method HasPrevious
105 CPPUNIT_ASSERT(_attr2->HasPrevious());
107 //Check method GetPrevious
108 CPPUNIT_ASSERT(_attr2->GetPrevious()->Label() == _attr1->Label());
111 CPPUNIT_ASSERT(_attr->Depth() == 1 && _attr1->Depth() == 2);
113 //Check method IsRoot
114 CPPUNIT_ASSERT(_attr->IsRoot());
116 //Check method IsFather
117 CPPUNIT_ASSERT(_attr->IsFather(_attr1));
119 //Check method IsDescendant
120 CPPUNIT_ASSERT(_attr2->IsDescendant(_attr));
122 //Check method GetFirst
123 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
127 //Check method Prepend
128 _attr->Prepend(_attr2);
130 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
132 //Check possibility to Prepend to itself
135 _attr->Prepend(_attr);
139 CPPUNIT_ASSERT(isRaised);
143 //Check method InsertBefore
144 _attr2->InsertBefore(_attr1);
146 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
148 //Check possibility to InsertBefore to itself
151 _attr->InsertBefore(_attr);
155 CPPUNIT_ASSERT(isRaised);
159 //Check method InsertAfter
160 _attr2->InsertAfter(_attr1);
162 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
164 //Check possibility to InsertAfter to itself
167 _attr->InsertAfter(_attr);
171 CPPUNIT_ASSERT(isRaised);
173 //Check method Remove
176 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
178 //Check method SetTreeID and GetTreeID
179 _attr2->SetTreeID(TreeNodeID);
181 CPPUNIT_ASSERT(_attr2->GetTreeID() == TreeNodeID);
183 cout << endl << "THE TEST IS NOT COMPLETE !!!" << endl;
187 //Try to create the attribute with given TreeID
188 string value = "0e1c36e6-1111-4d90-ab3b-18a14310e648";
189 _PTR(AttributeTreeNode) _attr_guid = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNodeGUID"+value);
190 CPPUNIT_ASSERT(_attr_guid && _attr_guid->GetTreeID() == value);
194 #undef SALOMEDS_ALL_TESTS