1 // Copyright (C) 2007-2020 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_StudyBuilder
25 * Use code of SALOMEDS_StudyBuilder.cxx
28 void SALOMEDSTest::testStudyBuilder()
31 _PTR(Study) study(new SALOMEDS_Study(_study));
33 CPPUNIT_ASSERT(study);
35 //Create Study Builder
36 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
38 //Check the StudyBuilder creation
39 CPPUNIT_ASSERT(studyBuilder);
41 //Check method NewComponent
42 _PTR(SComponent) sco1 = studyBuilder->NewComponent("Test");
43 CPPUNIT_ASSERT(sco1 && sco1->ComponentDataType() == "Test");
45 //Check method DefineComponentInstance
46 std::string ior = _orb->object_to_string(_study);
47 studyBuilder->DefineComponentInstance(sco1, ior);
49 sco1->ComponentIOR(newior);
50 CPPUNIT_ASSERT(newior == ior);
52 //Check method RemoveComponent
53 studyBuilder->RemoveComponent(sco1);
54 _PTR(SComponent) sco2 = study->FindComponent("Test");
55 CPPUNIT_ASSERT(!sco2);
57 //Try to create and find the component with empty type
58 _PTR(SComponent) sco_empty = studyBuilder->NewComponent("");
59 CPPUNIT_ASSERT(!sco_empty);
61 _PTR(SComponent) sco3 = studyBuilder->NewComponent("NewComp");
64 //Check method NewObject
65 _PTR(SObject) so1 = studyBuilder->NewObject(sco3);
67 std::string id1 = so1->GetID();
69 //Check method NewObjectToTag
70 _PTR(SObject) so2 = studyBuilder->NewObjectToTag(so1, 2);
71 CPPUNIT_ASSERT(so2 && so2->Tag() == 2);
72 std::string id2 = so2->GetID();
74 //Check method FindOrCreateAttribute
75 _PTR(SObject) so3 = studyBuilder->NewObject(sco3);
77 _PTR(AttributeName) an3 = studyBuilder->FindOrCreateAttribute(so3, "AttributeName");
80 //Try to create attribute with invalid type
81 CPPUNIT_ASSERT(!studyBuilder->FindOrCreateAttribute(so3, "invalid type"));
83 //Check method FindAttribute
84 _PTR(GenericAttribute) ga;
85 CPPUNIT_ASSERT(studyBuilder->FindAttribute(so3, ga, "AttributeName"));
87 //Try to find attribute with invalid type
88 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "invalid type"));
90 //Check method RemoveObject
91 studyBuilder->RemoveObject(so3);
92 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "AttributeName"));
94 //Check method RemoveObjectWithChildren
95 _PTR(AttributeName) an2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeName");
97 studyBuilder->RemoveObjectWithChildren(so1);
98 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so2, ga, "AttributeName"));
100 //Check method RemoveAttribute
101 _PTR(AttributeName) an1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName");
103 CPPUNIT_ASSERT(studyBuilder->FindAttribute(so1, ga, "AttributeName"));
104 studyBuilder->RemoveAttribute(so1, "AttributeName");
105 CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so1, ga, "AttributeName"));
107 //Check method Addreference
108 studyBuilder->Addreference(so2, so1);
110 CPPUNIT_ASSERT(so2->ReferencedObject(refSO) && refSO->GetID() == so1->GetID());
112 //Try to set reference to NULL SObject
113 bool isRaised = false;
114 _PTR(SObject) empty_so;
116 studyBuilder->Addreference(so2, empty_so);
121 CPPUNIT_ASSERT(isRaised);
123 //Check method RemoveReference
124 studyBuilder->RemoveReference(so2);
125 CPPUNIT_ASSERT(!so2->ReferencedObject(refSO));
127 //Check method SetGUID and IsGUID
128 std::string value = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
129 studyBuilder->SetGUID(so1, value);
131 CPPUNIT_ASSERT(studyBuilder->IsGUID(so1, value));
134 //Check method UndoLimit (set/get)
135 studyBuilder->UndoLimit(10);
136 CPPUNIT_ASSERT(studyBuilder->UndoLimit() == 10);
139 //Check method SetName
140 studyBuilder->SetName(so1, "new name");
141 CPPUNIT_ASSERT(so1->GetName() == "new name");
143 //Try to set empty Name
144 studyBuilder->SetName(so1, "");
145 CPPUNIT_ASSERT(so1->GetName() == "");
147 //Check method SetComment
148 studyBuilder->SetComment(so1, "new comment");
149 CPPUNIT_ASSERT(so1->GetComment() == "new comment");
151 //Check method empty Comment
152 studyBuilder->SetComment(so1, "");
153 CPPUNIT_ASSERT(so1->GetComment() == "");
155 //Try to set empty IOR
156 studyBuilder->SetIOR(so1, "");
157 CPPUNIT_ASSERT(so1->GetIOR() == "");
159 //Check method SetIOR
160 studyBuilder->SetIOR(so1, ior);
161 CPPUNIT_ASSERT(so1->GetIOR() == ior);
165 //Check method LoadWith
166 _PTR(Study) study2(new SALOMEDS_Study(new SALOMEDSImpl_Study()));
168 SALOME_NamingService NS(_orb);
169 CORBA::Object_var obj = SALOME_LifeCycleCORBA(&NS).FindOrLoad_Component("FactoryServer", "SMESH");
170 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
172 MESSAGE("Created a new SMESH component");
174 SALOMEDS::Driver_var drv = SALOMEDS::Driver::_narrow(obj);
175 CPPUNIT_ASSERT(!CORBA::is_nil(drv));
177 _PTR(StudyBuilder) sb2 = study2->NewBuilder();
178 _PTR(SComponent) sco = sb2->NewComponent("SMESH");
180 ior = _orb->object_to_string(drv);
181 sb2->DefineComponentInstance(sco, ior);
183 study2->SaveAs("srn_SALOMEDS_UnitTests.hdf", false, false);
186 _PTR(Study) study3(new SALOMEDS_Study(new SALOMEDSImpl_Study()));
187 study3->Open("srn_SALOMEDS_UnitTests.hdf");
188 _PTR(StudyBuilder) sb3 = study3->NewBuilder();
189 _PTR(SComponent) aComp = study3->FindComponent("SMESH");
190 CPPUNIT_ASSERT(aComp);
192 CORBA::Object_var obj2 = SALOME_LifeCycleCORBA(&NS).FindOrLoad_Component("FactoryServer", "SMESH");
193 CPPUNIT_ASSERT(!CORBA::is_nil(obj2));
194 SALOMEDS::Driver_var drv2 = SALOMEDS::Driver::_narrow(obj2);
195 ior = _orb->object_to_string(drv2);
200 sb3->LoadWith(aComp, ior);
206 CPPUNIT_ASSERT(!isRaised);
209 aComp->ComponentIOR(ior);
210 CPPUNIT_ASSERT(!ior.empty());
212 system("rm -f srn_SALOMEDS_UnitTests.hdf");