Salome HOME
Merge tag 'V8_5_0' into omu/Launcher9
[modules/kernel.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeTableOfString.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_AttributeTableOfString
25  * Use code of SALOMEDS_AttributeTableOfString.cxx
26  */
27 void SALOMEDSTest::testAttributeTableOfString()
28 {
29   //Create or find the Study manager
30   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
31
32   CPPUNIT_ASSERT(sm);
33
34   //Create a new study
35   _PTR(Study) study = sm->NewStudy("Test");
36
37   CPPUNIT_ASSERT(study);
38
39   //Create Study Builder
40   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
41
42   CPPUNIT_ASSERT(studyBuilder);
43
44   //Create a SObject with entry 0:1:1
45   _PTR(SObject) so = study->CreateObjectID("0:1:1");
46
47   CPPUNIT_ASSERT(so);
48
49   //Create an attribute AttributeTableOfString
50   _PTR(AttributeTableOfString) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfString");
51
52   //Check the attribute creation
53   CPPUNIT_ASSERT(_attr);
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
79   //Check method PutValue
80   _attr->PutValue("23", 1,1);
81
82   CPPUNIT_ASSERT(_attr->HasValue(1, 1));
83
84   //Check method GetValue
85   CPPUNIT_ASSERT(_attr->GetValue(1, 1) == "23");
86
87   //Check method GetRowSetIndices
88   std::vector<int> rs = _attr->GetRowSetIndices(1);
89
90   CPPUNIT_ASSERT(rs.size() == 1 && rs[0] == 1);
91
92   _attr->PutValue("32", 2,2);
93   CPPUNIT_ASSERT(_attr->HasValue(2, 2));
94
95   std::vector<std::string> rowTitles;
96   rowTitles.push_back("title1");
97   rowTitles.push_back("title2");
98
99   //Check method SetRowTitles
100   _attr->SetRowTitles(rowTitles);
101
102   //Check method SetRowTitle
103   _attr->SetRowTitle(1, "new_title");
104
105   //Check method GetRowTitles
106   std::vector<std::string> rt = _attr->GetRowTitles();
107
108   CPPUNIT_ASSERT(rt.size() == 2 && rt[0] == "new_title" && rt[1] == "title2");
109
110
111   std::vector<std::string> colTitles;
112   colTitles.push_back("title1");
113   colTitles.push_back("title2");
114
115   //Check method SetColumnTitles
116   _attr->SetColumnTitles(colTitles);
117
118   //Check method SetColumnTitle
119   _attr->SetColumnTitle(1, "new_title");
120
121   //Check method GetColumnTitles
122   std::vector<std::string> ct = _attr->GetColumnTitles();
123
124   CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
125
126   std::vector<std::string> rowUnits;
127   rowUnits.push_back("unit1");
128   rowUnits.push_back("unit2");
129
130   //Check method SetRowUnits
131   _attr->SetRowUnits(rowUnits);
132
133   //Check method SetRowUnit
134   _attr->SetRowUnit(1, "new_unit");
135
136   //Check method GetRowUnits
137   std::vector<std::string> ru = _attr->GetRowUnits();
138
139   CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
140
141   //Check method GetNbColumns
142   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
143
144   //Check method AddRow
145   std::vector<std::string> data;
146   data.push_back("11");
147   data.push_back("22");
148
149   _attr->AddRow(data);
150
151   CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
152
153   //Check method GetRow
154   std::vector<std::string> data2 = _attr->GetRow(3);
155
156   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "11" && data2[1] == "22");
157
158   //Check method SetRow
159   data[0] = "33";
160   _attr->SetRow(3, data);
161
162   data2 = _attr->GetRow(3);
163
164   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "33" && data2[1] == "22");
165
166    //Check method AddColumn
167   data[0] = "-11";
168   data[1] = "-22";
169   data.push_back("-33");
170
171   _attr->AddColumn(data);
172
173   CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
174
175   //Check method GetColumn
176   data2 = _attr->GetColumn(3);
177
178   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "-11" && data2[1] == "-22" && data2[2] == "-33");
179
180   //Check method SetColumn
181   data[0] = "11";
182   _attr->SetColumn(3, data);
183
184   data2 = _attr->GetColumn(3);
185
186   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "11" && data2[1] == "-22" && data2[2] == "-33");
187
188   sm->Close(study);
189 }
190
191
192