1 // Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 * Check all methods of SALOMEDS_Study
23 * Use code of SALOMEDS_Study.cxx
26 void SALOMEDSTest::testStudy()
28 //Create or find the Study manager
29 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
34 _PTR(Study) study = sm->NewStudy("Test");
36 //Check the creation of the study
37 CPPUNIT_ASSERT(study);
39 //Check method NewBuilder
40 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
41 CPPUNIT_ASSERT(studyBuilder);
43 //Check method NewComponentIterator
44 _PTR(SComponentIterator) componentIterator = study->NewComponentIterator();
46 CPPUNIT_ASSERT(componentIterator);
48 //Check method GetTransientReference
49 CPPUNIT_ASSERT(!study->GetTransientReference().empty());
51 //Check method StudyId
52 CPPUNIT_ASSERT(study->StudyId() > 0);
54 //Check method Name (get/set)
55 CPPUNIT_ASSERT(study->Name() == "Test");
56 study->Name("New name");
57 CPPUNIT_ASSERT(study->Name() == "New name");
60 //Check method URL (get/set)
62 CPPUNIT_ASSERT(study->URL() == "");
63 study->URL("some url");
64 CPPUNIT_ASSERT(study->URL() == "some url");
66 //Check method GetPersistentReference == URL
67 CPPUNIT_ASSERT(study->GetPersistentReference() == "some url");
69 //Check method IsSaved (get/set)
71 CPPUNIT_ASSERT(study->IsSaved());
72 study->IsSaved(false);
73 CPPUNIT_ASSERT(!study->IsSaved());
75 //Check method CreateObjectID
76 _PTR(SObject) so = study->CreateObjectID("0:2:1:3");
79 //Try to create SObject with empty and invalid entries
80 CPPUNIT_ASSERT(!study->CreateObjectID(""));
81 CPPUNIT_ASSERT(!study->CreateObjectID("entry"));
83 //Check method NewChildIterator
84 _PTR(ChildIterator) childIterator = study->NewChildIterator(so);
85 CPPUNIT_ASSERT(childIterator);
87 //Check method IsEmpty
88 CPPUNIT_ASSERT(!study->IsEmpty());
90 //Check method FindComponent
91 _PTR(SComponent) sco1 = studyBuilder->NewComponent("test1");
92 _PTR(SComponent) sco2 = study->FindComponent("test1");
93 CPPUNIT_ASSERT(sco1 && sco2);
94 CPPUNIT_ASSERT(sco1->GetID() == sco2->GetID());
95 _PTR(AttributeName) name_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeName");
96 CPPUNIT_ASSERT(name_attr_sco1);
97 name_attr_sco1->SetValue("sco1");
99 //Try to find component with empty type
100 CPPUNIT_ASSERT(!study->FindComponent(""));
102 //Check method GetComponentNames
103 vector<string> components = study->GetComponentNames(""); //The context doesn't matter
104 CPPUNIT_ASSERT(components.size() == 1 && components[0] == "sco1");
106 //Check method FindComponentID
107 _PTR(SComponent) sco3 = study->FindComponentID(sco1->GetID());
108 CPPUNIT_ASSERT(sco3 && sco3->GetID() == sco1->GetID());
110 //Try to find component with empty id
111 CPPUNIT_ASSERT(!study->FindComponentID(""));
113 _PTR(SObject) so1 = studyBuilder->NewObject(sco1);
115 _PTR(AttributeName) name_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
116 CPPUNIT_ASSERT(name_attr_so1);
117 name_attr_so1->SetValue("so1");
119 //Create an attribute AttributeIOR
120 _PTR(AttributeIOR) ior_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeIOR");
121 CPPUNIT_ASSERT(ior_attr_so1);
123 string ior = _orb->object_to_string(_sm);
124 ior_attr_so1->SetValue(ior);
126 _PTR(SObject) so2 = studyBuilder->NewObject(so1);
128 _PTR(AttributeName) name_attr_so2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
129 CPPUNIT_ASSERT(name_attr_so2);
130 name_attr_so2->SetValue("so2");
132 //Check method FindObject
133 _PTR(SObject) so3 = study->FindObject("so1");
134 CPPUNIT_ASSERT(so3 && so3->GetID() == so1->GetID());
136 //Try to find SObject with empty name
137 CPPUNIT_ASSERT(!study->FindObject(""));
139 //Check method FindObjectID
140 _PTR(SObject) so4 = study->FindObjectID(so1->GetID());
141 CPPUNIT_ASSERT(so4 && so4->GetID() == so1->GetID());
143 //Try to find SObject with empty ID
144 CPPUNIT_ASSERT(!study->FindObjectID(""));
146 //Check method FindObjectByName
147 vector< _PTR(SObject) > v = study->FindObjectByName("so1", sco1->ComponentDataType());
148 CPPUNIT_ASSERT(v.size()==1 && v[0]->GetID() == so1->GetID());
150 //Try to find SObject with empty name and empty component type
151 CPPUNIT_ASSERT((study->FindObjectByName("", "")).size() == 0);
153 //Check method FindObjectByPath
154 _PTR(SObject) path_so = study->FindObjectByPath("/"+sco1->GetName()+"/"+so1->GetName());
155 CPPUNIT_ASSERT(path_so && path_so->GetID() == so1->GetID());
157 //Check method FindObjectIOR
158 _PTR(SObject) so5 = study->FindObjectIOR(ior);
159 CPPUNIT_ASSERT(so5 && so5->GetID() == so1->GetID());
161 //Try to find SObject with empty IOR
162 CPPUNIT_ASSERT(!study->FindObjectIOR(""));
164 //Check method GetObjectPath
165 string path = study->GetObjectPath(so2);
167 //Try to get path of NULL SObject
168 _PTR(SObject) emptySO;
169 path = study->GetObjectPath(emptySO);
170 CPPUNIT_ASSERT(path.empty());
172 //Check method SetContext
173 study->SetContext("/sco1");
174 CPPUNIT_ASSERT(study->GetContext() == "/sco1");
176 //Check method FindObjectByPath
177 _PTR(SObject) so6 = study->FindObjectByPath("so1");
178 CPPUNIT_ASSERT(so6 && so6->GetID() == so1->GetID());
181 //Try to find SObject with empty path
182 _PTR(SObject) tmp = study->FindObjectByPath(""); //Must return the Context SObject
183 CPPUNIT_ASSERT(tmp && tmp->GetID() == sco1->GetID());
185 study->SetContext("/"); //Root
187 //Check method GetObjectNames
188 vector<string> vs = study->GetObjectNames("/sco1");
189 CPPUNIT_ASSERT(vs.size() == 2);
191 //Check method GetDirectoryNames
192 _PTR(AttributeLocalID) locid_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeLocalID");
193 CPPUNIT_ASSERT(locid_attr_sco1);
194 locid_attr_sco1->SetValue(16661); //DIRECTORYID
195 _PTR(AttributeLocalID) locid_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeLocalID");
196 CPPUNIT_ASSERT(locid_attr_so1);
197 locid_attr_so1->SetValue(16661); //DIRECTORYID
198 vs = study->GetDirectoryNames(""); //Empty context (the current is taken)
199 CPPUNIT_ASSERT(vs.size() == 2);
201 //Check method GetFileNames
202 locid_attr_sco1->SetValue(26662); //FILELOCALID
203 _PTR(AttributePersistentRef) persref_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributePersistentRef");
204 CPPUNIT_ASSERT(persref_attr_sco1);
205 persref_attr_sco1->SetValue("FILE: filename1");
206 locid_attr_so1->SetValue(26662); //FILELOCALID
207 _PTR(AttributePersistentRef) persref_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributePersistentRef");
208 CPPUNIT_ASSERT(persref_attr_so1);
209 persref_attr_so1->SetValue("FILE: filename2");
210 vs = study->GetFileNames("");
211 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "filename1" && vs[1] == "filename2");
213 //Check method StudyId (get/set)
214 int id = study->StudyId();
216 CPPUNIT_ASSERT(study->StudyId() == -1);
219 //Check method FindDependances
220 studyBuilder->Addreference(so2, so1);
221 studyBuilder->Addreference(sco1, so1);
222 vector< _PTR(SObject) > vso = study->FindDependances(so1);
223 CPPUNIT_ASSERT(vso.size() == 2 && vso[0]->GetID() == so2->GetID() && vso[1]->GetID() == sco1->GetID());
225 //Check method GetProperties
226 _PTR(AttributeStudyProperties) sp = study->GetProperties();
229 //Check Lock functionality
231 bool isLockRaised = false;
233 name_attr_so1->SetValue("test");
238 CPPUNIT_ASSERT(isLockRaised);
240 sp->SetLocked(false);
241 isLockRaised = false;
243 name_attr_so1->SetValue("test");
248 CPPUNIT_ASSERT(!isLockRaised);
250 //Check method GetLastModificationDate
251 sp->SetModification("srn", 1, 2, 3, 4, 5);
252 sp->SetModification("srn", 6, 7, 8, 9, 10);
253 string date = study->GetLastModificationDate();
255 CPPUNIT_ASSERT(date == "08/09/0010 07:06");
257 //Check method GetModificationsDate
258 vs = study->GetModificationsDate();
259 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "03/04/0005 02:01" && vs[1] == "08/09/0010 07:06");
261 //Check method GetCommonParameters
262 _PTR(AttributeParameter) cp = study->GetCommonParameters("id", 1); //Save point = 1
264 cp->SetBool("test_true", true);
265 cp->SetBool("test_false", false);
266 _PTR(AttributeParameter) cp2 = study->GetCommonParameters("id", 1); //Save point = 1
268 CPPUNIT_ASSERT(cp2->GetBool("test_true") && !cp2->GetBool("test_false"));
269 _PTR(AttributeParameter) cp21 = study->GetCommonParameters("id", 2); //Save point = 2
270 CPPUNIT_ASSERT(cp21);
271 CPPUNIT_ASSERT(!cp21->IsSet("test_true", PT_BOOLEAN) && !cp21->IsSet("test_false", PT_BOOLEAN));
273 //Check method GetModuleParameters
274 _PTR(AttributeParameter) cp3 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
276 cp3->SetBool("test_true", true);
277 cp3->SetBool("test_false", false);
278 _PTR(AttributeParameter) cp4 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
280 CPPUNIT_ASSERT(cp4->GetBool("test_true") && !cp4->GetBool("test_false"));
281 _PTR(AttributeParameter) cp5 = study->GetModuleParameters("id", "module name 2", 1); //Save point = 1, name = "module name 2"
283 CPPUNIT_ASSERT(!cp5->IsSet("test_true", PT_BOOLEAN) && !cp5->IsSet("test_false", PT_BOOLEAN));
284 _PTR(AttributeParameter) cp6 = study->GetModuleParameters("id", "module name", 2); //Save point = 2, name = "module name"
286 CPPUNIT_ASSERT(!cp6->IsSet("test_true", PT_BOOLEAN) && !cp6->IsSet("test_false", PT_BOOLEAN));
288 //Check method GetUseCaseBuilder
289 _PTR(UseCaseBuilder) ub = study->GetUseCaseBuilder();
292 //Check method SetStudyLock
293 study->SetStudyLock("locker1");
295 //Check method IsStudyLocked
296 CPPUNIT_ASSERT(study->IsStudyLocked());
298 //Check method GetLockerID
299 study->SetStudyLock("locker2");
300 vs = study->GetLockerID();
301 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "locker1" && vs[1] == "locker2");
303 //Check method UnLockStudy
304 study->UnLockStudy("locker1");
305 CPPUNIT_ASSERT(study->IsStudyLocked());
306 vs = study->GetLockerID();
307 CPPUNIT_ASSERT(vs.size() == 1 && vs[0] == "locker2");
308 study->UnLockStudy("locker2");
309 CPPUNIT_ASSERT(!study->IsStudyLocked());
310 vs = study->GetLockerID();
311 CPPUNIT_ASSERT(vs.size() == 0);
313 //Check method EnableUseCaseAutoFilling
314 study->EnableUseCaseAutoFilling(false);
315 _PTR(SObject) uso1 = study->NewBuilder()->NewObject(sco1);
316 vector< _PTR(GenericAttribute) > va1 = uso1->GetAllAttributes();
317 CPPUNIT_ASSERT(va1.size() == 0);
319 study->EnableUseCaseAutoFilling(true);
320 _PTR(SObject) uso2 = study->NewBuilder()->NewObject(sco1);
321 vector< _PTR(GenericAttribute) > va2 = uso2->GetAllAttributes();
322 CPPUNIT_ASSERT(va2.size() == 1); // +AttributeTreeNode
324 //Check method DumpStudy
325 study->DumpStudy(".", "SRN", false);
329 buffer[81] = (char)0;
330 f.getline(buffer, 80);
334 system("rm -f SRN.py");
335 CPPUNIT_ASSERT(line == "### This file is generated by SALOME automatically by dump python functionality");
338 bool isException = false;
340 sm->Close(study); //Close is called inside StudyManager::Close
345 CPPUNIT_ASSERT(!isException);