Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeTableOfReal.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*!
23  * Check all methods of SALOMEDS_AttributeTableOfReal
24  * Use code of SALOMEDS_AttributeTableOfReal.cxx
25  */
26 void SALOMEDSTest::testAttributeTableOfReal()
27 {
28   //Create or find the Study manager
29   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
30
31   CPPUNIT_ASSERT(sm);
32
33   //Create a new study
34   _PTR(Study) study = sm->NewStudy("Test");
35
36   CPPUNIT_ASSERT(study);
37
38   //Create Study Builder
39   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
40
41   CPPUNIT_ASSERT(studyBuilder);
42
43   //Create a SObject with entry 0:1:1
44   _PTR(SObject) so = study->CreateObjectID("0:1:1");
45
46   CPPUNIT_ASSERT(so);
47
48   //Create an attribute AttributeTableOfReal
49   _PTR(AttributeTableOfReal) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfReal");
50
51   //Check the attribute creation
52   CPPUNIT_ASSERT(_attr);
53
54   //Check method SetTitle
55   _attr->SetTitle("Table_1");
56
57   //Check method GetTitle
58   CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
59
60   //Check method SetNbColumns
61   _attr->SetNbColumns(2);
62
63   //Check method GetNbColumns
64   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
65
66   //Check method HasValue
67   CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
68
69   bool isCaught = false;
70   try {
71     _attr->GetValue(1, 1);
72   }
73   catch(...) {
74      isCaught = true;
75   }
76   CPPUNIT_ASSERT(isCaught);
77
78   //Check method PutValue
79   _attr->PutValue(23.23, 1,1);
80
81   CPPUNIT_ASSERT(_attr->HasValue(1, 1));
82
83   //Check method GetValue
84   CPPUNIT_ASSERT(_attr->GetValue(1, 1) == 23.23);
85
86   //Check method GetRowSetIndices
87   vector<int> rs = _attr->GetRowSetIndices(1);
88
89   CPPUNIT_ASSERT(rs.size() == 1 && rs[0] == 1);
90
91   _attr->PutValue(32.32, 2,2);
92   CPPUNIT_ASSERT(_attr->HasValue(2, 2));
93
94   vector<string> rowTitles;
95   rowTitles.push_back("title1");
96   rowTitles.push_back("title2");
97
98   //Check method SetRowTitles
99   _attr->SetRowTitles(rowTitles);
100
101   //Check method SetRowTitle
102   _attr->SetRowTitle(1, "new_title");
103
104   //Check method GetRowTitles
105   vector<string> rt = _attr->GetRowTitles();
106
107   CPPUNIT_ASSERT(rt.size() == 2 && rt[0] == "new_title" && rt[1] == "title2");
108
109   vector<string> colTitles;
110   colTitles.push_back("title1");
111   colTitles.push_back("title2");
112
113   //Check method SetColumnTitles
114   _attr->SetColumnTitles(colTitles);
115
116   //Check method SetColumnTitle
117   _attr->SetColumnTitle(1, "new_title");
118
119   //Check method GetColumnTitles
120   vector<string> ct = _attr->GetColumnTitles();
121
122   CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
123
124   vector<string> rowUnits;
125   rowUnits.push_back("unit1");
126   rowUnits.push_back("unit2");
127
128   //Check method SetRowUnits
129   _attr->SetRowUnits(rowUnits);
130
131   //Check method SetRowUnit
132   _attr->SetRowUnit(1, "new_unit");
133
134   //Check method GetRowUnits
135   vector<string> ru = _attr->GetRowUnits();
136
137   CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
138
139   //Check method GetNbColumns
140   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
141
142   //Check method AddRow
143   vector<double> data;
144   data.push_back(11.11);
145   data.push_back(22.22);
146
147   _attr->AddRow(data);
148
149   CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
150
151   //Check method GetRow
152   vector<double> data2 = _attr->GetRow(3);
153
154   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == 11.11 && data2[1] == 22.22);
155
156   //Check method SetRow
157   data[0] = 33.33;
158   _attr->SetRow(3, data);
159
160   data2 = _attr->GetRow(3);
161
162   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == 33.33 && data2[1] == 22.22);
163
164    //Check method AddColumn
165   data[0] = -11.11;
166   data[1] = -22.22;
167   data.push_back(-33.33);
168
169   _attr->AddColumn(data);
170
171   CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
172
173   //Check method GetColumn
174   data2 = _attr->GetColumn(3);
175
176   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == -11.11 && data2[1] == -22.22 && data2[2] == -33.33);
177
178   //Check method SetColumn
179   data[0] = 11.11;
180   _attr->SetColumn(3, data);
181
182   data2 = _attr->GetColumn(3);
183
184   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == 11.11 && data2[1] == -22.22 && data2[2] == -33.33);
185
186   sm->Close(study);
187 }
188
189
190