1 // Copyright (C) 2007-2015 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_StudyManager
25 * Use code of SALOMEDS_StudyManager.cxx
27 void SALOMEDSTest::testStudyManager()
29 //Create or find the Study manager
30 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
34 //Check method NewStudy
35 _PTR(Study) study1 = sm->NewStudy("Study1");
36 CPPUNIT_ASSERT(study1);
38 //Check method GetStudyByName
39 _PTR(Study) study3 = sm->GetStudyByName("Study1");
40 CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId());
41 CPPUNIT_ASSERT(study3->Name() == study1->Name());
43 //Check method GetOpenStudies
44 std::vector<std::string> v = sm->GetOpenStudies();
45 CPPUNIT_ASSERT(v.size() == 1);
47 //Check method GetStudyByID for invalid ID
48 CPPUNIT_ASSERT(!sm->GetStudyByID(-1));
50 //Check methods CanPaste, CanCopy, Copy, Paste
51 _PTR(StudyBuilder) sb1 = study1->NewBuilder();
52 _PTR(SComponent) sco1 = sb1->NewComponent("Test");
53 _PTR(SObject) so1 = sb1->NewObject(sco1);
54 _PTR(AttributeName) na1 = sb1->FindOrCreateAttribute(so1, "AttributeName");
56 na1->SetValue("Some name");
58 CPPUNIT_ASSERT(!sm->CanCopy(so1)); //The father component has no IOR
60 CPPUNIT_ASSERT(sm->Copy(so1));
62 CPPUNIT_ASSERT(!sm->CanPaste(so1)); //The father component has no IOR
64 _PTR(SObject) so1_2 = sb1->NewObject(sco1);
65 _PTR(SObject) pasted_so = sm->Paste(so1_2);
66 CPPUNIT_ASSERT(pasted_so);
68 _PTR(AttributeName) na2 = sb1->FindOrCreateAttribute(pasted_so, "AttributeName");
69 CPPUNIT_ASSERT(na2 && na2->Value() == "Some name");
73 sm->SaveAs("srn_UnitTest_Save.hdf", study1, false);
74 std::string url = study1->URL();
78 _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf"); //Contains Test component
79 system("rm -f srn_UnitTest_Save.hdf");
80 url = study1_opened->URL();
81 CPPUNIT_ASSERT(study1_opened);
82 CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf");
85 _PTR(StudyBuilder) sb3 = study1_opened->NewBuilder();
86 _PTR(SComponent) sco3 = study1_opened->FindComponent("Test");
88 // Add a new SObject with AttributeName that contains "Saved study" string
89 _PTR(SObject) so3 = sb3->NewObject(sco3);
90 std::string soID = so3->GetID();
91 _PTR(AttributeName) na3 = sb3->FindOrCreateAttribute(so3, "AttributeName");
94 na3->SetValue("Saved study");
96 // Save and close the study
97 sm->Save(study1_opened, false);
99 sm->Close(study1_opened);
101 // Open saved study and find the created SObject with AttributeName, then compare the stored string
102 _PTR(Study) study2_opened = sm->Open("srn_UnitTest_Save.hdf");
104 system("rm -f srn_UnitTest_Save.hdf");
106 CPPUNIT_ASSERT(study2_opened);
108 _PTR(SObject) so4 = study2_opened->CreateObjectID(soID);
109 _PTR(StudyBuilder) sb4 = study2_opened->NewBuilder();
110 _PTR(AttributeName) na4 = sb4->FindOrCreateAttribute(so4, "AttributeName");
111 CPPUNIT_ASSERT(na4 && na4->Value() == "Saved study"); //Compare the value of restored attribute with string that has to be saved.
113 //Check method SaveAsASCII
114 sm->SaveAsASCII("srn_UnitTest_SaveASCII.hdf", study2_opened, false);
115 url = study2_opened->URL();
116 sm->Close(study2_opened);
118 _PTR(Study) study3_opened = sm->Open("srn_UnitTest_SaveASCII.hdf"); //Contains Test component
119 system("rm -f srn_UnitTest_SaveASCII.hdf");
120 CPPUNIT_ASSERT(study3_opened);
121 CPPUNIT_ASSERT(url == "srn_UnitTest_SaveASCII.hdf");
123 //Check method SaveASCII
124 _PTR(StudyBuilder) sb5 = study3_opened->NewBuilder();
125 _PTR(SComponent) sco5 = study3_opened->FindComponent("Test");
126 CPPUNIT_ASSERT(sco5);
127 // Add a new SObject with AttributeName that contains "Saved study" string
128 _PTR(SObject) so5 = sb5->NewObject(sco5);
130 _PTR(AttributeName) na5 = sb5->FindOrCreateAttribute(so5, "AttributeName");
132 na5->SetValue("Saved study ASCII");
133 // Save and close the study
134 sm->Save(study3_opened, false);
135 sm->Close(study3_opened);
137 // Open saved study and find the created SObject with AttributeName, then compare the stored string
138 _PTR(Study) study4_opened = sm->Open("srn_UnitTest_SaveASCII.hdf");
139 system("rm -f srn_UnitTest_SaveASCII.hdf");
140 CPPUNIT_ASSERT(study4_opened);
141 _PTR(SObject) so6 = study4_opened->CreateObjectID(soID);
142 _PTR(StudyBuilder) sb6 = study4_opened->NewBuilder();
143 _PTR(AttributeName) na6 = sb6->FindOrCreateAttribute(so6, "AttributeName");
144 CPPUNIT_ASSERT(na6 && na6->Value() == "Saved study ASCII"); //Compare the value of restored attribute with string that has to be saved.