Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/yacs.git] / src / SALOMEDS / Test / SALOMEDSTest_SObject.cxx
1 // Copyright (C) 2006  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 /*!
22  * Check all methods of SALOMEDS_SObject
23  * Use code of SALOMEDS_SObject.cxx
24  */
25
26 void SALOMEDSTest::testSObject()
27 {
28   //Create or find the Study manager
29   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
30
31   CPPUNIT_ASSERT(sm);
32
33   //Create a new study
34   _PTR(Study) study = sm->NewStudy("TestSObject");
35
36   CPPUNIT_ASSERT(study);
37
38   //Create Study Builder
39   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
40
41   CPPUNIT_ASSERT(studyBuilder);
42
43   //Create a new SComponent
44   _PTR(SComponent) sco = studyBuilder->NewComponent("Test");
45
46   //Create new SObject
47   _PTR(SObject) so = studyBuilder->NewObjectToTag(sco, 2);
48
49   //Check the creation of the SObject
50   CPPUNIT_ASSERT(so);
51
52   //Check method GetID
53   CPPUNIT_ASSERT(so->GetID() == "0:1:1:2");
54
55   //Check method Tag
56   CPPUNIT_ASSERT(so->Tag() == 2);
57
58   //Check method GetFatherComponent
59   _PTR(SComponent) father = so->GetFatherComponent();
60   CPPUNIT_ASSERT(father->GetID() == sco->GetID());
61
62   //Check method GetFather
63   _PTR(SObject) so1 = studyBuilder->NewObject(so);
64   CPPUNIT_ASSERT(so1->GetFather()->GetID() == so->GetID());
65
66   //Check method FindAttribute
67      
68   _PTR(AttributeIOR) _attrIOR = studyBuilder->FindOrCreateAttribute(so, "AttributeIOR");
69   _PTR(AttributeName) _attrName = studyBuilder->FindOrCreateAttribute(so, "AttributeName");
70   _PTR(AttributeComment) _attrComment = studyBuilder->FindOrCreateAttribute(so, "AttributeComment"); 
71
72    string ior = _orb->object_to_string(_sm);
73   _attrIOR->SetValue(ior);
74   _attrName->SetValue("SO name");
75   _attrComment->SetValue("SO comment");
76
77   _PTR(GenericAttribute) ga;
78   CPPUNIT_ASSERT(so->FindAttribute(ga, "AttributeIOR"));
79
80   //Try to find attribute with empty type
81   CPPUNIT_ASSERT(!so->FindAttribute(ga, ""));
82
83   //Check method ReferencedObject
84   studyBuilder->Addreference(so1, so);
85   _PTR(SObject) so2; 
86   CPPUNIT_ASSERT(so1->ReferencedObject(so2));
87   CPPUNIT_ASSERT(so2->GetID() == so->GetID());
88
89   //Check method FindSubObject
90   CPPUNIT_ASSERT(so->FindSubObject(1, so2));
91   CPPUNIT_ASSERT(so2->GetID() == so1->GetID());
92
93   //Check method GetStudy
94   CPPUNIT_ASSERT(so->GetStudy()->StudyId() == study->StudyId());
95
96   //Check methods Name
97   so->Name("test");
98   CPPUNIT_ASSERT(so->Name() == "test");
99
100   //Check method GetAllAttributes
101   vector< _PTR(GenericAttribute) > v = so->GetAllAttributes();
102    
103   CPPUNIT_ASSERT(v.size() == 5); //+AttributeTarget +AttributeTreeNode
104
105   //Check method GetName
106   CPPUNIT_ASSERT(so->GetName() == "SO name");
107
108   //Check method GetComment
109   CPPUNIT_ASSERT(so->GetComment() == "SO comment");
110
111   //Check method GetIOR
112   CPPUNIT_ASSERT(so->GetIOR() == ior);
113
114   //Check method Depth
115   CPPUNIT_ASSERT(so->Depth() == 3);
116
117   //Check method GetObject
118   CORBA::Object_var obj = dynamic_cast<SALOMEDS_SObject*>(so.get())->GetObject();
119   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
120
121   sm->Close(study);
122 }
123
124
125