Back to index

salome-kernel  6.5.0
SALOMEDSTest_StudyManager.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 
00027 void SALOMEDSTest::testStudyManager()
00028 {
00029   //Create or find the Study manager
00030   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
00031 
00032   CPPUNIT_ASSERT(sm);
00033 
00034   //Check method NewStudy
00035   _PTR(Study) study1 = sm->NewStudy("Study1");
00036   CPPUNIT_ASSERT(study1);
00037 
00038   _PTR(Study) study2 = sm->NewStudy("Study2");
00039   CPPUNIT_ASSERT(study2);
00040 
00041   //Check method GetStudyByName
00042   _PTR(Study) study3 = sm->GetStudyByName("Study1");
00043   CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId());
00044   CPPUNIT_ASSERT(study3->Name() == study1->Name());
00045 
00046   //Check method GetStudyByName with empty name
00047   CPPUNIT_ASSERT(!sm->GetStudyByName(""));
00048 
00049   //Try to create Study with empty name
00050   _PTR(Study) study_empty = sm->NewStudy("");
00051   CPPUNIT_ASSERT(study_empty);
00052   CPPUNIT_ASSERT(sm->GetStudyByName(""));
00053   sm->Close(study_empty);
00054 
00055   //Check method FindStudyByID
00056   _PTR(Study) study4 = sm->GetStudyByID(study2->StudyId());
00057   CPPUNIT_ASSERT(study4->StudyId() == study2->StudyId());
00058   CPPUNIT_ASSERT(study4->Name() == study2->Name());
00059 
00060   //Check method GetOpenStudies
00061   std::vector<std::string> v = sm->GetOpenStudies();
00062   CPPUNIT_ASSERT(v.size() == 2);
00063 
00064   //Check method Close
00065   int id = study2->StudyId();
00066   sm->Close(study2);
00067   CPPUNIT_ASSERT(!sm->GetStudyByID(id));
00068 
00069   //Check method GetStudyByID for invalid ID
00070   CPPUNIT_ASSERT(!sm->GetStudyByID(-1));
00071 
00072   //Check methods CanPaste, CanCopy, Copy, Paste
00073   _PTR(StudyBuilder) sb1 = study1->NewBuilder();
00074   _PTR(SComponent) sco1 = sb1->NewComponent("Test");
00075   _PTR(SObject) so1 = sb1->NewObject(sco1);
00076   _PTR(AttributeName) na1 = sb1->FindOrCreateAttribute(so1, "AttributeName");
00077   CPPUNIT_ASSERT(na1);
00078   na1->SetValue("Some name");
00079 
00080   CPPUNIT_ASSERT(!sm->CanCopy(so1)); //The father component has no IOR
00081   
00082   CPPUNIT_ASSERT(sm->Copy(so1));
00083 
00084   CPPUNIT_ASSERT(!sm->CanPaste(so1)); //The father component has no IOR
00085 
00086   _PTR(SObject) so1_2 = sb1->NewObject(sco1);
00087   _PTR(SObject) pasted_so = sm->Paste(so1_2);
00088   CPPUNIT_ASSERT(pasted_so);
00089 
00090   _PTR(AttributeName) na2 = sb1->FindOrCreateAttribute(pasted_so, "AttributeName");
00091   CPPUNIT_ASSERT(na2 && na2->Value() == "Some name");
00092 
00093 
00094   //Check method SaveAs
00095   sm->SaveAs("srn_UnitTest_Save.hdf", study1, false);
00096   std::string url = study1->URL();
00097   sm->Close(study1);
00098 
00099   //Check method Open
00100   _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf");  //Contains Test component
00101   system("rm -f srn_UnitTest_Save.hdf");
00102   url = study1->URL();
00103   CPPUNIT_ASSERT(study1_opened);
00104   CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf");
00105 
00106   //Check method Save
00107   _PTR(StudyBuilder) sb3 = study1_opened->NewBuilder();
00108   _PTR(SComponent) sco3 = study1_opened->FindComponent("Test");
00109   CPPUNIT_ASSERT(sco3);
00110   //   Add a new SObject with AttributeName that contains "Saved study" string
00111   _PTR(SObject) so3 = sb3->NewObject(sco3);
00112   std::string soID = so3->GetID();
00113   _PTR(AttributeName) na3 = sb3->FindOrCreateAttribute(so3, "AttributeName");
00114   CPPUNIT_ASSERT(na3);
00115  
00116   na3->SetValue("Saved study");
00117 
00118   //   Save and close the study
00119   sm->Save(study1_opened, false);
00120 
00121   sm->Close(study1_opened);
00122 
00123   //  Open saved study and find the created SObject with AttributeName, then compare the stored string
00124   _PTR(Study) study2_opened = sm->Open("srn_UnitTest_Save.hdf");
00125 
00126   system("rm -f srn_UnitTest_Save.hdf");
00127 
00128   CPPUNIT_ASSERT(study2_opened);
00129 
00130   _PTR(SObject) so4 = study2_opened->CreateObjectID(soID);
00131   _PTR(StudyBuilder) sb4 = study2_opened->NewBuilder();
00132   _PTR(AttributeName) na4 = sb4->FindOrCreateAttribute(so4, "AttributeName");
00133   CPPUNIT_ASSERT(na4 && na4->Value() == "Saved study"); //Compare the value of restored attribute with string that has to be saved.
00134  
00135   //Check method SaveAsASCII
00136   sm->SaveAsASCII("srn_UnitTest_SaveASCII.hdf", study2_opened, false);
00137   url = study2_opened->URL();
00138   sm->Close(study2_opened);
00139 
00140   _PTR(Study) study3_opened = sm->Open("srn_UnitTest_SaveASCII.hdf");  //Contains Test component
00141   system("rm -f srn_UnitTest_SaveASCII.hdf");
00142   CPPUNIT_ASSERT(study3_opened);
00143   CPPUNIT_ASSERT(url == "srn_UnitTest_SaveASCII.hdf");
00144 
00145   //Check method SaveASCII
00146   _PTR(StudyBuilder) sb5 = study3_opened->NewBuilder();
00147   _PTR(SComponent) sco5 = study3_opened->FindComponent("Test");
00148   CPPUNIT_ASSERT(sco5);
00149   //   Add a new SObject with AttributeName that contains "Saved study" string
00150   _PTR(SObject) so5 = sb5->NewObject(sco5);
00151   soID = so5->GetID();
00152   _PTR(AttributeName) na5 = sb5->FindOrCreateAttribute(so5, "AttributeName");
00153   CPPUNIT_ASSERT(na5);
00154   na5->SetValue("Saved study ASCII");
00155   //   Save and close the study
00156   sm->Save(study3_opened, false);
00157   sm->Close(study3_opened);
00158 
00159   //  Open saved study and find the created SObject with AttributeName, then compare the stored string
00160   _PTR(Study) study4_opened = sm->Open("srn_UnitTest_SaveASCII.hdf");
00161   system("rm -f srn_UnitTest_SaveASCII.hdf");
00162   CPPUNIT_ASSERT(study4_opened);
00163   _PTR(SObject) so6 = study4_opened->CreateObjectID(soID);
00164   _PTR(StudyBuilder) sb6 = study4_opened->NewBuilder();
00165   _PTR(AttributeName) na6 = sb6->FindOrCreateAttribute(so6, "AttributeName");
00166   CPPUNIT_ASSERT(na6 && na6->Value() == "Saved study ASCII"); //Compare the value of restored attribute with string that has to be saved.
00167 }
00168 
00169 
00170