Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeTableOfString.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_AttributeTableOfString
24  * Use code of SALOMEDS_AttributeTableOfString.cxx
25  */
26 void SALOMEDSTest::testAttributeTableOfString()
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 AttributeTableOfString
49   _PTR(AttributeTableOfString) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeTableOfString");
50
51   //Check the attribute creation
52   CPPUNIT_ASSERT(_attr);
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
78   //Check method PutValue
79   _attr->PutValue("23", 1,1);
80
81   CPPUNIT_ASSERT(_attr->HasValue(1, 1));
82
83   //Check method GetValue
84   CPPUNIT_ASSERT(_attr->GetValue(1, 1) == "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", 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
110   vector<string> colTitles;
111   colTitles.push_back("title1");
112   colTitles.push_back("title2");
113
114   //Check method SetColumnTitles
115   _attr->SetColumnTitles(colTitles);
116
117   //Check method SetColumnTitle
118   _attr->SetColumnTitle(1, "new_title");
119
120   //Check method GetColumnTitles
121   vector<string> ct = _attr->GetColumnTitles();
122
123   CPPUNIT_ASSERT(ct.size() == 2 && ct[0] == "new_title" && ct[1] == "title2");
124
125   vector<string> rowUnits;
126   rowUnits.push_back("unit1");
127   rowUnits.push_back("unit2");
128
129   //Check method SetRowUnits
130   _attr->SetRowUnits(rowUnits);
131
132   //Check method SetRowUnit
133   _attr->SetRowUnit(1, "new_unit");
134
135   //Check method GetRowUnits
136   vector<string> ru = _attr->GetRowUnits();
137
138   CPPUNIT_ASSERT(ru.size() == 2 && ru[0] == "new_unit" && ru[1] == "unit2");
139
140   //Check method GetNbColumns
141   CPPUNIT_ASSERT(_attr->GetNbColumns() == 2);
142
143   //Check method AddRow
144   vector<string> data;
145   data.push_back("11");
146   data.push_back("22");
147
148   _attr->AddRow(data);
149
150   CPPUNIT_ASSERT(_attr->GetNbRows() == 3);
151
152   //Check method GetRow
153   vector<string> data2 = _attr->GetRow(3);
154
155   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "11" && data2[1] == "22");
156
157   //Check method SetRow
158   data[0] = "33";
159   _attr->SetRow(3, data);
160
161   data2 = _attr->GetRow(3);
162
163   CPPUNIT_ASSERT(data2.size() == 2 && data2[0] == "33" && data2[1] == "22");
164
165    //Check method AddColumn
166   data[0] = "-11";
167   data[1] = "-22";
168   data.push_back("-33");
169
170   _attr->AddColumn(data);
171
172   CPPUNIT_ASSERT(_attr->GetNbColumns() == 3);
173
174   //Check method GetColumn
175   data2 = _attr->GetColumn(3);
176
177   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "-11" && data2[1] == "-22" && data2[2] == "-33");
178
179   //Check method SetColumn
180   data[0] = "11";
181   _attr->SetColumn(3, data);
182
183   data2 = _attr->GetColumn(3);
184
185   CPPUNIT_ASSERT(data2.size() == 3 && data2[0] == "11" && data2[1] == "-22" && data2[2] == "-33");
186
187   sm->Close(study);
188 }
189
190
191