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 _PTR(Study) study2 = sm->NewStudy("Study2");
39 CPPUNIT_ASSERT(study2);
41 //Check method GetStudyByName
42 _PTR(Study) study3 = sm->GetStudyByName("Study1");
43 CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId());
44 CPPUNIT_ASSERT(study3->Name() == study1->Name());
46 //Check method GetStudyByName with empty name
47 CPPUNIT_ASSERT(!sm->GetStudyByName(""));
49 //Try to create Study with empty name
50 _PTR(Study) study_empty = sm->NewStudy("");
51 CPPUNIT_ASSERT(study_empty);
52 CPPUNIT_ASSERT(sm->GetStudyByName(""));
53 sm->Close(study_empty);
55 //Check method FindStudyByID
56 _PTR(Study) study4 = sm->GetStudyByID(study2->StudyId());
57 CPPUNIT_ASSERT(study4->StudyId() == study2->StudyId());
58 CPPUNIT_ASSERT(study4->Name() == study2->Name());
60 //Check method GetOpenStudies
61 std::vector<std::string> v = sm->GetOpenStudies();
62 CPPUNIT_ASSERT(v.size() == 2);
65 int id = study2->StudyId();
67 CPPUNIT_ASSERT(!sm->GetStudyByID(id));
69 //Check method GetStudyByID for invalid ID
70 CPPUNIT_ASSERT(!sm->GetStudyByID(-1));
72 //Check methods CanPaste, CanCopy, Copy, Paste
73 _PTR(StudyBuilder) sb1 = study1->NewBuilder();
74 _PTR(SComponent) sco1 = sb1->NewComponent("Test");
75 _PTR(SObject) so1 = sb1->NewObject(sco1);
76 _PTR(AttributeName) na1 = sb1->FindOrCreateAttribute(so1, "AttributeName");
78 na1->SetValue("Some name");
80 CPPUNIT_ASSERT(!sm->CanCopy(so1)); //The father component has no IOR
82 CPPUNIT_ASSERT(sm->Copy(so1));
84 CPPUNIT_ASSERT(!sm->CanPaste(so1)); //The father component has no IOR
86 _PTR(SObject) so1_2 = sb1->NewObject(sco1);
87 _PTR(SObject) pasted_so = sm->Paste(so1_2);
88 CPPUNIT_ASSERT(pasted_so);
90 _PTR(AttributeName) na2 = sb1->FindOrCreateAttribute(pasted_so, "AttributeName");
91 CPPUNIT_ASSERT(na2 && na2->Value() == "Some name");
95 sm->SaveAs("srn_UnitTest_Save.hdf", study1, false);
96 std::string url = study1->URL();
100 _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf"); //Contains Test component
101 system("rm -f srn_UnitTest_Save.hdf");
102 url = study1_opened->URL();
103 CPPUNIT_ASSERT(study1_opened);
104 CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf");
107 _PTR(StudyBuilder) sb3 = study1_opened->NewBuilder();
108 _PTR(SComponent) sco3 = study1_opened->FindComponent("Test");
109 CPPUNIT_ASSERT(sco3);
110 // Add a new SObject with AttributeName that contains "Saved study" string
111 _PTR(SObject) so3 = sb3->NewObject(sco3);
112 std::string soID = so3->GetID();
113 _PTR(AttributeName) na3 = sb3->FindOrCreateAttribute(so3, "AttributeName");
116 na3->SetValue("Saved study");
118 // Save and close the study
119 sm->Save(study1_opened, false);
121 sm->Close(study1_opened);
123 // Open saved study and find the created SObject with AttributeName, then compare the stored string
124 _PTR(Study) study2_opened = sm->Open("srn_UnitTest_Save.hdf");
126 system("rm -f srn_UnitTest_Save.hdf");
128 CPPUNIT_ASSERT(study2_opened);
130 _PTR(SObject) so4 = study2_opened->CreateObjectID(soID);
131 _PTR(StudyBuilder) sb4 = study2_opened->NewBuilder();
132 _PTR(AttributeName) na4 = sb4->FindOrCreateAttribute(so4, "AttributeName");
133 CPPUNIT_ASSERT(na4 && na4->Value() == "Saved study"); //Compare the value of restored attribute with string that has to be saved.
135 //Check method SaveAsASCII
136 sm->SaveAsASCII("srn_UnitTest_SaveASCII.hdf", study2_opened, false);
137 url = study2_opened->URL();
138 sm->Close(study2_opened);
140 _PTR(Study) study3_opened = sm->Open("srn_UnitTest_SaveASCII.hdf"); //Contains Test component
141 system("rm -f srn_UnitTest_SaveASCII.hdf");
142 CPPUNIT_ASSERT(study3_opened);
143 CPPUNIT_ASSERT(url == "srn_UnitTest_SaveASCII.hdf");
145 //Check method SaveASCII
146 _PTR(StudyBuilder) sb5 = study3_opened->NewBuilder();
147 _PTR(SComponent) sco5 = study3_opened->FindComponent("Test");
148 CPPUNIT_ASSERT(sco5);
149 // Add a new SObject with AttributeName that contains "Saved study" string
150 _PTR(SObject) so5 = sb5->NewObject(sco5);
152 _PTR(AttributeName) na5 = sb5->FindOrCreateAttribute(so5, "AttributeName");
154 na5->SetValue("Saved study ASCII");
155 // Save and close the study
156 sm->Save(study3_opened, false);
157 sm->Close(study3_opened);
159 // Open saved study and find the created SObject with AttributeName, then compare the stored string
160 _PTR(Study) study4_opened = sm->Open("srn_UnitTest_SaveASCII.hdf");
161 system("rm -f srn_UnitTest_SaveASCII.hdf");
162 CPPUNIT_ASSERT(study4_opened);
163 _PTR(SObject) so6 = study4_opened->CreateObjectID(soID);
164 _PTR(StudyBuilder) sb6 = study4_opened->NewBuilder();
165 _PTR(AttributeName) na6 = sb6->FindOrCreateAttribute(so6, "AttributeName");
166 CPPUNIT_ASSERT(na6 && na6->Value() == "Saved study ASCII"); //Compare the value of restored attribute with string that has to be saved.