1 // Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 * Check all methods of SALOMEDS_AttributeTableOfString
23 * Use code of SALOMEDS_AttributeTableOfString.cxx
25 void SALOMEDSTest::testAttributeTableOfString()
27 //Create or find the Study manager
28 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
33 _PTR(Study) study = sm->NewStudy("Test");
35 CPPUNIT_ASSERT(study);
37 //Create Study Builder
38 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
40 CPPUNIT_ASSERT(studyBuilder);
42 //Create a SObject with entry 0:1:1
43 _PTR(SObject) so = study->CreateObjectID("0:1:1");
47 //Create an attribute AttributeTableOfString
48 _PTR(AttributeTableOfString) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfString");
50 //Check the attribute creation
51 CPPUNIT_ASSERT(_attr);
52 //Check method SetTitle
53 _attr->SetTitle("Table_1");
55 //Check method GetTitle
56 CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
58 //Check method SetNbColumns
59 _attr->SetNbColumns(2);
61 //Check method GetNbColumns
62 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
64 //Check method HasValue
65 CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
67 bool isCaught = false;
69 _attr->GetValue(1, 1);
74 CPPUNIT_ASSERT(isCaught);
77 //Check method PutValue
78 _attr->PutValue("23", 1,1);
80 CPPUNIT_ASSERT(_attr->HasValue(1, 1));
82 //Check method GetValue
83 CPPUNIT_ASSERT(_attr->GetValue(1, 1) == "23");
85 //Check method GetRowSetIndices
86 vector<int> rs = _attr->GetRowSetIndices(1);
88 CPPUNIT_ASSERT(rs.size() == 1 && rs[0] == 1);
90 _attr->PutValue("32", 2,2);
91 CPPUNIT_ASSERT(_attr->HasValue(2, 2));
93 vector<string> rowTitles;
94 rowTitles.push_back("title1");
95 rowTitles.push_back("title2");
97 //Check method SetRowTitles
98 _attr->SetRowTitles(rowTitles);
100 //Check method SetRowTitle
101 _attr->SetRowTitle(1, "new_title");
103 //Check method GetRowTitles
104 vector<string> rt = _attr->GetRowTitles();
106 CPPUNIT_ASSERT(rt.size() == 2 && rt[0] == "new_title" && rt[1] == "title2");
109 vector<string> colTitles;
110 colTitles.push_back("title1");
111 colTitles.push_back("title2");
113 //Check method SetColumnTitles
114 _attr->SetColumnTitles(colTitles);
116 //Check method SetColumnTitle
117 _attr->SetColumnTitle(1, "new_title");
119 //Check method GetColumnTitles
120 vector<string> ct = _attr->GetColumnTitles();
122 CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
124 vector<string> rowUnits;
125 rowUnits.push_back("unit1");
126 rowUnits.push_back("unit2");
128 //Check method SetRowUnits
129 _attr->SetRowUnits(rowUnits);
131 //Check method SetRowUnit
132 _attr->SetRowUnit(1, "new_unit");
134 //Check method GetRowUnits
135 vector<string> ru = _attr->GetRowUnits();
137 CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
139 //Check method GetNbColumns
140 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
142 //Check method AddRow
144 data.push_back("11");
145 data.push_back("22");
149 CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
151 //Check method GetRow
152 vector<string> data2 = _attr->GetRow(3);
154 CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "11" && data2[1] == "22");
156 //Check method SetRow
158 _attr->SetRow(3, data);
160 data2 = _attr->GetRow(3);
162 CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "33" && data2[1] == "22");
164 //Check method AddColumn
167 data.push_back("-33");
169 _attr->AddColumn(data);
171 CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
173 //Check method GetColumn
174 data2 = _attr->GetColumn(3);
176 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "-11" && data2[1] == "-22" && data2[2] == "-33");
178 //Check method SetColumn
180 _attr->SetColumn(3, data);
182 data2 = _attr->GetColumn(3);
184 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "11" && data2[1] == "-22" && data2[2] == "-33");