1 // Copyright (C) 2007-2016 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_Study
25 * Use code of SALOMEDS_Study.cxx
28 void SALOMEDSTest::testStudy()
31 _PTR(Study) study(new SALOMEDS_Study(_study));
33 //Check the creation of the study
34 CPPUNIT_ASSERT(study);
36 //Check method NewBuilder
37 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
38 CPPUNIT_ASSERT(studyBuilder);
40 //Check method NewComponentIterator
41 _PTR(SComponentIterator) componentIterator = study->NewComponentIterator();
43 CPPUNIT_ASSERT(componentIterator);
45 //Check method GetTransientReference
46 CPPUNIT_ASSERT(!study->GetTransientReference().empty());
48 //Check method URL (get/set)
50 CPPUNIT_ASSERT(study->URL() == "");
51 study->URL("some url");
52 CPPUNIT_ASSERT(study->URL() == "some url");
54 //Check method GetPersistentReference == URL
55 CPPUNIT_ASSERT(study->GetPersistentReference() == "some url");
57 //Check method IsSaved (get/set)
59 CPPUNIT_ASSERT(study->IsSaved());
60 study->IsSaved(false);
61 CPPUNIT_ASSERT(!study->IsSaved());
63 //Check method CreateObjectID
64 _PTR(SObject) so = study->CreateObjectID("0:2:1:3");
67 //Try to create SObject with empty and invalid entries
68 //CPPUNIT_ASSERT(!study->CreateObjectID(""));
69 CPPUNIT_ASSERT(!study->CreateObjectID("entry"));
71 //Check method NewChildIterator
72 _PTR(ChildIterator) childIterator = study->NewChildIterator(so);
73 CPPUNIT_ASSERT(childIterator);
75 //Check method IsEmpty
76 CPPUNIT_ASSERT(!study->IsEmpty());
78 //Check method FindComponent
79 _PTR(SComponent) sco1 = studyBuilder->NewComponent("test1");
80 _PTR(SComponent) sco2 = study->FindComponent("test1");
81 CPPUNIT_ASSERT(sco1 && sco2);
82 CPPUNIT_ASSERT(sco1->GetID() == sco2->GetID());
83 _PTR(AttributeName) name_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeName");
84 CPPUNIT_ASSERT(name_attr_sco1);
85 name_attr_sco1->SetValue("sco1");
87 //Try to find component with empty type
88 CPPUNIT_ASSERT(!study->FindComponent(""));
90 //Check method GetComponentNames
91 std::vector<std::string> components = study->GetComponentNames(""); //The context doesn't matter
92 CPPUNIT_ASSERT(components.size() == 1 && components[0] == "sco1");
94 //Check method FindComponentID
95 _PTR(SComponent) sco3 = study->FindComponentID(sco1->GetID());
96 CPPUNIT_ASSERT(sco3 && sco3->GetID() == sco1->GetID());
98 //Try to find component with empty id
99 CPPUNIT_ASSERT(!study->FindComponentID(""));
101 _PTR(SObject) so1 = studyBuilder->NewObject(sco1);
103 _PTR(AttributeName) name_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
104 CPPUNIT_ASSERT(name_attr_so1);
105 name_attr_so1->SetValue("so1");
107 //Create an attribute AttributeIOR
108 _PTR(AttributeIOR) ior_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeIOR");
109 CPPUNIT_ASSERT(ior_attr_so1);
111 std::string ior = _orb->object_to_string(_study);
112 ior_attr_so1->SetValue(ior);
114 _PTR(SObject) so2 = studyBuilder->NewObject(so1);
116 _PTR(AttributeName) name_attr_so2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
117 CPPUNIT_ASSERT(name_attr_so2);
118 name_attr_so2->SetValue("so2");
120 //Check method FindObject
121 _PTR(SObject) so3 = study->FindObject("so1");
122 CPPUNIT_ASSERT(so3 && so3->GetID() == so1->GetID());
124 //Try to find SObject with empty name
125 CPPUNIT_ASSERT(!study->FindObject(""));
127 //Check method FindObjectID
128 _PTR(SObject) so4 = study->FindObjectID(so1->GetID());
129 CPPUNIT_ASSERT(so4 && so4->GetID() == so1->GetID());
131 //Try to find SObject with empty ID
132 //CPPUNIT_ASSERT(!study->FindObjectID(""));
134 //Check method FindObjectByName
135 std::vector< _PTR(SObject) > v = study->FindObjectByName("so1", sco1->ComponentDataType());
136 CPPUNIT_ASSERT(v.size()==1 && v[0]->GetID() == so1->GetID());
138 //Try to find SObject with empty name and empty component type
139 CPPUNIT_ASSERT((study->FindObjectByName("", "")).size() == 0);
141 //Check method FindObjectByPath
142 _PTR(SObject) path_so = study->FindObjectByPath("/"+sco1->GetName()+"/"+so1->GetName());
143 CPPUNIT_ASSERT(path_so && path_so->GetID() == so1->GetID());
145 //Check method FindObjectIOR
146 _PTR(SObject) so5 = study->FindObjectIOR(ior);
147 CPPUNIT_ASSERT(so5 && so5->GetID() == so1->GetID());
149 //Try to find SObject with empty IOR
150 CPPUNIT_ASSERT(!study->FindObjectIOR(""));
152 //Check method GetObjectPath
153 std::string path = study->GetObjectPath(so2);
155 //Try to get path of NULL SObject
156 _PTR(SObject) emptySO;
157 path = study->GetObjectPath(emptySO);
158 CPPUNIT_ASSERT(path.empty());
160 //Check method SetContext
161 study->SetContext("/sco1");
162 CPPUNIT_ASSERT(study->GetContext() == "/sco1");
164 //Check method FindObjectByPath
165 _PTR(SObject) so6 = study->FindObjectByPath("so1");
166 CPPUNIT_ASSERT(so6 && so6->GetID() == so1->GetID());
169 //Try to find SObject with empty path
170 _PTR(SObject) tmp = study->FindObjectByPath(""); //Must return the Context SObject
171 CPPUNIT_ASSERT(tmp && tmp->GetID() == sco1->GetID());
173 study->SetContext("/"); //Root
175 //Check method GetObjectNames
176 std::vector<std::string> vs = study->GetObjectNames("/sco1");
177 CPPUNIT_ASSERT(vs.size() == 2);
179 //Check method GetDirectoryNames
180 _PTR(AttributeLocalID) locid_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeLocalID");
181 CPPUNIT_ASSERT(locid_attr_sco1);
182 locid_attr_sco1->SetValue(16661); //DIRECTORYID
183 _PTR(AttributeLocalID) locid_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeLocalID");
184 CPPUNIT_ASSERT(locid_attr_so1);
185 locid_attr_so1->SetValue(16661); //DIRECTORYID
186 vs = study->GetDirectoryNames(""); //Empty context (the current is taken)
187 CPPUNIT_ASSERT(vs.size() == 2);
189 //Check method GetFileNames
190 locid_attr_sco1->SetValue(26662); //FILELOCALID
191 _PTR(AttributePersistentRef) persref_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributePersistentRef");
192 CPPUNIT_ASSERT(persref_attr_sco1);
193 persref_attr_sco1->SetValue("FILE: filename1");
194 locid_attr_so1->SetValue(26662); //FILELOCALID
195 _PTR(AttributePersistentRef) persref_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributePersistentRef");
196 CPPUNIT_ASSERT(persref_attr_so1);
197 persref_attr_so1->SetValue("FILE: filename2");
198 vs = study->GetFileNames("");
199 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "filename1" && vs[1] == "filename2");
201 //Check method FindDependances
202 studyBuilder->Addreference(so2, so1);
203 studyBuilder->Addreference(sco1, so1);
204 std::vector< _PTR(SObject) > vso = study->FindDependances(so1);
205 CPPUNIT_ASSERT(vso.size() == 2 && vso[0]->GetID() == sco1->GetID() && vso[1]->GetID() == so2->GetID());
207 //Check method GetProperties
208 _PTR(AttributeStudyProperties) sp = study->GetProperties();
211 //Check Lock functionality
212 /*sp->SetLocked(true);
213 bool isLockRaised = false;
215 name_attr_so1->SetValue("test");
220 CPPUNIT_ASSERT(isLockRaised);
222 sp->SetLocked(false);
223 isLockRaised = false;
225 name_attr_so1->SetValue("test");
230 CPPUNIT_ASSERT(!isLockRaised);*/
232 //Check method GetLastModificationDate
233 sp->SetModification("srn", 1, 2, 3, 4, 5);
234 sp->SetModification("srn", 6, 7, 8, 9, 10);
235 std::string date = study->GetLastModificationDate();
237 CPPUNIT_ASSERT(date == "08/09/0010 07:06");
239 //Check method GetModificationsDate
240 vs = study->GetModificationsDate();
241 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "03/04/0005 02:01" && vs[1] == "08/09/0010 07:06");
243 //Check method GetCommonParameters
244 _PTR(AttributeParameter) cp = study->GetCommonParameters("id", 1); //Save point = 1
246 cp->SetBool("test_true", true);
247 cp->SetBool("test_false", false);
248 _PTR(AttributeParameter) cp2 = study->GetCommonParameters("id", 1); //Save point = 1
250 CPPUNIT_ASSERT(cp2->GetBool("test_true") && !cp2->GetBool("test_false"));
251 _PTR(AttributeParameter) cp21 = study->GetCommonParameters("id", 2); //Save point = 2
252 CPPUNIT_ASSERT(cp21);
253 CPPUNIT_ASSERT(!cp21->IsSet("test_true", PT_BOOLEAN) && !cp21->IsSet("test_false", PT_BOOLEAN));
255 //Check method GetModuleParameters
256 _PTR(AttributeParameter) cp3 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
258 cp3->SetBool("test_true", true);
259 cp3->SetBool("test_false", false);
260 _PTR(AttributeParameter) cp4 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
262 CPPUNIT_ASSERT(cp4->GetBool("test_true") && !cp4->GetBool("test_false"));
263 _PTR(AttributeParameter) cp5 = study->GetModuleParameters("id", "module name 2", 1); //Save point = 1, name = "module name 2"
265 CPPUNIT_ASSERT(!cp5->IsSet("test_true", PT_BOOLEAN) && !cp5->IsSet("test_false", PT_BOOLEAN));
266 _PTR(AttributeParameter) cp6 = study->GetModuleParameters("id", "module name", 2); //Save point = 2, name = "module name"
268 CPPUNIT_ASSERT(!cp6->IsSet("test_true", PT_BOOLEAN) && !cp6->IsSet("test_false", PT_BOOLEAN));
270 //Check method GetUseCaseBuilder
271 _PTR(UseCaseBuilder) ub = study->GetUseCaseBuilder();
274 //Check method SetStudyLock
275 study->SetStudyLock("locker1");
277 //Check method IsStudyLocked
278 CPPUNIT_ASSERT(study->IsStudyLocked());
280 //Check method GetLockerID
281 study->SetStudyLock("locker2");
282 vs = study->GetLockerID();
283 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "locker1" && vs[1] == "locker2");
285 //Check method UnLockStudy
286 study->UnLockStudy("locker1");
287 CPPUNIT_ASSERT(study->IsStudyLocked());
288 vs = study->GetLockerID();
289 CPPUNIT_ASSERT(vs.size() == 1 && vs[0] == "locker2");
290 study->UnLockStudy("locker2");
291 CPPUNIT_ASSERT(!study->IsStudyLocked());
292 vs = study->GetLockerID();
293 CPPUNIT_ASSERT(vs.size() == 0);
295 //Check method EnableUseCaseAutoFilling
296 study->EnableUseCaseAutoFilling(false);
297 _PTR(SObject) uso1 = study->NewBuilder()->NewObject(sco1);
298 std::vector< _PTR(GenericAttribute) > va1 = uso1->GetAllAttributes();
299 CPPUNIT_ASSERT(va1.size() == 0);
301 study->EnableUseCaseAutoFilling(true);
302 _PTR(SObject) uso2 = study->NewBuilder()->NewObject(sco1);
303 std::vector< _PTR(GenericAttribute) > va2 = uso2->GetAllAttributes();
304 CPPUNIT_ASSERT(va2.size() == 1); // +AttributeTreeNode
306 //Check method DumpStudy
307 study->DumpStudy(".", "SRN", false, false);
309 std::fstream f("SRN.py");
311 buffer[81] = (char)0;
313 f.getline(buffer, 80);
314 std::string line(buffer);
317 system("rm -f SRN.py");
318 CPPUNIT_ASSERT(line.substr(0,50) == "### This file is generated automatically by SALOME");
321 bool isException = false;
323 study->Clear(); //Clear is called inside Study::Clear()
328 CPPUNIT_ASSERT(!isException);