Salome HOME
7fd481f2bb25dd907dcab24501e02a976063b3ab
[modules/kernel.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeTreeNode.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 /*!
24  * Check all methods of SALOMEDS_AttributeTreeNode
25  * Use code of SALOMEDS_AttributeTreeNode.cxx
26  */
27 #define SALOMEDS_ALL_TESTS
28 void SALOMEDSTest::testAttributeTreeNode()
29 {
30   //Create Study
31   _PTR(Study) study(new SALOMEDS_Study(_study));
32
33   CPPUNIT_ASSERT(study);
34
35   //Create Study Builder
36   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
37
38   CPPUNIT_ASSERT(studyBuilder);
39
40   //Create a SObject with entry 0:1:1
41   _PTR(SObject) so = study->CreateObjectID("0:1:1");
42
43   CPPUNIT_ASSERT(so);
44
45   //Create an attribute AttributeTreeNode
46   _PTR(AttributeTreeNode) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNode");
47
48   //Check the attribute creation
49   CPPUNIT_ASSERT(_attr);
50
51   std::string TreeNodeID = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
52
53   _PTR(SObject) so1 = study->CreateObjectID("0:1:2");
54                                                                
55   _PTR(AttributeTreeNode) _attr1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeTreeNode");
56
57   //Check the attribute creation
58   CPPUNIT_ASSERT(_attr1);
59
60   //Check method Label
61   CPPUNIT_ASSERT(_attr1->Label() == "0:1:2");
62
63   _PTR(SObject) so2 = study->CreateObjectID("0:1:3");
64
65   _PTR(AttributeTreeNode) _attr2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeTreeNode");
66
67   //Check the attribute creation
68   CPPUNIT_ASSERT(_attr2);
69
70   //Check method SetFather 
71   _attr1->SetFather(_attr);
72
73   //Check method HasFather
74   CPPUNIT_ASSERT(_attr1->HasFather());
75
76 #ifdef SALOMEDS_ALL_TESTS
77   //Check method GetFather
78   CPPUNIT_ASSERT(_attr1->GetFather()->Label() == _attr->Label());
79
80   //Check method Append
81   _attr->Append(_attr1);
82
83   //Check possibility to Append to itself
84   bool isRaised = false;
85   try {
86     _attr->Append(_attr);
87   }catch(...) {
88     isRaised = true;
89   }
90   CPPUNIT_ASSERT(isRaised);
91
92   _attr->Append(_attr2);
93   
94   //Check method HasNext
95   CPPUNIT_ASSERT(_attr1->HasNext());
96
97   //Check method GetNext
98   CPPUNIT_ASSERT(_attr1->GetNext()->Label() == _attr2->Label());
99
100   //Check method HasPrevious
101   CPPUNIT_ASSERT(_attr2->HasPrevious());
102
103   //Check method GetPrevious
104   CPPUNIT_ASSERT(_attr2->GetPrevious()->Label() == _attr1->Label());
105
106   //Check method Depth
107   CPPUNIT_ASSERT(_attr->Depth() == 1 && _attr1->Depth() == 2);
108
109   //Check method IsRoot
110   CPPUNIT_ASSERT(_attr->IsRoot());
111
112   //Check method IsFather
113   CPPUNIT_ASSERT(_attr->IsFather(_attr1));
114
115   //Check method IsDescendant
116   CPPUNIT_ASSERT(_attr2->IsDescendant(_attr));
117
118   //Check method GetFirst
119   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
120
121   _attr2->Remove();
122
123   //Check method Prepend
124   _attr->Prepend(_attr2);
125
126   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
127
128   //Check possibility to Prepend to itself
129   isRaised = false;
130   try {
131     _attr->Prepend(_attr);
132   }catch(...) {
133     isRaised = true;
134   }
135   CPPUNIT_ASSERT(isRaised);
136
137   _attr1->Remove();
138
139   //Check method InsertBefore
140   _attr2->InsertBefore(_attr1);
141
142   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
143
144   //Check possibility to InsertBefore to itself
145   isRaised = false;
146   try {
147     _attr->InsertBefore(_attr);
148   }catch(...) {
149     isRaised = true;
150   }
151   CPPUNIT_ASSERT(isRaised);
152
153   _attr1->Remove();
154
155   //Check method InsertAfter
156   _attr2->InsertAfter(_attr1);
157
158   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
159
160   //Check possibility to InsertAfter to itself
161   isRaised = false;
162   try {
163     _attr->InsertAfter(_attr);
164   }catch(...) {
165     isRaised = true;
166   }
167   CPPUNIT_ASSERT(isRaised);
168
169   //Check method Remove
170   _attr2->Remove();
171
172   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
173
174   //Check method SetTreeID and GetTreeID
175   _attr2->SetTreeID(TreeNodeID);
176
177   CPPUNIT_ASSERT(_attr2->GetTreeID() == TreeNodeID); 
178 #else
179   std::cout << std::endl << "THE TEST IS NOT COMPLETE !!!" << std::endl;
180 #endif
181
182
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);
187   
188   study->Clear();
189 }
190 #undef SALOMEDS_ALL_TESTS
191
192