Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/yacs.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeTableOfString.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_AttributeTableOfString
23  * Use code of SALOMEDS_AttributeTableOfString.cxx
24  */
25 void SALOMEDSTest::testAttributeTableOfString()
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 AttributeTableOfString
48   _PTR(AttributeTableOfString) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfString");
49
50   //Check the attribute creation
51   CPPUNIT_ASSERT(_attr);
52   //Check method SetTitle
53   _attr->SetTitle("Table_1");
54
55   //Check method GetTitle
56   CPPUNIT_ASSERT(_attr->GetTitle() == "Table_1");
57
58   //Check method SetNbColumns
59   _attr->SetNbColumns(2);
60
61   //Check method GetNbColumns
62   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
63
64   //Check method HasValue
65   CPPUNIT_ASSERT(!_attr->HasValue(1, 1));
66
67   bool isCaught = false;
68   try {
69     _attr->GetValue(1, 1);
70   }
71   catch(...) {
72      isCaught = true;
73   }
74   CPPUNIT_ASSERT(isCaught);
75
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
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<string> data;
144   data.push_back("11");
145   data.push_back("22");
146
147   _attr->AddRow(data);
148
149   CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
150
151   //Check method GetRow
152   vector<string> data2 = _attr->GetRow(3);
153
154   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "11" && data2[1] == "22");
155
156   //Check method SetRow
157   data[0] = "33";
158   _attr->SetRow(3, data);
159
160   data2 = _attr->GetRow(3);
161
162   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "33" && data2[1] == "22");
163
164    //Check method AddColumn
165   data[0] = "-11";
166   data[1] = "-22";
167   data.push_back("-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" && 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