Back to index

salome-kernel  6.5.0
SALOMEDSTest_AttributeTreeNode.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 
00027 #define SALOMEDS_ALL_TESTS
00028 void SALOMEDSTest::testAttributeTreeNode()
00029 {
00030   //Create or find the Study manager
00031   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
00032 
00033   CPPUNIT_ASSERT(sm);
00034 
00035   //Create a new study
00036   _PTR(Study) study = sm->NewStudy("Test");
00037 
00038   CPPUNIT_ASSERT(study);
00039 
00040   //Create Study Builder
00041   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
00042 
00043   CPPUNIT_ASSERT(studyBuilder);
00044 
00045   //Create a SObject with entry 0:1:1
00046   _PTR(SObject) so = study->CreateObjectID("0:1:1");
00047 
00048   CPPUNIT_ASSERT(so);
00049 
00050   //Create an attribute AttributeTreeNode
00051   _PTR(AttributeTreeNode) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNode");
00052 
00053   //Check the attribute creation
00054   CPPUNIT_ASSERT(_attr);
00055 
00056   std::string TreeNodeID = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
00057 
00058   _PTR(SObject) so1 = study->CreateObjectID("0:1:2");
00059                                                                
00060   _PTR(AttributeTreeNode) _attr1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeTreeNode");
00061 
00062   //Check the attribute creation
00063   CPPUNIT_ASSERT(_attr1);
00064 
00065   //Check method Label
00066   CPPUNIT_ASSERT(_attr1->Label() == "0:1:2");
00067 
00068   _PTR(SObject) so2 = study->CreateObjectID("0:1:3");
00069 
00070   _PTR(AttributeTreeNode) _attr2 = studyBuilder->FindOrCreateAttribute(so2, "AttributeTreeNode");
00071 
00072   //Check the attribute creation
00073   CPPUNIT_ASSERT(_attr2);
00074 
00075   //Check method SetFather 
00076   _attr1->SetFather(_attr);
00077 
00078   //Check method HasFather
00079   CPPUNIT_ASSERT(_attr1->HasFather());
00080 
00081 #ifdef SALOMEDS_ALL_TESTS
00082   //Check method GetFather
00083   CPPUNIT_ASSERT(_attr1->GetFather()->Label() == _attr->Label());
00084 
00085   //Check method Append
00086   _attr->Append(_attr1);
00087 
00088   //Check possibility to Append to itself
00089   bool isRaised = false;
00090   try {
00091     _attr->Append(_attr);
00092   }catch(...) {
00093     isRaised = true;
00094   }
00095   CPPUNIT_ASSERT(isRaised);
00096 
00097   _attr->Append(_attr2);
00098   
00099   //Check method HasNext
00100   CPPUNIT_ASSERT(_attr1->HasNext());
00101 
00102   //Check method GetNext
00103   CPPUNIT_ASSERT(_attr1->GetNext()->Label() == _attr2->Label());
00104 
00105   //Check method HasPrevious
00106   CPPUNIT_ASSERT(_attr2->HasPrevious());
00107 
00108   //Check method GetPrevious
00109   CPPUNIT_ASSERT(_attr2->GetPrevious()->Label() == _attr1->Label());
00110 
00111   //Check method Depth
00112   CPPUNIT_ASSERT(_attr->Depth() == 1 && _attr1->Depth() == 2);
00113 
00114   //Check method IsRoot
00115   CPPUNIT_ASSERT(_attr->IsRoot());
00116 
00117   //Check method IsFather
00118   CPPUNIT_ASSERT(_attr->IsFather(_attr1));
00119 
00120   //Check method IsDescendant
00121   CPPUNIT_ASSERT(_attr2->IsDescendant(_attr));
00122 
00123   //Check method GetFirst
00124   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
00125 
00126   _attr2->Remove();
00127 
00128   //Check method Prepend
00129   _attr->Prepend(_attr2);
00130 
00131   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
00132 
00133   //Check possibility to Prepend to itself
00134   isRaised = false;
00135   try {
00136     _attr->Prepend(_attr);
00137   }catch(...) {
00138     isRaised = true;
00139   }
00140   CPPUNIT_ASSERT(isRaised);
00141 
00142   _attr1->Remove();
00143 
00144   //Check method InsertBefore
00145   _attr2->InsertBefore(_attr1);
00146 
00147   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
00148 
00149   //Check possibility to InsertBefore to itself
00150   isRaised = false;
00151   try {
00152     _attr->InsertBefore(_attr);
00153   }catch(...) {
00154     isRaised = true;
00155   }
00156   CPPUNIT_ASSERT(isRaised);
00157 
00158   _attr1->Remove();
00159 
00160   //Check method InsertAfter
00161   _attr2->InsertAfter(_attr1);
00162 
00163   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr2->Label());
00164 
00165   //Check possibility to InsertAfter to itself
00166   isRaised = false;
00167   try {
00168     _attr->InsertAfter(_attr);
00169   }catch(...) {
00170     isRaised = true;
00171   }
00172   CPPUNIT_ASSERT(isRaised);
00173 
00174   //Check method Remove
00175   _attr2->Remove();
00176 
00177   CPPUNIT_ASSERT(_attr->GetFirst()->Label() == _attr1->Label());
00178 
00179   //Check method SetTreeID and GetTreeID
00180   _attr2->SetTreeID(TreeNodeID);
00181 
00182   CPPUNIT_ASSERT(_attr2->GetTreeID() == TreeNodeID); 
00183 #else
00184   std::cout << std::endl << "THE TEST IS NOT COMPLETE !!!" << std::endl;
00185 #endif
00186 
00187 
00188   //Try to create the attribute with given TreeID
00189   std::string value = "0e1c36e6-1111-4d90-ab3b-18a14310e648";
00190   _PTR(AttributeTreeNode) _attr_guid = studyBuilder->FindOrCreateAttribute(so, "AttributeTreeNodeGUID"+value);
00191   CPPUNIT_ASSERT(_attr_guid && _attr_guid->GetTreeID() == value);
00192   
00193   sm->Close(study);
00194 }
00195 #undef SALOMEDS_ALL_TESTS
00196 
00197