Back to index

salome-kernel  6.5.0
SALOMEDSTest_AttributeTableOfInteger.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 void SALOMEDSTest::testAttributeTableOfInteger()
00028 {
00029   //Create or find the Study manager
00030   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
00031 
00032   CPPUNIT_ASSERT(sm);
00033 
00034   //Create a new study
00035   _PTR(Study) study = sm->NewStudy("Test");
00036 
00037   CPPUNIT_ASSERT(study);
00038 
00039   //Create Study Builder
00040   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
00041 
00042   CPPUNIT_ASSERT(studyBuilder);
00043 
00044   //Create a SObject with entry 0:1:1
00045   _PTR(SObject) so = study->CreateObjectID("0:1:1");
00046 
00047   CPPUNIT_ASSERT(so);
00048 
00049   //Create an attribute AttributeTableOfInteger
00050   _PTR(AttributeTableOfInteger) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfInteger");
00051 
00052   //Check the attribute creation
00053   CPPUNIT_ASSERT(_attr);
00054 
00055   //Check method SetTitle
00056   _attr->SetTitle("Table_1");
00057 
00058   //Check method GetTitle
00059   CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
00060 
00061   //Check method SetNbColumns
00062   _attr->SetNbColumns(2);
00063 
00064   //Check method GetNbColumns
00065   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
00066 
00067   //Check method HasValue
00068   CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
00069 
00070   bool isCaught = false;
00071   try {
00072     _attr->GetValue(1, 1);
00073   }
00074   catch(...) {
00075      isCaught = true;
00076   }
00077   CPPUNIT_ASSERT(isCaught);
00078 
00079   //Check method PutValue
00080   _attr->PutValue(23, 1,1);
00081 
00082   CPPUNIT_ASSERT(_attr->HasValue(1, 1));
00083 
00084   //Check method GetValue
00085   CPPUNIT_ASSERT(_attr->GetValue(1, 1) == 23);
00086 
00087   //Check method GetRowSetIndices
00088   std::vector<int> rs = _attr->GetRowSetIndices(1);
00089 
00090   CPPUNIT_ASSERT(rs.size() == 1 && rs[0] == 1);
00091 
00092   _attr->PutValue(32, 2,2);
00093   CPPUNIT_ASSERT(_attr->HasValue(2, 2));
00094 
00095   std::vector<std::string> rowTitles;
00096   rowTitles.push_back("title1");
00097   rowTitles.push_back("title2");
00098 
00099   //Check method SetRowTitles
00100   _attr->SetRowTitles(rowTitles);
00101   
00102   //Check method SetRowTitle
00103   _attr->SetRowTitle(1, "new_title");
00104 
00105   //Check method GetRowTitles
00106   std::vector<std::string> rt = _attr->GetRowTitles();
00107 
00108   CPPUNIT_ASSERT(rt.size() == 2 && rt[0] == "new_title" && rt[1] == "title2");
00109 
00110   std::vector<std::string> colTitles;
00111   colTitles.push_back("title1");
00112   colTitles.push_back("title2");
00113 
00114   //Check method SetColumnTitles
00115   _attr->SetColumnTitles(colTitles);
00116  
00117   //Check method SetColumnTitle
00118   _attr->SetColumnTitle(1, "new_title");
00119 
00120   //Check method GetColumnTitles
00121   std::vector<std::string> ct = _attr->GetColumnTitles();
00122 
00123   CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
00124 
00125   std::vector<std::string> rowUnits;
00126   rowUnits.push_back("unit1");
00127   rowUnits.push_back("unit2");
00128 
00129   //Check method SetRowUnits
00130   _attr->SetRowUnits(rowUnits);
00131 
00132   //Check method SetRowUnit
00133   _attr->SetRowUnit(1, "new_unit");
00134 
00135   //Check method GetRowUnits
00136   std::vector<std::string> ru = _attr->GetRowUnits();
00137 
00138   CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
00139 
00140   //Check method GetNbColumns
00141   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
00142 
00143   //Check method AddRow
00144   std::vector<int> data;
00145   data.push_back(11);
00146   data.push_back(22);
00147 
00148   _attr->AddRow(data);
00149 
00150   CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
00151 
00152   //Check method GetRow
00153   std::vector<int> data2 = _attr->GetRow(3);
00154 
00155   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == 11 && data2[1] == 22);
00156 
00157   //Check method SetRow
00158   data[0] = 33;
00159   _attr->SetRow(3, data);
00160 
00161   data2 = _attr->GetRow(3);
00162 
00163   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == 33 && data2[1] == 22);
00164 
00165    //Check method AddColumn
00166   data[0] = -11;
00167   data[1] = -22;
00168   data.push_back(-33);
00169 
00170   _attr->AddColumn(data);
00171 
00172 
00173   CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
00174 
00175   //Check method GetColumn
00176   data2 = _attr->GetColumn(3);
00177 
00178   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == -11 && data2[1] == -22 && data2[2] == -33);
00179 
00180   //Check method SetColumn
00181   data[0] = 11;
00182   _attr->SetColumn(3, data);
00183 
00184   data2 = _attr->GetColumn(3);
00185 
00186   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == 11 && data2[1] == -22 && data2[2] == -33);
00187 
00188   sm->Close(study);
00189 }
00190 
00191 
00192