1 // Copyright (C) 2007-2015 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()
30 //Create or find the Study manager
31 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
36 _PTR(Study) study = sm->NewStudy("Test");
38 //Check the creation of the study
39 CPPUNIT_ASSERT(study);
41 //Check method NewBuilder
42 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
43 CPPUNIT_ASSERT(studyBuilder);
45 //Check method NewComponentIterator
46 _PTR(SComponentIterator) componentIterator = study->NewComponentIterator();
48 CPPUNIT_ASSERT(componentIterator);
50 //Check method GetTransientReference
51 CPPUNIT_ASSERT(!study->GetTransientReference().empty());
53 //Check method StudyId
54 CPPUNIT_ASSERT(study->StudyId() > 0);
56 //Check method Name (get/set)
57 CPPUNIT_ASSERT(study->Name() == "Test");
58 study->Name("New name");
59 CPPUNIT_ASSERT(study->Name() == "New name");
62 //Check method URL (get/set)
64 CPPUNIT_ASSERT(study->URL() == "");
65 study->URL("some url");
66 CPPUNIT_ASSERT(study->URL() == "some url");
68 //Check method GetPersistentReference == URL
69 CPPUNIT_ASSERT(study->GetPersistentReference() == "some url");
71 //Check method IsSaved (get/set)
73 CPPUNIT_ASSERT(study->IsSaved());
74 study->IsSaved(false);
75 CPPUNIT_ASSERT(!study->IsSaved());
77 //Check method CreateObjectID
78 _PTR(SObject) so = study->CreateObjectID("0:2:1:3");
81 //Try to create SObject with empty and invalid entries
82 CPPUNIT_ASSERT(!study->CreateObjectID(""));
83 CPPUNIT_ASSERT(!study->CreateObjectID("entry"));
85 //Check method NewChildIterator
86 _PTR(ChildIterator) childIterator = study->NewChildIterator(so);
87 CPPUNIT_ASSERT(childIterator);
89 //Check method IsEmpty
90 CPPUNIT_ASSERT(!study->IsEmpty());
92 //Check method FindComponent
93 _PTR(SComponent) sco1 = studyBuilder->NewComponent("test1");
94 _PTR(SComponent) sco2 = study->FindComponent("test1");
95 CPPUNIT_ASSERT(sco1 && sco2);
96 CPPUNIT_ASSERT(sco1->GetID() == sco2->GetID());
97 _PTR(AttributeName) name_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeName");
98 CPPUNIT_ASSERT(name_attr_sco1);
99 name_attr_sco1->SetValue("sco1");
101 //Try to find component with empty type
102 CPPUNIT_ASSERT(!study->FindComponent(""));
104 //Check method GetComponentNames
105 std::vector<std::string> components = study->GetComponentNames(""); //The context doesn't matter
106 CPPUNIT_ASSERT(components.size() == 1 && components[0] == "sco1");
108 //Check method FindComponentID
109 _PTR(SComponent) sco3 = study->FindComponentID(sco1->GetID());
110 CPPUNIT_ASSERT(sco3 && sco3->GetID() == sco1->GetID());
112 //Try to find component with empty id
113 CPPUNIT_ASSERT(!study->FindComponentID(""));
115 _PTR(SObject) so1 = studyBuilder->NewObject(sco1);
117 _PTR(AttributeName) name_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
118 CPPUNIT_ASSERT(name_attr_so1);
119 name_attr_so1->SetValue("so1");
121 //Create an attribute AttributeIOR
122 _PTR(AttributeIOR) ior_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeIOR");
123 CPPUNIT_ASSERT(ior_attr_so1);
125 std::string ior = _orb->object_to_string(_sm);
126 ior_attr_so1->SetValue(ior);
128 _PTR(SObject) so2 = studyBuilder->NewObject(so1);
130 _PTR(AttributeName) name_attr_so2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
131 CPPUNIT_ASSERT(name_attr_so2);
132 name_attr_so2->SetValue("so2");
134 //Check method FindObject
135 _PTR(SObject) so3 = study->FindObject("so1");
136 CPPUNIT_ASSERT(so3 && so3->GetID() == so1->GetID());
138 //Try to find SObject with empty name
139 CPPUNIT_ASSERT(!study->FindObject(""));
141 //Check method FindObjectID
142 _PTR(SObject) so4 = study->FindObjectID(so1->GetID());
143 CPPUNIT_ASSERT(so4 && so4->GetID() == so1->GetID());
145 //Try to find SObject with empty ID
146 CPPUNIT_ASSERT(!study->FindObjectID(""));
148 //Check method FindObjectByName
149 std::vector< _PTR(SObject) > v = study->FindObjectByName("so1", sco1->ComponentDataType());
150 CPPUNIT_ASSERT(v.size()==1 && v[0]->GetID() == so1->GetID());
152 //Try to find SObject with empty name and empty component type
153 CPPUNIT_ASSERT((study->FindObjectByName("", "")).size() == 0);
155 //Check method FindObjectByPath
156 _PTR(SObject) path_so = study->FindObjectByPath("/"+sco1->GetName()+"/"+so1->GetName());
157 CPPUNIT_ASSERT(path_so && path_so->GetID() == so1->GetID());
159 //Check method FindObjectIOR
160 _PTR(SObject) so5 = study->FindObjectIOR(ior);
161 CPPUNIT_ASSERT(so5 && so5->GetID() == so1->GetID());
163 //Try to find SObject with empty IOR
164 CPPUNIT_ASSERT(!study->FindObjectIOR(""));
166 //Check method GetObjectPath
167 std::string path = study->GetObjectPath(so2);
169 //Try to get path of NULL SObject
170 _PTR(SObject) emptySO;
171 path = study->GetObjectPath(emptySO);
172 CPPUNIT_ASSERT(path.empty());
174 //Check method SetContext
175 study->SetContext("/sco1");
176 CPPUNIT_ASSERT(study->GetContext() == "/sco1");
178 //Check method FindObjectByPath
179 _PTR(SObject) so6 = study->FindObjectByPath("so1");
180 CPPUNIT_ASSERT(so6 && so6->GetID() == so1->GetID());
183 //Try to find SObject with empty path
184 _PTR(SObject) tmp = study->FindObjectByPath(""); //Must return the Context SObject
185 CPPUNIT_ASSERT(tmp && tmp->GetID() == sco1->GetID());
187 study->SetContext("/"); //Root
189 //Check method GetObjectNames
190 std::vector<std::string> vs = study->GetObjectNames("/sco1");
191 CPPUNIT_ASSERT(vs.size() == 2);
193 //Check method GetDirectoryNames
194 _PTR(AttributeLocalID) locid_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeLocalID");
195 CPPUNIT_ASSERT(locid_attr_sco1);
196 locid_attr_sco1->SetValue(16661); //DIRECTORYID
197 _PTR(AttributeLocalID) locid_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeLocalID");
198 CPPUNIT_ASSERT(locid_attr_so1);
199 locid_attr_so1->SetValue(16661); //DIRECTORYID
200 vs = study->GetDirectoryNames(""); //Empty context (the current is taken)
201 CPPUNIT_ASSERT(vs.size() == 2);
203 //Check method GetFileNames
204 locid_attr_sco1->SetValue(26662); //FILELOCALID
205 _PTR(AttributePersistentRef) persref_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributePersistentRef");
206 CPPUNIT_ASSERT(persref_attr_sco1);
207 persref_attr_sco1->SetValue("FILE: filename1");
208 locid_attr_so1->SetValue(26662); //FILELOCALID
209 _PTR(AttributePersistentRef) persref_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributePersistentRef");
210 CPPUNIT_ASSERT(persref_attr_so1);
211 persref_attr_so1->SetValue("FILE: filename2");
212 vs = study->GetFileNames("");
213 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "filename1" && vs[1] == "filename2");
215 //Check method StudyId (get/set)
216 int id = study->StudyId();
218 CPPUNIT_ASSERT(study->StudyId() == -1);
221 //Check method FindDependances
222 studyBuilder->Addreference(so2, so1);
223 studyBuilder->Addreference(sco1, so1);
224 std::vector< _PTR(SObject) > vso = study->FindDependances(so1);
225 CPPUNIT_ASSERT(vso.size() == 2 && vso[0]->GetID() == so2->GetID() && vso[1]->GetID() == sco1->GetID());
227 //Check method GetProperties
228 _PTR(AttributeStudyProperties) sp = study->GetProperties();
231 //Check Lock functionality
233 bool isLockRaised = false;
235 name_attr_so1->SetValue("test");
240 CPPUNIT_ASSERT(isLockRaised);
242 sp->SetLocked(false);
243 isLockRaised = false;
245 name_attr_so1->SetValue("test");
250 CPPUNIT_ASSERT(!isLockRaised);
252 //Check method GetLastModificationDate
253 sp->SetModification("srn", 1, 2, 3, 4, 5);
254 sp->SetModification("srn", 6, 7, 8, 9, 10);
255 std::string date = study->GetLastModificationDate();
257 CPPUNIT_ASSERT(date == "08/09/0010 07:06");
259 //Check method GetModificationsDate
260 vs = study->GetModificationsDate();
261 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "03/04/0005 02:01" && vs[1] == "08/09/0010 07:06");
263 //Check method GetCommonParameters
264 _PTR(AttributeParameter) cp = study->GetCommonParameters("id", 1); //Save point = 1
266 cp->SetBool("test_true", true);
267 cp->SetBool("test_false", false);
268 _PTR(AttributeParameter) cp2 = study->GetCommonParameters("id", 1); //Save point = 1
270 CPPUNIT_ASSERT(cp2->GetBool("test_true") && !cp2->GetBool("test_false"));
271 _PTR(AttributeParameter) cp21 = study->GetCommonParameters("id", 2); //Save point = 2
272 CPPUNIT_ASSERT(cp21);
273 CPPUNIT_ASSERT(!cp21->IsSet("test_true", PT_BOOLEAN) && !cp21->IsSet("test_false", PT_BOOLEAN));
275 //Check method GetModuleParameters
276 _PTR(AttributeParameter) cp3 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
278 cp3->SetBool("test_true", true);
279 cp3->SetBool("test_false", false);
280 _PTR(AttributeParameter) cp4 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
282 CPPUNIT_ASSERT(cp4->GetBool("test_true") && !cp4->GetBool("test_false"));
283 _PTR(AttributeParameter) cp5 = study->GetModuleParameters("id", "module name 2", 1); //Save point = 1, name = "module name 2"
285 CPPUNIT_ASSERT(!cp5->IsSet("test_true", PT_BOOLEAN) && !cp5->IsSet("test_false", PT_BOOLEAN));
286 _PTR(AttributeParameter) cp6 = study->GetModuleParameters("id", "module name", 2); //Save point = 2, name = "module name"
288 CPPUNIT_ASSERT(!cp6->IsSet("test_true", PT_BOOLEAN) && !cp6->IsSet("test_false", PT_BOOLEAN));
290 //Check method GetUseCaseBuilder
291 _PTR(UseCaseBuilder) ub = study->GetUseCaseBuilder();
294 //Check method SetStudyLock
295 study->SetStudyLock("locker1");
297 //Check method IsStudyLocked
298 CPPUNIT_ASSERT(study->IsStudyLocked());
300 //Check method GetLockerID
301 study->SetStudyLock("locker2");
302 vs = study->GetLockerID();
303 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "locker1" && vs[1] == "locker2");
305 //Check method UnLockStudy
306 study->UnLockStudy("locker1");
307 CPPUNIT_ASSERT(study->IsStudyLocked());
308 vs = study->GetLockerID();
309 CPPUNIT_ASSERT(vs.size() == 1 && vs[0] == "locker2");
310 study->UnLockStudy("locker2");
311 CPPUNIT_ASSERT(!study->IsStudyLocked());
312 vs = study->GetLockerID();
313 CPPUNIT_ASSERT(vs.size() == 0);
315 //Check method EnableUseCaseAutoFilling
316 study->EnableUseCaseAutoFilling(false);
317 _PTR(SObject) uso1 = study->NewBuilder()->NewObject(sco1);
318 std::vector< _PTR(GenericAttribute) > va1 = uso1->GetAllAttributes();
319 CPPUNIT_ASSERT(va1.size() == 0);
321 study->EnableUseCaseAutoFilling(true);
322 _PTR(SObject) uso2 = study->NewBuilder()->NewObject(sco1);
323 std::vector< _PTR(GenericAttribute) > va2 = uso2->GetAllAttributes();
324 CPPUNIT_ASSERT(va2.size() == 1); // +AttributeTreeNode
326 //Check method DumpStudy
327 study->DumpStudy(".", "SRN", false, false);
329 std::fstream f("SRN.py");
331 buffer[81] = (char)0;
332 f.getline(buffer, 80);
333 std::string line(buffer);
336 system("rm -f SRN.py");
337 CPPUNIT_ASSERT(line == "### This file is generated by SALOME automatically by dump python functionality");
340 bool isException = false;
342 sm->Close(study); //Close is called inside StudyManager::Close
347 CPPUNIT_ASSERT(!isException);