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