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