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_AttributeTableOfReal
23 * Use code of SALOMEDS_AttributeTableOfReal.cxx
25 void SALOMEDSTest::testAttributeTableOfReal()
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 AttributeTableOfReal
48 _PTR(AttributeTableOfReal) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfReal");
50 //Check the attribute creation
51 CPPUNIT_ASSERT(_attr);
53 //Check method SetTitle
54 _attr->SetTitle("Table_1");
56 //Check method GetTitle
57 CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
59 //Check method SetNbColumns
60 _attr->SetNbColumns(2);
62 //Check method GetNbColumns
63 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
65 //Check method HasValue
66 CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
68 bool isCaught = false;
70 _attr->GetValue(1, 1);
75 CPPUNIT_ASSERT(isCaught);
77 //Check method PutValue
78 _attr->PutValue(23.23, 1,1);
80 CPPUNIT_ASSERT(_attr->HasValue(1, 1));
82 //Check method GetValue
83 CPPUNIT_ASSERT(_attr->GetValue(1, 1) == 23.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.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");
108 vector<string> colTitles;
109 colTitles.push_back("title1");
110 colTitles.push_back("title2");
112 //Check method SetColumnTitles
113 _attr->SetColumnTitles(colTitles);
115 //Check method SetColumnTitle
116 _attr->SetColumnTitle(1, "new_title");
118 //Check method GetColumnTitles
119 vector<string> ct = _attr->GetColumnTitles();
121 CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
123 vector<string> rowUnits;
124 rowUnits.push_back("unit1");
125 rowUnits.push_back("unit2");
127 //Check method SetRowUnits
128 _attr->SetRowUnits(rowUnits);
130 //Check method SetRowUnit
131 _attr->SetRowUnit(1, "new_unit");
133 //Check method GetRowUnits
134 vector<string> ru = _attr->GetRowUnits();
136 CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
138 //Check method GetNbColumns
139 CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
141 //Check method AddRow
143 data.push_back(11.11);
144 data.push_back(22.22);
148 CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
150 //Check method GetRow
151 vector<double> data2 = _attr->GetRow(3);
153 CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == 11.11 && data2[1] == 22.22);
155 //Check method SetRow
157 _attr->SetRow(3, data);
159 data2 = _attr->GetRow(3);
161 CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == 33.33 && data2[1] == 22.22);
163 //Check method AddColumn
166 data.push_back(-33.33);
168 _attr->AddColumn(data);
170 CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
172 //Check method GetColumn
173 data2 = _attr->GetColumn(3);
175 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == -11.11 && data2[1] == -22.22 && data2[2] == -33.33);
177 //Check method SetColumn
179 _attr->SetColumn(3, data);
181 data2 = _attr->GetColumn(3);
183 CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == 11.11 && data2[1] == -22.22 && data2[2] == -33.33);