Back to index

salome-kernel  6.5.0
SALOMEDSTest_AttributeParameter.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 
00023 #define PT_INTEGER 0
00024 #define PT_REAL    1
00025 #define PT_BOOLEAN 2
00026 #define PT_STRING  3
00027 #define PT_REALARRAY 4
00028 #define PT_INTARRAY  5
00029 #define PT_STRARRAY  6
00030 
00035 void SALOMEDSTest::testAttributeParameter()
00036 {
00037   //Create or find the Study manager
00038   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
00039 
00040   CPPUNIT_ASSERT(sm);
00041 
00042   //Create a new study
00043   _PTR(Study) study = sm->NewStudy("Test");
00044 
00045   CPPUNIT_ASSERT(study);
00046 
00047   //Create Study Builder
00048   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
00049 
00050   CPPUNIT_ASSERT(studyBuilder);
00051 
00052   //Create a SObject with entry 0:1:1
00053   _PTR(SObject) so = study->CreateObjectID("0:1:1");
00054 
00055   CPPUNIT_ASSERT(so);
00056 
00057   //Create an attribute AttributeParameter
00058   _PTR(AttributeParameter) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeParameter");
00059 
00060   //Check the attribute creation
00061   CPPUNIT_ASSERT(_attr);
00062 
00063   //Try to retreive a value with invalid ID
00064   bool isRaised = false;
00065   CPPUNIT_ASSERT(!_attr->IsSet("invalid ID", PT_INTEGER));
00066   try {
00067     _attr->GetInt("invalid ID");
00068   }
00069   catch(...) {
00070     isRaised = true;
00071   }
00072   CPPUNIT_ASSERT(isRaised);
00073 
00074   //Check method SetInt and GetInt
00075   _attr->SetInt("IntValue", 1);
00076   CPPUNIT_ASSERT(_attr->IsSet("IntValue", PT_INTEGER));
00077   CPPUNIT_ASSERT(_attr->GetInt("IntValue") == 1);
00078 
00079   //Check method SetReal an GetReal
00080   _attr->SetReal("RealValue", 1.2);
00081   CPPUNIT_ASSERT(_attr->IsSet("RealValue", PT_REAL));
00082   CPPUNIT_ASSERT(_attr->GetReal("RealValue") == 1.2);
00083 
00084   //Check method SetString and GetString
00085   _attr->SetString("StringValue", "hello");
00086   CPPUNIT_ASSERT(_attr->IsSet("StringValue", PT_STRING));
00087   CPPUNIT_ASSERT(_attr->GetString("StringValue") == "hello");
00088 
00089   //Check method SetBool and GetBool
00090   _attr->SetBool("BoolValue", 0);
00091   CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN));
00092   CPPUNIT_ASSERT(!_attr->GetBool("BoolValue"));
00093 
00094   _attr->SetBool("BoolValue", 0);
00095   CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN));
00096   CPPUNIT_ASSERT(!_attr->GetBool("BoolValue"));
00097 
00098   std::vector<int> intArray;
00099   intArray.push_back(0);
00100   intArray.push_back(1);
00101 
00102   //Check method SetIntArray and GetIntArray
00103   _attr->SetIntArray("IntArray", intArray);
00104   CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY));
00105   CPPUNIT_ASSERT(_attr->GetIntArray("IntArray")[0] == 0);
00106   CPPUNIT_ASSERT(_attr->GetIntArray("IntArray")[1] == 1); 
00107 
00108   std::vector<double> realArray;
00109   realArray.push_back(0.0);
00110   realArray.push_back(1.1);
00111   
00112   //Check method SetRealArray and GetRealArray
00113   _attr->SetRealArray("RealArray", realArray);
00114   CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY));
00115   CPPUNIT_ASSERT(_attr->GetRealArray("RealArray")[0] == 0.0);
00116   CPPUNIT_ASSERT(_attr->GetRealArray("RealArray")[1] == 1.1); 
00117 
00118   std::vector<std::string> strArray;
00119   strArray.push_back("hello");
00120   strArray.push_back("world");
00121   
00122   //Check method SetStrArray and GetStrArray
00123   _attr->SetStrArray("StrArray", strArray);
00124   CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY));
00125   CPPUNIT_ASSERT(_attr->GetStrArray("StrArray")[0] == "hello");
00126   CPPUNIT_ASSERT(_attr->GetStrArray("StrArray")[1] == "world"); 
00127 
00128   /*
00129   string saved = _attr->Save();
00130   _attr->Load(saved);
00131 
00132   CPPUNIT_ASSERT(_attr->IsSet("IntValue", PT_INTEGER) && _attr->GetInt("IntValue") == 1);
00133   CPPUNIT_ASSERT(_attr->IsSet("RealValue", PT_REAL) && _attr->GetReal("IntValue") == 1.2);
00134   CPPUNIT_ASSERT(_attr->IsSet("StringValue", PT_STRING) && _attr->GetString("StringValue") == "hello");
00135   CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN) && _attr->GetBool("BoolValue") == 0);
00136   CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY) && _attr->GetIntArray("IntArray")[0] == 0);
00137   CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY) && _attr->GetIntArray("IntArray")[1] == 1);
00138   CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY) && _attr->GetRealArray("RealArray")[0] == 0.0);
00139   CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY) && _attr->GetRealArray("RealArray")[1] == 1.1);
00140   CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY) && _attr->GetStrArray("StrArray")[0] == "hello");
00141   CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY) && _attr->GetStrArray("StrArray")[1] == "world");
00142   */
00143 
00144   sm->Close(study);
00145 }
00146 
00147 
00148