1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 * Check all methods of SALOMEDS_AttributeTableOfString
25 * Use code of SALOMEDS_AttributeTableOfString.cxx
27 void SALOMEDSTest::testAttributeTableOfString()
30 _PTR(Study) study(new SALOMEDS_Study(_study));
32 CPPUNIT_ASSERT(study);
34 //Create Study Builder
35 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
37 CPPUNIT_ASSERT(studyBuilder);
39 //Create a SObject with entry 0:1:1
40 _PTR(SObject) so = study->CreateObjectID("0:1:1");
44 //Create an attribute AttributeTableOfString
45 _PTR(AttributeTableOfString) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfString");
47 //Check the attribute creation
48 CPPUNIT_ASSERT(_attr);
49 //Check method SetTitle
50 _attr->SetTitle("Table_1");
52 //Check method GetTitle
53 CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
55 //Check method SetNbColumns
56 _attr->SetNbColumns(2);
58 //Check method GetNbColumns
59 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
61 //Check method HasValue
62 CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
64 bool isCaught = false;
66 _attr->GetValue(1, 1);
71 CPPUNIT_ASSERT(isCaught);
74 //Check method PutValue
75 _attr->PutValue("23", 1,1);
77 CPPUNIT_ASSERT(_attr->HasValue(1, 1));
79 //Check method GetValue
80 CPPUNIT_ASSERT(_attr->GetValue(1, 1) == "23");
82 //Check method GetRowSetIndices
83 std::vector<int> rs = _attr->GetRowSetIndices(1);
85 CPPUNIT_ASSERT(rs.size() == 1 && rs[0] == 1);
87 _attr->PutValue("32", 2,2);
88 CPPUNIT_ASSERT(_attr->HasValue(2, 2));
90 std::vector<std::string> rowTitles;
91 rowTitles.push_back("title1");
92 rowTitles.push_back("title2");
94 //Check method SetRowTitles
95 _attr->SetRowTitles(rowTitles);
97 //Check method SetRowTitle
98 _attr->SetRowTitle(1, "new_title");
100 //Check method GetRowTitles
101 std::vector<std::string> rt = _attr->GetRowTitles();
103 CPPUNIT_ASSERT(rt.size() == 2 && rt[0] == "new_title" && rt[1] == "title2");
106 std::vector<std::string> colTitles;
107 colTitles.push_back("title1");
108 colTitles.push_back("title2");
110 //Check method SetColumnTitles
111 _attr->SetColumnTitles(colTitles);
113 //Check method SetColumnTitle
114 _attr->SetColumnTitle(1, "new_title");
116 //Check method GetColumnTitles
117 std::vector<std::string> ct = _attr->GetColumnTitles();
119 CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
121 std::vector<std::string> rowUnits;
122 rowUnits.push_back("unit1");
123 rowUnits.push_back("unit2");
125 //Check method SetRowUnits
126 _attr->SetRowUnits(rowUnits);
128 //Check method SetRowUnit
129 _attr->SetRowUnit(1, "new_unit");
131 //Check method GetRowUnits
132 std::vector<std::string> ru = _attr->GetRowUnits();
134 CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
136 //Check method GetNbColumns
137 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
139 //Check method AddRow
140 std::vector<std::string> data;
141 data.push_back("11");
142 data.push_back("22");
146 CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
148 //Check method GetRow
149 std::vector<std::string> data2 = _attr->GetRow(3);
151 CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "11" && data2[1] == "22");
153 //Check method SetRow
155 _attr->SetRow(3, data);
157 data2 = _attr->GetRow(3);
159 CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "33" && data2[1] == "22");
161 //Check method AddColumn
164 data.push_back("-33");
166 _attr->AddColumn(data);
168 CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
170 //Check method GetColumn
171 data2 = _attr->GetColumn(3);
173 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "-11" && data2[1] == "-22" && data2[2] == "-33");
175 //Check method SetColumn
177 _attr->SetColumn(3, data);
179 data2 = _attr->GetColumn(3);
181 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "11" && data2[1] == "-22" && data2[2] == "-33");