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