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_SObject
23 * Use code of SALOMEDS_SObject.cxx
26 void SALOMEDSTest::testSObject()
28 //Create or find the Study manager
29 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
34 _PTR(Study) study = sm->NewStudy("TestSObject");
36 CPPUNIT_ASSERT(study);
38 //Create Study Builder
39 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
41 CPPUNIT_ASSERT(studyBuilder);
43 //Create a new SComponent
44 _PTR(SComponent) sco = studyBuilder->NewComponent("Test");
47 _PTR(SObject) so = studyBuilder->NewObjectToTag(sco, 2);
49 //Check the creation of the SObject
53 CPPUNIT_ASSERT(so->GetID() == "0:1:1:2");
56 CPPUNIT_ASSERT(so->Tag() == 2);
58 //Check method GetFatherComponent
59 _PTR(SComponent) father = so->GetFatherComponent();
60 CPPUNIT_ASSERT(father->GetID() == sco->GetID());
62 //Check method GetFather
63 _PTR(SObject) so1 = studyBuilder->NewObject(so);
64 CPPUNIT_ASSERT(so1->GetFather()->GetID() == so->GetID());
66 //Check method FindAttribute
68 _PTR(AttributeIOR) _attrIOR = studyBuilder->FindOrCreateAttribute(so, "AttributeIOR");
69 _PTR(AttributeName) _attrName = studyBuilder->FindOrCreateAttribute(so, "AttributeName");
70 _PTR(AttributeComment) _attrComment = studyBuilder->FindOrCreateAttribute(so, "AttributeComment");
72 string ior = _orb->object_to_string(_sm);
73 _attrIOR->SetValue(ior);
74 _attrName->SetValue("SO name");
75 _attrComment->SetValue("SO comment");
77 _PTR(GenericAttribute) ga;
78 CPPUNIT_ASSERT(so->FindAttribute(ga, "AttributeIOR"));
80 //Try to find attribute with empty type
81 CPPUNIT_ASSERT(!so->FindAttribute(ga, ""));
83 //Check method ReferencedObject
84 studyBuilder->Addreference(so1, so);
86 CPPUNIT_ASSERT(so1->ReferencedObject(so2));
87 CPPUNIT_ASSERT(so2->GetID() == so->GetID());
89 //Check method FindSubObject
90 CPPUNIT_ASSERT(so->FindSubObject(1, so2));
91 CPPUNIT_ASSERT(so2->GetID() == so1->GetID());
93 //Check method GetStudy
94 CPPUNIT_ASSERT(so->GetStudy()->StudyId() == study->StudyId());
98 CPPUNIT_ASSERT(so->Name() == "test");
100 //Check method GetAllAttributes
101 vector< _PTR(GenericAttribute) > v = so->GetAllAttributes();
103 CPPUNIT_ASSERT(v.size() == 5); //+AttributeTarget +AttributeTreeNode
105 //Check method GetName
106 CPPUNIT_ASSERT(so->GetName() == "SO name");
108 //Check method GetComment
109 CPPUNIT_ASSERT(so->GetComment() == "SO comment");
111 //Check method GetIOR
112 CPPUNIT_ASSERT(so->GetIOR() == ior);
115 CPPUNIT_ASSERT(so->Depth() == 3);
117 //Check method GetObject
118 CORBA::Object_var obj = dynamic_cast<SALOMEDS_SObject*>(so.get())->GetObject();
119 CPPUNIT_ASSERT(!CORBA::is_nil(obj));