Back to index

salome-kernel  6.5.0
SALOMEDSTest_UseCase.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 
00028 #define SALOMEDS_ALL_TESTS
00029 
00030 void SALOMEDSTest::testUseCase()
00031 {
00032   //Create or find the Study manager
00033   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
00034   CPPUNIT_ASSERT(sm);
00035 
00036   //Create a new study
00037   _PTR(Study) study = sm->NewStudy("TestSObject");
00038   CPPUNIT_ASSERT(study);
00039 
00040   //Create Study Builder
00041   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
00042   CPPUNIT_ASSERT(studyBuilder);
00043 
00044   //Create a new UseCaseBuilder
00045   _PTR(UseCaseBuilder) builder = study->GetUseCaseBuilder();
00046   CPPUNIT_ASSERT(builder);
00047 
00048   //Check method AddUseCase
00049   _PTR(SObject) root1 = builder->AddUseCase("UseCase_1");
00050   _PTR(SObject) root2 = builder->AddUseCase("UseCase_2");
00051   CPPUNIT_ASSERT(root1 && root2);
00052 
00053   //Check method SetCurrentObject
00054   builder->SetCurrentObject(root1);
00055 
00056   //Check method GetCurrentObject
00057   CPPUNIT_ASSERT(builder->GetCurrentObject() && builder->GetCurrentObject()->GetID() == root1->GetID());
00058 
00059   //Check method SetRootCurrent
00060   CPPUNIT_ASSERT(builder->SetRootCurrent());
00061   CPPUNIT_ASSERT(builder->GetCurrentObject()->GetID() == "0:2"); //Root in UseCases is always placed at label 0:2
00062 
00063   //Check method IsUseCase
00064   CPPUNIT_ASSERT(builder->IsUseCase(root1) && builder->IsUseCase(root2));
00065 
00066   //Check method SetName
00067   builder->SetName("A root use case");
00068 
00069   //Check method GetName
00070   CPPUNIT_ASSERT(builder->GetName() == "A root use case");
00071 
00072 #ifdef SALOMEDS_ALL_TESTS
00073   //Check method GetUseCaseIterator
00074   builder->SetRootCurrent();
00075   _PTR(SObject) nullObject;
00076   _PTR(UseCaseIterator) root_it = builder->GetUseCaseIterator(nullObject); //The iterator on all UseCases
00077   root_it->Init(false); //Only the first level
00078   CPPUNIT_ASSERT(root_it->More());
00079   CPPUNIT_ASSERT(root_it->Value()->GetID() == root1->GetID());
00080   root_it->Next();
00081   CPPUNIT_ASSERT(root_it->More());
00082   CPPUNIT_ASSERT(root_it->Value()->GetID() == root2->GetID());
00083   root_it->Next();
00084   CPPUNIT_ASSERT(!root_it->More());
00085 #else
00086   cout << endl << "THE TEST IS NOT COMPLETE !!!" << endl;
00087 #endif
00088 
00089   builder->SetCurrentObject(root1);
00090   _PTR(UseCaseIterator) it = builder->GetUseCaseIterator(root1); //The iterator on the given UseCase
00091 
00092   //Check method Append
00093   _PTR(SObject) so1 = study->CreateObjectID("0:1:1");
00094   _PTR(SObject) so2 = study->CreateObjectID("0:1:2");
00095   CPPUNIT_ASSERT(builder->Append(so1));
00096 
00097   //Check methods Init, More, Next and Value of UseCaseIterator
00098   it->Init(false);
00099   CPPUNIT_ASSERT(it->More());
00100   CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
00101   it->Next();
00102   CPPUNIT_ASSERT(!it->More());
00103 
00104   //Check method AppendTo
00105   CPPUNIT_ASSERT(builder->AppendTo(so1, so2));
00106 
00107   //Check method HasChildren
00108   CPPUNIT_ASSERT(builder->HasChildren(so1));
00109   CPPUNIT_ASSERT(!builder->HasChildren(so2));
00110 
00111   //Check method Init of UseCaseIterator
00112   it->Init(false); //Only the first level
00113   CPPUNIT_ASSERT(it->More());
00114   CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
00115   it->Next();
00116   CPPUNIT_ASSERT(!it->More());
00117 
00118   it->Init(true); //All levels
00119   CPPUNIT_ASSERT(it->More());
00120   CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
00121   it->Next();
00122   CPPUNIT_ASSERT(it->More());
00123   CPPUNIT_ASSERT(it->Value()->GetID() == so2->GetID());
00124   it->Next();
00125   CPPUNIT_ASSERT(!it->More());
00126 
00127   //Check method Remove
00128   CPPUNIT_ASSERT(builder->Remove(so2));
00129   it->Init(true);
00130   CPPUNIT_ASSERT(it->More());
00131   CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
00132   it->Next();
00133   CPPUNIT_ASSERT(!it->More());
00134 
00135   CPPUNIT_ASSERT(builder->Append(so2));
00136 
00137   //Check method InsertBefore
00138   CPPUNIT_ASSERT(builder->InsertBefore(so2, so1));
00139 
00140   it->Init(false);
00141   CPPUNIT_ASSERT(it->More());
00142   CPPUNIT_ASSERT(it->Value()->GetID() == so2->GetID());
00143   it->Next();
00144   CPPUNIT_ASSERT(it->More());
00145   CPPUNIT_ASSERT(it->Value()->GetID() == so1->GetID());
00146 
00147   sm->Close(study);
00148 }
00149 #undef SALOMEDS_ALL_TESTS
00150 
00151