1 // Copyright (C) 2007-2012 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
24 * Check all methods of SALOMEDS_AttributeTreeNode
25 * Use code of SALOMEDS_AttributeTreeNode.cxx
27 #define SALOMEDS_ALL_TESTS
28 void SALOMEDSTest::testAttributeTreeNode()
30 //Create or find the Study manager
31 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
36 _PTR(Study) study = sm->NewStudy("Test");
38 CPPUNIT_ASSERT(study);
40 //Create Study Builder
41 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
43 CPPUNIT_ASSERT(studyBuilder);
45 //Create a SObject with entry 0:1:1
46 _PTR(SObject) so = study->CreateObjectID("0:1:1");
50 //Create an attribute AttributeTreeNode
51 _PTR(AttributeTreeNode) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNode");
53 //Check the attribute creation
54 CPPUNIT_ASSERT(_attr);
56 std::string TreeNodeID = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
58 _PTR(SObject) so1 = study->CreateObjectID("0:1:2");
60 _PTR(AttributeTreeNode) _attr1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeTreeNode");
62 //Check the attribute creation
63 CPPUNIT_ASSERT(_attr1);
66 CPPUNIT_ASSERT(_attr1->Label() == "0:1:2");
68 _PTR(SObject) so2 = study->CreateObjectID("0:1:3");
70 _PTR(AttributeTreeNode) _attr2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeTreeNode");
72 //Check the attribute creation
73 CPPUNIT_ASSERT(_attr2);
75 //Check method SetFather
76 _attr1->SetFather(_attr);
78 //Check method HasFather
79 CPPUNIT_ASSERT(_attr1->HasFather());
81 #ifdef SALOMEDS_ALL_TESTS
82 //Check method GetFather
83 CPPUNIT_ASSERT(_attr1->GetFather()->Label() == _attr->Label());
86 _attr->Append(_attr1);
88 //Check possibility to Append to itself
89 bool isRaised = false;
95 CPPUNIT_ASSERT(isRaised);
97 _attr->Append(_attr2);
99 //Check method HasNext
100 CPPUNIT_ASSERT(_attr1->HasNext());
102 //Check method GetNext
103 CPPUNIT_ASSERT(_attr1->GetNext()->Label() == _attr2->Label());
105 //Check method HasPrevious
106 CPPUNIT_ASSERT(_attr2->HasPrevious());
108 //Check method GetPrevious
109 CPPUNIT_ASSERT(_attr2->GetPrevious()->Label() == _attr1->Label());
112 CPPUNIT_ASSERT(_attr->Depth() == 1 && _attr1->Depth() == 2);
114 //Check method IsRoot
115 CPPUNIT_ASSERT(_attr->IsRoot());
117 //Check method IsFather
118 CPPUNIT_ASSERT(_attr->IsFather(_attr1));
120 //Check method IsDescendant
121 CPPUNIT_ASSERT(_attr2->IsDescendant(_attr));
123 //Check method GetFirst
124 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
128 //Check method Prepend
129 _attr->Prepend(_attr2);
131 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
133 //Check possibility to Prepend to itself
136 _attr->Prepend(_attr);
140 CPPUNIT_ASSERT(isRaised);
144 //Check method InsertBefore
145 _attr2->InsertBefore(_attr1);
147 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
149 //Check possibility to InsertBefore to itself
152 _attr->InsertBefore(_attr);
156 CPPUNIT_ASSERT(isRaised);
160 //Check method InsertAfter
161 _attr2->InsertAfter(_attr1);
163 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
165 //Check possibility to InsertAfter to itself
168 _attr->InsertAfter(_attr);
172 CPPUNIT_ASSERT(isRaised);
174 //Check method Remove
177 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
179 //Check method SetTreeID and GetTreeID
180 _attr2->SetTreeID(TreeNodeID);
182 CPPUNIT_ASSERT(_attr2->GetTreeID() == TreeNodeID);
184 std::cout << std::endl << "THE TEST IS NOT COMPLETE !!!" << std::endl;
188 //Try to create the attribute with given TreeID
189 std::string value = "0e1c36e6-1111-4d90-ab3b-18a14310e648";
190 _PTR(AttributeTreeNode) _attr_guid = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNodeGUID"+value);
191 CPPUNIT_ASSERT(_attr_guid && _attr_guid->GetTreeID() == value);
195 #undef SALOMEDS_ALL_TESTS