1 // Copyright (C) 2007-2008 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.
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
23 * Check all methods of SALOMEDS_StudyManager
24 * Use code of SALOMEDS_StudyManager.cxx
26 void SALOMEDSTest::testStudyManager()
28 //Create or find the Study manager
29 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
33 //Check method NewStudy
34 _PTR(Study) study1 = sm->NewStudy("Study1");
35 CPPUNIT_ASSERT(study1);
37 _PTR(Study) study2 = sm->NewStudy("Study2");
38 CPPUNIT_ASSERT(study2);
40 //Check method GetStudyByName
41 _PTR(Study) study3 = sm->GetStudyByName("Study1");
42 CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId());
43 CPPUNIT_ASSERT(study3->Name() == study1->Name());
45 //Check method GetStudyByName with empty name
46 CPPUNIT_ASSERT(!sm->GetStudyByName(""));
48 //Try to create Study with empty name
49 _PTR(Study) study_empty = sm->NewStudy("");
50 CPPUNIT_ASSERT(study_empty);
51 CPPUNIT_ASSERT(sm->GetStudyByName(""));
52 sm->Close(study_empty);
54 //Check method FindStudyByID
55 _PTR(Study) study4 = sm->GetStudyByID(study2->StudyId());
56 CPPUNIT_ASSERT(study4->StudyId() == study2->StudyId());
57 CPPUNIT_ASSERT(study4->Name() == study2->Name());
59 //Check method GetOpenStudies
60 vector<string> v = sm->GetOpenStudies();
61 CPPUNIT_ASSERT(v.size() == 2);
64 int id = study2->StudyId();
66 CPPUNIT_ASSERT(!sm->GetStudyByID(id));
68 //Check method GetStudyByID for invalid ID
69 CPPUNIT_ASSERT(!sm->GetStudyByID(-1));
71 //Check methods CanPaste, CanCopy, Copy, Paste
72 _PTR(StudyBuilder) sb1 = study1->NewBuilder();
73 _PTR(SComponent) sco1 = sb1->NewComponent("Test");
74 _PTR(SObject) so1 = sb1->NewObject(sco1);
75 _PTR(AttributeName) na1 = sb1->FindOrCreateAttribute(so1, "AttributeName");
77 na1->SetValue("Some name");
79 CPPUNIT_ASSERT(!sm->CanCopy(so1)); //The father component has no IOR
81 CPPUNIT_ASSERT(sm->Copy(so1));
83 CPPUNIT_ASSERT(!sm->CanPaste(so1)); //The father component has no IOR
85 _PTR(SObject) so1_2 = sb1->NewObject(sco1);
86 _PTR(SObject) pasted_so = sm->Paste(so1_2);
87 CPPUNIT_ASSERT(pasted_so);
89 _PTR(AttributeName) na2 = sb1->FindOrCreateAttribute(pasted_so, "AttributeName");
90 CPPUNIT_ASSERT(na2 && na2->Value() == "Some name");
94 sm->SaveAs("srn_UnitTest_Save.hdf", study1, false);
95 string url = study1->URL();
99 _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf"); //Contains Test component
100 system("rm -f srn_UnitTest_Save.hdf");
102 CPPUNIT_ASSERT(study1_opened);
103 CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf");
106 _PTR(StudyBuilder) sb3 = study1_opened->NewBuilder();
107 _PTR(SComponent) sco3 = study1_opened->FindComponent("Test");
108 CPPUNIT_ASSERT(sco3);
109 // Add a new SObject with AttributeName that contains "Saved study" string
110 _PTR(SObject) so3 = sb3->NewObject(sco3);
111 string soID = so3->GetID();
112 _PTR(AttributeName) na3 = sb3->FindOrCreateAttribute(so3, "AttributeName");
115 na3->SetValue("Saved study");
117 // Save and close the study
118 sm->Save(study1_opened, false);
120 sm->Close(study1_opened);
122 // Open saved study and find the created SObject with AttributeName, then compare the stored string
123 _PTR(Study) study2_opened = sm->Open("srn_UnitTest_Save.hdf");
125 system("rm -f srn_UnitTest_Save.hdf");
127 CPPUNIT_ASSERT(study2_opened);
129 _PTR(SObject) so4 = study2_opened->CreateObjectID(soID);
130 _PTR(StudyBuilder) sb4 = study2_opened->NewBuilder();
131 _PTR(AttributeName) na4 = sb4->FindOrCreateAttribute(so4, "AttributeName");
132 CPPUNIT_ASSERT(na4 && na4->Value() == "Saved study"); //Compare the value of restored attribute with string that has to be saved.
134 //Check method SaveAsASCII
135 sm->SaveAsASCII("srn_UnitTest_SaveASCII.hdf", study2_opened, false);
136 url = study2_opened->URL();
137 sm->Close(study2_opened);
139 _PTR(Study) study3_opened = sm->Open("srn_UnitTest_SaveASCII.hdf"); //Contains Test component
140 system("rm -f srn_UnitTest_SaveASCII.hdf");
141 CPPUNIT_ASSERT(study3_opened);
142 CPPUNIT_ASSERT(url == "srn_UnitTest_SaveASCII.hdf");
144 //Check method SaveASCII
145 _PTR(StudyBuilder) sb5 = study3_opened->NewBuilder();
146 _PTR(SComponent) sco5 = study3_opened->FindComponent("Test");
147 CPPUNIT_ASSERT(sco5);
148 // Add a new SObject with AttributeName that contains "Saved study" string
149 _PTR(SObject) so5 = sb5->NewObject(sco5);
151 _PTR(AttributeName) na5 = sb5->FindOrCreateAttribute(so5, "AttributeName");
153 na5->SetValue("Saved study ASCII");
154 // Save and close the study
155 sm->Save(study3_opened, false);
156 sm->Close(study3_opened);
158 // Open saved study and find the created SObject with AttributeName, then compare the stored string
159 _PTR(Study) study4_opened = sm->Open("srn_UnitTest_SaveASCII.hdf");
160 system("rm -f srn_UnitTest_SaveASCII.hdf");
161 CPPUNIT_ASSERT(study4_opened);
162 _PTR(SObject) so6 = study4_opened->CreateObjectID(soID);
163 _PTR(StudyBuilder) sb6 = study4_opened->NewBuilder();
164 _PTR(AttributeName) na6 = sb6->FindOrCreateAttribute(so6, "AttributeName");
165 CPPUNIT_ASSERT(na6 && na6->Value() == "Saved study ASCII"); //Compare the value of restored attribute with string that has to be saved.