1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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()
31 _PTR(Study) study(new SALOMEDS_Study(_study));
33 CPPUNIT_ASSERT(study);
35 //Create Study Builder
36 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
38 CPPUNIT_ASSERT(studyBuilder);
40 //Create a SObject with entry 0:1:1
41 _PTR(SObject) so = study->CreateObjectID("0:1:1");
45 //Create an attribute AttributeTreeNode
46 _PTR(AttributeTreeNode) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNode");
48 //Check the attribute creation
49 CPPUNIT_ASSERT(_attr);
51 std::string TreeNodeID = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
53 _PTR(SObject) so1 = study->CreateObjectID("0:1:2");
55 _PTR(AttributeTreeNode) _attr1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeTreeNode");
57 //Check the attribute creation
58 CPPUNIT_ASSERT(_attr1);
61 CPPUNIT_ASSERT(_attr1->Label() == "0:1:2");
63 _PTR(SObject) so2 = study->CreateObjectID("0:1:3");
65 _PTR(AttributeTreeNode) _attr2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeTreeNode");
67 //Check the attribute creation
68 CPPUNIT_ASSERT(_attr2);
70 //Check method SetFather
71 _attr1->SetFather(_attr);
73 //Check method HasFather
74 CPPUNIT_ASSERT(_attr1->HasFather());
76 #ifdef SALOMEDS_ALL_TESTS
77 //Check method GetFather
78 CPPUNIT_ASSERT(_attr1->GetFather()->Label() == _attr->Label());
81 _attr->Append(_attr1);
83 //Check possibility to Append to itself
84 bool isRaised = false;
90 CPPUNIT_ASSERT(isRaised);
92 _attr->Append(_attr2);
94 //Check method HasNext
95 CPPUNIT_ASSERT(_attr1->HasNext());
97 //Check method GetNext
98 CPPUNIT_ASSERT(_attr1->GetNext()->Label() == _attr2->Label());
100 //Check method HasPrevious
101 CPPUNIT_ASSERT(_attr2->HasPrevious());
103 //Check method GetPrevious
104 CPPUNIT_ASSERT(_attr2->GetPrevious()->Label() == _attr1->Label());
107 CPPUNIT_ASSERT(_attr->Depth() == 1 && _attr1->Depth() == 2);
109 //Check method IsRoot
110 CPPUNIT_ASSERT(_attr->IsRoot());
112 //Check method IsFather
113 CPPUNIT_ASSERT(_attr->IsFather(_attr1));
115 //Check method IsDescendant
116 CPPUNIT_ASSERT(_attr2->IsDescendant(_attr));
118 //Check method GetFirst
119 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
123 //Check method Prepend
124 _attr->Prepend(_attr2);
126 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
128 //Check possibility to Prepend to itself
131 _attr->Prepend(_attr);
135 CPPUNIT_ASSERT(isRaised);
139 //Check method InsertBefore
140 _attr2->InsertBefore(_attr1);
142 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
144 //Check possibility to InsertBefore to itself
147 _attr->InsertBefore(_attr);
151 CPPUNIT_ASSERT(isRaised);
155 //Check method InsertAfter
156 _attr2->InsertAfter(_attr1);
158 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
160 //Check possibility to InsertAfter to itself
163 _attr->InsertAfter(_attr);
167 CPPUNIT_ASSERT(isRaised);
169 //Check method Remove
172 CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
174 //Check method SetTreeID and GetTreeID
175 _attr2->SetTreeID(TreeNodeID);
177 CPPUNIT_ASSERT(_attr2->GetTreeID() == TreeNodeID);
179 std::cout << std::endl << "THE TEST IS NOT COMPLETE !!!" << std::endl;
183 //Try to create the attribute with given TreeID
184 std::string value = "0e1c36e6-1111-4d90-ab3b-18a14310e648";
185 _PTR(AttributeTreeNode) _attr_guid = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNodeGUID"+value);
186 CPPUNIT_ASSERT(_attr_guid && _attr_guid->GetTreeID() == value);
190 #undef SALOMEDS_ALL_TESTS