1 // Copyright (C) 2007-2008 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.
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
23 * Check all methods of SALOMEDS_Study
24 * Use code of SALOMEDS_Study.cxx
27 void SALOMEDSTest::testStudy()
29 //Create or find the Study manager
30 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
35 _PTR(Study) study = sm->NewStudy("Test");
37 //Check the creation of the study
38 CPPUNIT_ASSERT(study);
40 //Check method NewBuilder
41 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
42 CPPUNIT_ASSERT(studyBuilder);
44 //Check method NewComponentIterator
45 _PTR(SComponentIterator) componentIterator = study->NewComponentIterator();
47 CPPUNIT_ASSERT(componentIterator);
49 //Check method GetTransientReference
50 CPPUNIT_ASSERT(!study->GetTransientReference().empty());
52 //Check method StudyId
53 CPPUNIT_ASSERT(study->StudyId() > 0);
55 //Check method Name (get/set)
56 CPPUNIT_ASSERT(study->Name() == "Test");
57 study->Name("New name");
58 CPPUNIT_ASSERT(study->Name() == "New name");
61 //Check method URL (get/set)
63 CPPUNIT_ASSERT(study->URL() == "");
64 study->URL("some url");
65 CPPUNIT_ASSERT(study->URL() == "some url");
67 //Check method GetPersistentReference == URL
68 CPPUNIT_ASSERT(study->GetPersistentReference() == "some url");
70 //Check method IsSaved (get/set)
72 CPPUNIT_ASSERT(study->IsSaved());
73 study->IsSaved(false);
74 CPPUNIT_ASSERT(!study->IsSaved());
76 //Check method CreateObjectID
77 _PTR(SObject) so = study->CreateObjectID("0:2:1:3");
80 //Try to create SObject with empty and invalid entries
81 CPPUNIT_ASSERT(!study->CreateObjectID(""));
82 CPPUNIT_ASSERT(!study->CreateObjectID("entry"));
84 //Check method NewChildIterator
85 _PTR(ChildIterator) childIterator = study->NewChildIterator(so);
86 CPPUNIT_ASSERT(childIterator);
88 //Check method IsEmpty
89 CPPUNIT_ASSERT(!study->IsEmpty());
91 //Check method FindComponent
92 _PTR(SComponent) sco1 = studyBuilder->NewComponent("test1");
93 _PTR(SComponent) sco2 = study->FindComponent("test1");
94 CPPUNIT_ASSERT(sco1 && sco2);
95 CPPUNIT_ASSERT(sco1->GetID() == sco2->GetID());
96 _PTR(AttributeName) name_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeName");
97 CPPUNIT_ASSERT(name_attr_sco1);
98 name_attr_sco1->SetValue("sco1");
100 //Try to find component with empty type
101 CPPUNIT_ASSERT(!study->FindComponent(""));
103 //Check method GetComponentNames
104 vector<string> components = study->GetComponentNames(""); //The context doesn't matter
105 CPPUNIT_ASSERT(components.size() == 1 && components[0] == "sco1");
107 //Check method FindComponentID
108 _PTR(SComponent) sco3 = study->FindComponentID(sco1->GetID());
109 CPPUNIT_ASSERT(sco3 && sco3->GetID() == sco1->GetID());
111 //Try to find component with empty id
112 CPPUNIT_ASSERT(!study->FindComponentID(""));
114 _PTR(SObject) so1 = studyBuilder->NewObject(sco1);
116 _PTR(AttributeName) name_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
117 CPPUNIT_ASSERT(name_attr_so1);
118 name_attr_so1->SetValue("so1");
120 //Create an attribute AttributeIOR
121 _PTR(AttributeIOR) ior_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeIOR");
122 CPPUNIT_ASSERT(ior_attr_so1);
124 string ior = _orb->object_to_string(_sm);
125 ior_attr_so1->SetValue(ior);
127 _PTR(SObject) so2 = studyBuilder->NewObject(so1);
129 _PTR(AttributeName) name_attr_so2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
130 CPPUNIT_ASSERT(name_attr_so2);
131 name_attr_so2->SetValue("so2");
133 //Check method FindObject
134 _PTR(SObject) so3 = study->FindObject("so1");
135 CPPUNIT_ASSERT(so3 && so3->GetID() == so1->GetID());
137 //Try to find SObject with empty name
138 CPPUNIT_ASSERT(!study->FindObject(""));
140 //Check method FindObjectID
141 _PTR(SObject) so4 = study->FindObjectID(so1->GetID());
142 CPPUNIT_ASSERT(so4 && so4->GetID() == so1->GetID());
144 //Try to find SObject with empty ID
145 CPPUNIT_ASSERT(!study->FindObjectID(""));
147 //Check method FindObjectByName
148 vector< _PTR(SObject) > v = study->FindObjectByName("so1", sco1->ComponentDataType());
149 CPPUNIT_ASSERT(v.size()==1 && v[0]->GetID() == so1->GetID());
151 //Try to find SObject with empty name and empty component type
152 CPPUNIT_ASSERT((study->FindObjectByName("", "")).size() == 0);
154 //Check method FindObjectByPath
155 _PTR(SObject) path_so = study->FindObjectByPath("/"+sco1->GetName()+"/"+so1->GetName());
156 CPPUNIT_ASSERT(path_so && path_so->GetID() == so1->GetID());
158 //Check method FindObjectIOR
159 _PTR(SObject) so5 = study->FindObjectIOR(ior);
160 CPPUNIT_ASSERT(so5 && so5->GetID() == so1->GetID());
162 //Try to find SObject with empty IOR
163 CPPUNIT_ASSERT(!study->FindObjectIOR(""));
165 //Check method GetObjectPath
166 string path = study->GetObjectPath(so2);
168 //Try to get path of NULL SObject
169 _PTR(SObject) emptySO;
170 path = study->GetObjectPath(emptySO);
171 CPPUNIT_ASSERT(path.empty());
173 //Check method SetContext
174 study->SetContext("/sco1");
175 CPPUNIT_ASSERT(study->GetContext() == "/sco1");
177 //Check method FindObjectByPath
178 _PTR(SObject) so6 = study->FindObjectByPath("so1");
179 CPPUNIT_ASSERT(so6 && so6->GetID() == so1->GetID());
182 //Try to find SObject with empty path
183 _PTR(SObject) tmp = study->FindObjectByPath(""); //Must return the Context SObject
184 CPPUNIT_ASSERT(tmp && tmp->GetID() == sco1->GetID());
186 study->SetContext("/"); //Root
188 //Check method GetObjectNames
189 vector<string> vs = study->GetObjectNames("/sco1");
190 CPPUNIT_ASSERT(vs.size() == 2);
192 //Check method GetDirectoryNames
193 _PTR(AttributeLocalID) locid_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributeLocalID");
194 CPPUNIT_ASSERT(locid_attr_sco1);
195 locid_attr_sco1->SetValue(16661); //DIRECTORYID
196 _PTR(AttributeLocalID) locid_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeLocalID");
197 CPPUNIT_ASSERT(locid_attr_so1);
198 locid_attr_so1->SetValue(16661); //DIRECTORYID
199 vs = study->GetDirectoryNames(""); //Empty context (the current is taken)
200 CPPUNIT_ASSERT(vs.size() == 2);
202 //Check method GetFileNames
203 locid_attr_sco1->SetValue(26662); //FILELOCALID
204 _PTR(AttributePersistentRef) persref_attr_sco1 = studyBuilder->FindOrCreateAttribute(sco1, "AttributePersistentRef");
205 CPPUNIT_ASSERT(persref_attr_sco1);
206 persref_attr_sco1->SetValue("FILE: filename1");
207 locid_attr_so1->SetValue(26662); //FILELOCALID
208 _PTR(AttributePersistentRef) persref_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributePersistentRef");
209 CPPUNIT_ASSERT(persref_attr_so1);
210 persref_attr_so1->SetValue("FILE: filename2");
211 vs = study->GetFileNames("");
212 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "filename1" && vs[1] == "filename2");
214 //Check method StudyId (get/set)
215 int id = study->StudyId();
217 CPPUNIT_ASSERT(study->StudyId() == -1);
220 //Check method FindDependances
221 studyBuilder->Addreference(so2, so1);
222 studyBuilder->Addreference(sco1, so1);
223 vector< _PTR(SObject) > vso = study->FindDependances(so1);
224 CPPUNIT_ASSERT(vso.size() == 2 && vso[0]->GetID() == so2->GetID() && vso[1]->GetID() == sco1->GetID());
226 //Check method GetProperties
227 _PTR(AttributeStudyProperties) sp = study->GetProperties();
230 //Check Lock functionality
232 bool isLockRaised = false;
234 name_attr_so1->SetValue("test");
239 CPPUNIT_ASSERT(isLockRaised);
241 sp->SetLocked(false);
242 isLockRaised = false;
244 name_attr_so1->SetValue("test");
249 CPPUNIT_ASSERT(!isLockRaised);
251 //Check method GetLastModificationDate
252 sp->SetModification("srn", 1, 2, 3, 4, 5);
253 sp->SetModification("srn", 6, 7, 8, 9, 10);
254 string date = study->GetLastModificationDate();
256 CPPUNIT_ASSERT(date == "08/09/0010 07:06");
258 //Check method GetModificationsDate
259 vs = study->GetModificationsDate();
260 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "03/04/0005 02:01" && vs[1] == "08/09/0010 07:06");
262 //Check method GetCommonParameters
263 _PTR(AttributeParameter) cp = study->GetCommonParameters("id", 1); //Save point = 1
265 cp->SetBool("test_true", true);
266 cp->SetBool("test_false", false);
267 _PTR(AttributeParameter) cp2 = study->GetCommonParameters("id", 1); //Save point = 1
269 CPPUNIT_ASSERT(cp2->GetBool("test_true") && !cp2->GetBool("test_false"));
270 _PTR(AttributeParameter) cp21 = study->GetCommonParameters("id", 2); //Save point = 2
271 CPPUNIT_ASSERT(cp21);
272 CPPUNIT_ASSERT(!cp21->IsSet("test_true", PT_BOOLEAN) && !cp21->IsSet("test_false", PT_BOOLEAN));
274 //Check method GetModuleParameters
275 _PTR(AttributeParameter) cp3 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
277 cp3->SetBool("test_true", true);
278 cp3->SetBool("test_false", false);
279 _PTR(AttributeParameter) cp4 = study->GetModuleParameters("id", "module name", 1); //Save point = 1, name = "module name"
281 CPPUNIT_ASSERT(cp4->GetBool("test_true") && !cp4->GetBool("test_false"));
282 _PTR(AttributeParameter) cp5 = study->GetModuleParameters("id", "module name 2", 1); //Save point = 1, name = "module name 2"
284 CPPUNIT_ASSERT(!cp5->IsSet("test_true", PT_BOOLEAN) && !cp5->IsSet("test_false", PT_BOOLEAN));
285 _PTR(AttributeParameter) cp6 = study->GetModuleParameters("id", "module name", 2); //Save point = 2, name = "module name"
287 CPPUNIT_ASSERT(!cp6->IsSet("test_true", PT_BOOLEAN) && !cp6->IsSet("test_false", PT_BOOLEAN));
289 //Check method GetUseCaseBuilder
290 _PTR(UseCaseBuilder) ub = study->GetUseCaseBuilder();
293 //Check method SetStudyLock
294 study->SetStudyLock("locker1");
296 //Check method IsStudyLocked
297 CPPUNIT_ASSERT(study->IsStudyLocked());
299 //Check method GetLockerID
300 study->SetStudyLock("locker2");
301 vs = study->GetLockerID();
302 CPPUNIT_ASSERT(vs.size() == 2 && vs[0] == "locker1" && vs[1] == "locker2");
304 //Check method UnLockStudy
305 study->UnLockStudy("locker1");
306 CPPUNIT_ASSERT(study->IsStudyLocked());
307 vs = study->GetLockerID();
308 CPPUNIT_ASSERT(vs.size() == 1 && vs[0] == "locker2");
309 study->UnLockStudy("locker2");
310 CPPUNIT_ASSERT(!study->IsStudyLocked());
311 vs = study->GetLockerID();
312 CPPUNIT_ASSERT(vs.size() == 0);
314 //Check method EnableUseCaseAutoFilling
315 study->EnableUseCaseAutoFilling(false);
316 _PTR(SObject) uso1 = study->NewBuilder()->NewObject(sco1);
317 vector< _PTR(GenericAttribute) > va1 = uso1->GetAllAttributes();
318 CPPUNIT_ASSERT(va1.size() == 0);
320 study->EnableUseCaseAutoFilling(true);
321 _PTR(SObject) uso2 = study->NewBuilder()->NewObject(sco1);
322 vector< _PTR(GenericAttribute) > va2 = uso2->GetAllAttributes();
323 CPPUNIT_ASSERT(va2.size() == 1); // +AttributeTreeNode
325 //Check method DumpStudy
326 study->DumpStudy(".", "SRN", false);
330 buffer[81] = (char)0;
331 f.getline(buffer, 80);
335 system("rm -f SRN.py");
336 CPPUNIT_ASSERT(line == "### This file is generated by SALOME automatically by dump python functionality");
339 bool isException = false;
341 sm->Close(study); //Close is called inside StudyManager::Close
346 CPPUNIT_ASSERT(!isException);