1 // Copyright (C) 2007-2013 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
24 * Check all methods of SALOMEDS_StudyBuilder
25 * Use code of SALOMEDS_StudyBuilder.cxx
28 void SALOMEDSTest::testStudyBuilder()
30 //Create or find the Study manager
31 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
36 _PTR(Study) study = sm->NewStudy("TestStudyBuilder");
38 CPPUNIT_ASSERT(study);
40 //Create Study Builder
41 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
43 //Check the StudyBuilder creation
44 CPPUNIT_ASSERT(studyBuilder);
46 //Check method NewComponent
47 _PTR(SComponent) sco1 = studyBuilder->NewComponent("Test");
48 CPPUNIT_ASSERT(sco1 && sco1->ComponentDataType() == "Test");
50 //Check method DefineComponentInstance
51 std::string ior = _orb->object_to_string(_sm);
52 studyBuilder->DefineComponentInstance(sco1, ior);
54 sco1->ComponentIOR(newior);
55 CPPUNIT_ASSERT(newior == ior);
57 //Check method RemoveComponent
58 studyBuilder->RemoveComponent(sco1);
59 _PTR(SComponent) sco2 = study->FindComponent("Test");
60 CPPUNIT_ASSERT(!sco2);
62 //Try to create and find the component with empty type
63 _PTR(SComponent) sco_empty = studyBuilder->NewComponent("");
64 CPPUNIT_ASSERT(!sco_empty);
66 _PTR(SComponent) sco3 = studyBuilder->NewComponent("NewComp");
69 //Check method NewObject
70 _PTR(SObject) so1 = studyBuilder->NewObject(sco3);
72 std::string id1 = so1->GetID();
74 //Check method NewObjectToTag
75 _PTR(SObject) so2 = studyBuilder->NewObjectToTag(so1, 2);
76 CPPUNIT_ASSERT(so2 && so2->Tag() == 2);
77 std::string id2 = so2->GetID();
79 //Check method FindOrCreateAttribute
80 _PTR(SObject) so3 = studyBuilder->NewObject(sco3);
82 _PTR(AttributeName) an3 = studyBuilder->FindOrCreateAttribute(so3, "AttributeName");
85 //Try to create attribute with invalid type
86 CPPUNIT_ASSERT(!studyBuilder->FindOrCreateAttribute(so3, "invalid type"));
88 //Check method FindAttribute
89 _PTR(GenericAttribute) ga;
90 CPPUNIT_ASSERT(studyBuilder->FindAttribute(so3, ga, "AttributeName"));
92 //Try to find attribute with invalid type
93 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "invalid type"));
95 //Check method RemoveObject
96 studyBuilder->RemoveObject(so3);
97 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "AttributeName"));
99 //Check method RemoveObjectWithChildren
100 _PTR(AttributeName) an2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
102 studyBuilder->RemoveObjectWithChildren(so1);
103 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so2, ga, "AttributeName"));
105 //Check method RemoveAttribute
106 _PTR(AttributeName) an1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
108 CPPUNIT_ASSERT(studyBuilder->FindAttribute(so1, ga, "AttributeName"));
109 studyBuilder->RemoveAttribute(so1, "AttributeName");
110 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so1, ga, "AttributeName"));
112 //Check method Addreference
113 studyBuilder->Addreference(so2, so1);
115 CPPUNIT_ASSERT(so2->ReferencedObject(refSO) && refSO->GetID() == so1->GetID());
117 //Try to set reference to NULL SObject
118 bool isRaised = false;
119 _PTR(SObject) empty_so;
121 studyBuilder->Addreference(so2, empty_so);
126 CPPUNIT_ASSERT(isRaised);
128 //Check method RemoveReference
129 studyBuilder->RemoveReference(so2);
130 CPPUNIT_ASSERT(!so2->ReferencedObject(refSO));
132 //Check method SetGUID and IsGUID
133 std::string value = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
134 studyBuilder->SetGUID(so1, value);
136 CPPUNIT_ASSERT(studyBuilder->IsGUID(so1, value));
139 //Check method UndoLimit (set/get)
140 studyBuilder->UndoLimit(10);
141 CPPUNIT_ASSERT(studyBuilder->UndoLimit() == 10);
144 //Check method SetName
145 studyBuilder->SetName(so1, "new name");
146 CPPUNIT_ASSERT(so1->GetName() == "new name");
148 //Try to set empty Name
149 studyBuilder->SetName(so1, "");
150 CPPUNIT_ASSERT(so1->GetName() == "");
152 //Check method SetComment
153 studyBuilder->SetComment(so1, "new comment");
154 CPPUNIT_ASSERT(so1->GetComment() == "new comment");
156 //Check method empty Comment
157 studyBuilder->SetComment(so1, "");
158 CPPUNIT_ASSERT(so1->GetComment() == "");
160 //Try to set empty IOR
161 studyBuilder->SetIOR(so1, "");
162 CPPUNIT_ASSERT(so1->GetIOR() == "");
164 //Check method SetIOR
165 studyBuilder->SetIOR(so1, ior);
166 CPPUNIT_ASSERT(so1->GetIOR() == ior);
170 //Check method LoadWith
171 _PTR(Study) study2 = sm->NewStudy("Study2");
173 SALOME_NamingService NS(_orb);
174 CORBA::Object_var obj = SALOME_LifeCycleCORBA(&NS).FindOrLoad_Component("FactoryServer", "SMESH");
175 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
177 MESSAGE("Created a new SMESH component");
179 SALOMEDS::Driver_var drv = SALOMEDS::Driver::_narrow(obj);
180 CPPUNIT_ASSERT(!CORBA::is_nil(drv));
182 _PTR(StudyBuilder) sb2 = study2->NewBuilder();
183 _PTR(SComponent) sco = sb2->NewComponent("SMESH");
185 ior = _orb->object_to_string(drv);
186 sb2->DefineComponentInstance(sco, ior);
188 sm->SaveAs("srn_SALOMEDS_UnitTests.hdf", study2, false);
191 _PTR(Study) study3 = sm->Open("srn_SALOMEDS_UnitTests.hdf");
192 _PTR(StudyBuilder) sb3 = study3->NewBuilder();
193 _PTR(SComponent) aComp = study3->FindComponent("SMESH");
194 CPPUNIT_ASSERT(aComp);
196 CORBA::Object_var obj2 = SALOME_LifeCycleCORBA(&NS).FindOrLoad_Component("FactoryServer", "SMESH");
197 CPPUNIT_ASSERT(!CORBA::is_nil(obj2));
198 SALOMEDS::Driver_var drv2 = SALOMEDS::Driver::_narrow(obj2);
199 ior = _orb->object_to_string(drv2);
204 sb3->LoadWith(aComp, ior);
211 CPPUNIT_ASSERT(!isRaised);
214 aComp->ComponentIOR(ior);
215 CPPUNIT_ASSERT(!ior.empty());
217 system("rm -f srn_SALOMEDS_UnitTests.hdf");
219 //Check method AddDirectory
220 _PTR(AttributeName) na1 = sb3->FindOrCreateAttribute(aComp, "AttributeName");
221 na1->SetValue("Component");
225 sb3->AddDirectory("/Component/Dir1");
231 CPPUNIT_ASSERT(!isRaised);
232 _PTR(SObject) so5 = study3->FindObjectByPath("/Component/Dir1");
237 sb3->AddDirectory("/Component/Dir1"); //Attempt to create the same directory
241 CPPUNIT_ASSERT(isRaised);
245 sb3->AddDirectory("/MyComponent/Dir1"); //Attempt to create the invalid directory
249 CPPUNIT_ASSERT(isRaised);