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