Back to index

salome-kernel  6.5.0
SALOMEDSTest_AttributeTableOfString.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::testAttributeTableOfString()
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 AttributeTableOfString
00050   _PTR(AttributeTableOfString) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfString");
00051 
00052   //Check the attribute creation
00053   CPPUNIT_ASSERT(_attr);
00054   //Check method SetTitle
00055   _attr->SetTitle("Table_1");
00056 
00057   //Check method GetTitle
00058   CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
00059 
00060   //Check method SetNbColumns
00061   _attr->SetNbColumns(2);
00062 
00063   //Check method GetNbColumns
00064   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
00065 
00066   //Check method HasValue
00067   CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
00068 
00069   bool isCaught = false;
00070   try {
00071     _attr->GetValue(1, 1);
00072   }
00073   catch(...) {
00074      isCaught = true;
00075   }
00076   CPPUNIT_ASSERT(isCaught);
00077 
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 
00111   std::vector<std::string> colTitles;
00112   colTitles.push_back("title1");
00113   colTitles.push_back("title2");
00114 
00115   //Check method SetColumnTitles
00116   _attr->SetColumnTitles(colTitles);
00117 
00118   //Check method SetColumnTitle
00119   _attr->SetColumnTitle(1, "new_title");
00120 
00121   //Check method GetColumnTitles
00122   std::vector<std::string> ct = _attr->GetColumnTitles();
00123 
00124   CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
00125 
00126   std::vector<std::string> rowUnits;
00127   rowUnits.push_back("unit1");
00128   rowUnits.push_back("unit2");
00129 
00130   //Check method SetRowUnits
00131   _attr->SetRowUnits(rowUnits);
00132 
00133   //Check method SetRowUnit
00134   _attr->SetRowUnit(1, "new_unit");
00135 
00136   //Check method GetRowUnits
00137   std::vector<std::string> ru = _attr->GetRowUnits();
00138 
00139   CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
00140 
00141   //Check method GetNbColumns
00142   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
00143 
00144   //Check method AddRow
00145   std::vector<std::string> data;
00146   data.push_back("11");
00147   data.push_back("22");
00148 
00149   _attr->AddRow(data);
00150 
00151   CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
00152 
00153   //Check method GetRow
00154   std::vector<std::string> data2 = _attr->GetRow(3);
00155 
00156   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "11" && data2[1] == "22");
00157 
00158   //Check method SetRow
00159   data[0] = "33";
00160   _attr->SetRow(3, data);
00161 
00162   data2 = _attr->GetRow(3);
00163 
00164   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "33" && data2[1] == "22");
00165 
00166    //Check method AddColumn
00167   data[0] = "-11";
00168   data[1] = "-22";
00169   data.push_back("-33");
00170 
00171   _attr->AddColumn(data);
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