1 // Copyright (C) 2007-2012 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
24 * Check all methods of SALOMEDS_UseCaseBuilder and UseCaseIterator
25 * Use code of SALOMEDS_UseCaseBuilder.cxx and SALOMEDS_UseCaseIterator.cxx
28 #define SALOMEDS_ALL_TESTS
30 void SALOMEDSTest::testUseCase()
32 //Create or find the Study manager
33 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
37 _PTR(Study) study = sm->NewStudy("TestSObject");
38 CPPUNIT_ASSERT(study);
40 //Create Study Builder
41 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
42 CPPUNIT_ASSERT(studyBuilder);
44 //Create a new UseCaseBuilder
45 _PTR(UseCaseBuilder) builder = study->GetUseCaseBuilder();
46 CPPUNIT_ASSERT(builder);
48 //Check method AddUseCase
49 _PTR(SObject) root1 = builder->AddUseCase("UseCase_1");
50 _PTR(SObject) root2 = builder->AddUseCase("UseCase_2");
51 CPPUNIT_ASSERT(root1 && root2);
53 //Check method SetCurrentObject
54 builder->SetCurrentObject(root1);
56 //Check method GetCurrentObject
57 CPPUNIT_ASSERT(builder->GetCurrentObject() && builder->GetCurrentObject()->GetID() == root1->GetID());
59 //Check method SetRootCurrent
60 CPPUNIT_ASSERT(builder->SetRootCurrent());
61 CPPUNIT_ASSERT(builder->GetCurrentObject()->GetID() == "0:2"); //Root in UseCases is always placed at label 0:2
63 //Check method IsUseCase
64 CPPUNIT_ASSERT(builder->IsUseCase(root1) && builder->IsUseCase(root2));
66 //Check method SetName
67 builder->SetName("A root use case");
69 //Check method GetName
70 CPPUNIT_ASSERT(builder->GetName() == "A root use case");
72 #ifdef SALOMEDS_ALL_TESTS
73 //Check method GetUseCaseIterator
74 builder->SetRootCurrent();
75 _PTR(SObject) nullObject;
76 _PTR(UseCaseIterator) root_it = builder->GetUseCaseIterator(nullObject); //The iterator on all UseCases
77 root_it->Init(false); //Only the first level
78 CPPUNIT_ASSERT(root_it->More());
79 CPPUNIT_ASSERT(root_it->Value()->GetID() == root1->GetID());
81 CPPUNIT_ASSERT(root_it->More());
82 CPPUNIT_ASSERT(root_it->Value()->GetID() == root2->GetID());
84 CPPUNIT_ASSERT(!root_it->More());
86 cout << endl << "THE TEST IS NOT COMPLETE !!!" << endl;
89 builder->SetCurrentObject(root1);
90 _PTR(UseCaseIterator) it = builder->GetUseCaseIterator(root1); //The iterator on the given UseCase
93 _PTR(SObject) so1 = study->CreateObjectID("0:1:1");
94 _PTR(SObject) so2 = study->CreateObjectID("0:1:2");
95 CPPUNIT_ASSERT(builder->Append(so1));
97 //Check methods Init, More, Next and Value of UseCaseIterator
99 CPPUNIT_ASSERT(it->More());
100 CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
102 CPPUNIT_ASSERT(!it->More());
104 //Check method AppendTo
105 CPPUNIT_ASSERT(builder->AppendTo(so1, so2));
107 //Check method HasChildren
108 CPPUNIT_ASSERT(builder->HasChildren(so1));
109 CPPUNIT_ASSERT(!builder->HasChildren(so2));
111 //Check method Init of UseCaseIterator
112 it->Init(false); //Only the first level
113 CPPUNIT_ASSERT(it->More());
114 CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
116 CPPUNIT_ASSERT(!it->More());
118 it->Init(true); //All levels
119 CPPUNIT_ASSERT(it->More());
120 CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
122 CPPUNIT_ASSERT(it->More());
123 CPPUNIT_ASSERT(it->Value()->GetID() == so2->GetID());
125 CPPUNIT_ASSERT(!it->More());
127 //Check method Remove
128 CPPUNIT_ASSERT(builder->Remove(so2));
130 CPPUNIT_ASSERT(it->More());
131 CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
133 CPPUNIT_ASSERT(!it->More());
135 CPPUNIT_ASSERT(builder->Append(so2));
137 //Check method InsertBefore
138 CPPUNIT_ASSERT(builder->InsertBefore(so2, so1));
141 CPPUNIT_ASSERT(it->More());
142 CPPUNIT_ASSERT(it->Value()->GetID() == so2->GetID());
144 CPPUNIT_ASSERT(it->More());
145 CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
149 #undef SALOMEDS_ALL_TESTS