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