Back to index

salome-kernel  6.5.0
SALOMEDSTest_SObject.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00028 void SALOMEDSTest::testSObject()
00029 {
00030   //Create or find the Study manager
00031   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
00032 
00033   CPPUNIT_ASSERT(sm);
00034 
00035   //Create a new study
00036   _PTR(Study) study = sm->NewStudy("TestSObject");
00037 
00038   CPPUNIT_ASSERT(study);
00039 
00040   //Create Study Builder
00041   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
00042 
00043   CPPUNIT_ASSERT(studyBuilder);
00044 
00045   //Create a new SComponent
00046   _PTR(SComponent) sco = studyBuilder->NewComponent("Test");
00047 
00048   //Create new SObject
00049   _PTR(SObject) so = studyBuilder->NewObjectToTag(sco, 2);
00050 
00051   //Check the creation of the SObject
00052   CPPUNIT_ASSERT(so);
00053 
00054   //Check method GetID
00055   CPPUNIT_ASSERT(so->GetID() == "0:1:1:2");
00056 
00057   //Check method Tag
00058   CPPUNIT_ASSERT(so->Tag() == 2);
00059 
00060   //Check method GetFatherComponent
00061   _PTR(SComponent) father = so->GetFatherComponent();
00062   CPPUNIT_ASSERT(father->GetID() == sco->GetID());
00063 
00064   //Check method GetFather
00065   _PTR(SObject) so1 = studyBuilder->NewObject(so);
00066   CPPUNIT_ASSERT(so1->GetFather()->GetID() == so->GetID());
00067 
00068   //Check method FindAttribute
00069      
00070   _PTR(AttributeIOR) _attrIOR = studyBuilder->FindOrCreateAttribute(so, "AttributeIOR");
00071   _PTR(AttributeName) _attrName = studyBuilder->FindOrCreateAttribute(so, "AttributeName");
00072   _PTR(AttributeComment) _attrComment = studyBuilder->FindOrCreateAttribute(so, "AttributeComment"); 
00073 
00074    std::string ior = _orb->object_to_string(_sm);
00075   _attrIOR->SetValue(ior);
00076   _attrName->SetValue("SO name");
00077   _attrComment->SetValue("SO comment");
00078 
00079   _PTR(GenericAttribute) ga;
00080   CPPUNIT_ASSERT(so->FindAttribute(ga, "AttributeIOR"));
00081 
00082   //Try to find attribute with empty type
00083   CPPUNIT_ASSERT(!so->FindAttribute(ga, ""));
00084 
00085   //Check method ReferencedObject
00086   studyBuilder->Addreference(so1, so);
00087   _PTR(SObject) so2; 
00088   CPPUNIT_ASSERT(so1->ReferencedObject(so2));
00089   CPPUNIT_ASSERT(so2->GetID() == so->GetID());
00090 
00091   //Check method FindSubObject
00092   CPPUNIT_ASSERT(so->FindSubObject(1, so2));
00093   CPPUNIT_ASSERT(so2->GetID() == so1->GetID());
00094 
00095   //Check method GetStudy
00096   CPPUNIT_ASSERT(so->GetStudy()->StudyId() == study->StudyId());
00097 
00098   //Check methods Name
00099   so->Name("test");
00100   CPPUNIT_ASSERT(so->Name() == "test");
00101 
00102   //Check method GetAllAttributes
00103   std::vector< _PTR(GenericAttribute) > v = so->GetAllAttributes();
00104    
00105   CPPUNIT_ASSERT(v.size() == 5); //+AttributeTarget +AttributeTreeNode
00106 
00107   //Check method GetName
00108   CPPUNIT_ASSERT(so->GetName() == "SO name");
00109 
00110   //Check method GetComment
00111   CPPUNIT_ASSERT(so->GetComment() == "SO comment");
00112 
00113   //Check method GetIOR
00114   CPPUNIT_ASSERT(so->GetIOR() == ior);
00115 
00116   //Check method Depth
00117   CPPUNIT_ASSERT(so->Depth() == 3);
00118 
00119   //Check method GetObject
00120   CORBA::Object_var obj = dynamic_cast<SALOMEDS_SObject*>(so.get())->GetObject();
00121   CPPUNIT_ASSERT(!CORBA::is_nil(obj));
00122 
00123   sm->Close(study);
00124 }
00125 
00126 
00127