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_StudyBuilder
24 * Use code of SALOMEDS_StudyBuilder.cxx
27 void SALOMEDSTest::testStudyBuilder()
29 //Create or find the Study manager
30 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
35 _PTR(Study) study = sm->NewStudy("TestStudyBuilder");
37 CPPUNIT_ASSERT(study);
39 //Create Study Builder
40 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
42 //Check the StudyBuilder creation
43 CPPUNIT_ASSERT(studyBuilder);
45 //Check method NewComponent
46 _PTR(SComponent) sco1 = studyBuilder->NewComponent("Test");
47 CPPUNIT_ASSERT(sco1 && sco1->ComponentDataType() == "Test");
49 //Check method DefineComponentInstance
50 string ior = _orb->object_to_string(_sm);
51 studyBuilder->DefineComponentInstance(sco1, ior);
53 sco1->ComponentIOR(newior);
54 CPPUNIT_ASSERT(newior == ior);
56 //Check method RemoveComponent
57 studyBuilder->RemoveComponent(sco1);
58 _PTR(SComponent) sco2 = study->FindComponent("Test");
59 CPPUNIT_ASSERT(!sco2);
61 //Try to create and find the component with empty type
62 _PTR(SComponent) sco_empty = studyBuilder->NewComponent("");
63 CPPUNIT_ASSERT(!sco_empty);
65 _PTR(SComponent) sco3 = studyBuilder->NewComponent("NewComp");
68 //Check method NewObject
69 _PTR(SObject) so1 = studyBuilder->NewObject(sco3);
71 string id1 = so1->GetID();
73 //Check method NewObjectToTag
74 _PTR(SObject) so2 = studyBuilder->NewObjectToTag(so1, 2);
75 CPPUNIT_ASSERT(so2 && so2->Tag() == 2);
76 string id2 = so2->GetID();
78 //Check method FindOrCreateAttribute
79 _PTR(SObject) so3 = studyBuilder->NewObject(sco3);
81 _PTR(AttributeName) an3 = studyBuilder->FindOrCreateAttribute(so3, "AttributeName");
84 //Try to create attribute with invalid type
85 CPPUNIT_ASSERT(!studyBuilder->FindOrCreateAttribute(so3, "invalid type"));
87 //Check method FindAttribute
88 _PTR(GenericAttribute) ga;
89 CPPUNIT_ASSERT(studyBuilder->FindAttribute(so3, ga, "AttributeName"));
91 //Try to find attribute with invalid type
92 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "invalid type"));
94 //Check method RemoveObject
95 studyBuilder->RemoveObject(so3);
96 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "AttributeName"));
98 //Check method RemoveObjectWithChildren
99 _PTR(AttributeName) an2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
101 studyBuilder->RemoveObjectWithChildren(so1);
102 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so2, ga, "AttributeName"));
104 //Check method RemoveAttribute
105 _PTR(AttributeName) an1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
107 CPPUNIT_ASSERT(studyBuilder->FindAttribute(so1, ga, "AttributeName"));
108 studyBuilder->RemoveAttribute(so1, "AttributeName");
109 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so1, ga, "AttributeName"));
111 //Check method Addreference
112 studyBuilder->Addreference(so2, so1);
114 CPPUNIT_ASSERT(so2->ReferencedObject(refSO) && refSO->GetID() == so1->GetID());
116 //Try to set reference to NULL SObject
117 bool isRaised = false;
118 _PTR(SObject) empty_so;
120 studyBuilder->Addreference(so2, empty_so);
125 CPPUNIT_ASSERT(isRaised);
127 //Check method RemoveReference
128 studyBuilder->RemoveReference(so2);
129 CPPUNIT_ASSERT(!so2->ReferencedObject(refSO));
131 //Check method SetGUID and IsGUID
132 string value = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
133 studyBuilder->SetGUID(so1, value);
135 CPPUNIT_ASSERT(studyBuilder->IsGUID(so1, value));
138 //Check method UndoLimit (set/get)
139 studyBuilder->UndoLimit(10);
140 CPPUNIT_ASSERT(studyBuilder->UndoLimit() == 10);
143 //Check method SetName
144 studyBuilder->SetName(so1, "new name");
145 CPPUNIT_ASSERT(so1->GetName() == "new name");
147 //Try to set empty Name
148 studyBuilder->SetName(so1, "");
149 CPPUNIT_ASSERT(so1->GetName() == "");
151 //Check method SetComment
152 studyBuilder->SetComment(so1, "new comment");
153 CPPUNIT_ASSERT(so1->GetComment() == "new comment");
155 //Check method empty Comment
156 studyBuilder->SetComment(so1, "");
157 CPPUNIT_ASSERT(so1->GetComment() == "");
159 //Try to set empty IOR
160 studyBuilder->SetIOR(so1, "");
161 CPPUNIT_ASSERT(so1->GetIOR() == "");
163 //Check method SetIOR
164 studyBuilder->SetIOR(so1, ior);
165 CPPUNIT_ASSERT(so1->GetIOR() == ior);
169 //Check method LoadWith
170 _PTR(Study) study2 = sm->NewStudy("Study2");
172 SALOME_NamingService NS(_orb);
173 CORBA::Object_var obj = SALOME_LifeCycleCORBA(&NS).FindOrLoad_Component("FactoryServer", "SMESH");
174 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
176 MESSAGE("Created a new SMESH component");
178 SALOMEDS::Driver_var drv = SALOMEDS::Driver::_narrow(obj);
179 CPPUNIT_ASSERT(!CORBA::is_nil(drv));
181 _PTR(StudyBuilder) sb2 = study2->NewBuilder();
182 _PTR(SComponent) sco = sb2->NewComponent("SMESH");
184 ior = _orb->object_to_string(drv);
185 sb2->DefineComponentInstance(sco, ior);
187 sm->SaveAs("srn_SALOMEDS_UnitTests.hdf", study2, false);
190 _PTR(Study) study3 = sm->Open("srn_SALOMEDS_UnitTests.hdf");
191 _PTR(StudyBuilder) sb3 = study3->NewBuilder();
192 _PTR(SComponent) aComp = study3->FindComponent("SMESH");
193 CPPUNIT_ASSERT(aComp);
195 CORBA::Object_var obj2 = SALOME_LifeCycleCORBA(&NS).FindOrLoad_Component("FactoryServer", "SMESH");
196 CPPUNIT_ASSERT(!CORBA::is_nil(obj2));
197 SALOMEDS::Driver_var drv2 = SALOMEDS::Driver::_narrow(obj2);
198 ior = _orb->object_to_string(drv2);
203 sb3->LoadWith(aComp, ior);
210 CPPUNIT_ASSERT(!isRaised);
213 aComp->ComponentIOR(ior);
214 CPPUNIT_ASSERT(!ior.empty());
216 system("rm -f srn_SALOMEDS_UnitTests.hdf");
218 //Check method AddDirectory
219 _PTR(AttributeName) na1 = sb3->FindOrCreateAttribute(aComp, "AttributeName");
220 na1->SetValue("Component");
224 sb3->AddDirectory("/Component/Dir1");
230 CPPUNIT_ASSERT(!isRaised);
231 _PTR(SObject) so5 = study3->FindObjectByPath("/Component/Dir1");
236 sb3->AddDirectory("/Component/Dir1"); //Attempt to create the same directory
240 CPPUNIT_ASSERT(isRaised);
244 sb3->AddDirectory("/MyComponent/Dir1"); //Attempt to create the invalid directory
248 CPPUNIT_ASSERT(isRaised);