1 // Copyright (C) 2007-2008 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.
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
23 * Check all methods of SALOMEDS_AttributeTableOfInteger
24 * Use code of SALOMEDS_AttributeTableOfInteger.cxx
26 void SALOMEDSTest::testAttributeTableOfInteger()
28 //Create or find the Study manager
29 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
34 _PTR(Study) study = sm->NewStudy("Test");
36 CPPUNIT_ASSERT(study);
38 //Create Study Builder
39 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
41 CPPUNIT_ASSERT(studyBuilder);
43 //Create a SObject with entry 0:1:1
44 _PTR(SObject) so = study->CreateObjectID("0:1:1");
48 //Create an attribute AttributeTableOfInteger
49 _PTR(AttributeTableOfInteger) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfInteger");
51 //Check the attribute creation
52 CPPUNIT_ASSERT(_attr);
54 //Check method SetTitle
55 _attr->SetTitle("Table_1");
57 //Check method GetTitle
58 CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
60 //Check method SetNbColumns
61 _attr->SetNbColumns(2);
63 //Check method GetNbColumns
64 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
66 //Check method HasValue
67 CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
69 bool isCaught = false;
71 _attr->GetValue(1, 1);
76 CPPUNIT_ASSERT(isCaught);
78 //Check method PutValue
79 _attr->PutValue(23, 1,1);
81 CPPUNIT_ASSERT(_attr->HasValue(1, 1));
83 //Check method GetValue
84 CPPUNIT_ASSERT(_attr->GetValue(1, 1) == 23);
86 //Check method GetRowSetIndices
87 vector<int> rs = _attr->GetRowSetIndices(1);
89 CPPUNIT_ASSERT(rs.size() == 1 && rs[0] == 1);
91 _attr->PutValue(32, 2,2);
92 CPPUNIT_ASSERT(_attr->HasValue(2, 2));
94 vector<string> rowTitles;
95 rowTitles.push_back("title1");
96 rowTitles.push_back("title2");
98 //Check method SetRowTitles
99 _attr->SetRowTitles(rowTitles);
101 //Check method SetRowTitle
102 _attr->SetRowTitle(1, "new_title");
104 //Check method GetRowTitles
105 vector<string> rt = _attr->GetRowTitles();
107 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
149 CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
151 //Check method GetRow
152 vector<int> 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
169 _attr->AddColumn(data);
172 CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
174 //Check method GetColumn
175 data2 = _attr->GetColumn(3);
177 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == -11 && data2[1] == -22 && data2[2] == -33);
179 //Check method SetColumn
181 _attr->SetColumn(3, data);
183 data2 = _attr->GetColumn(3);
185 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == 11 && data2[1] == -22 && data2[2] == -33);