Salome HOME
Issue 0020194: EDF 977 ALL: Get rid of warnings PACKAGE_VERSION already defined
[modules/kernel.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeParameter.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 #define PT_INTEGER 0
23 #define PT_REAL    1
24 #define PT_BOOLEAN 2
25 #define PT_STRING  3
26 #define PT_REALARRAY 4
27 #define PT_INTARRAY  5
28 #define PT_STRARRAY  6
29
30 /*!
31  * Check all methods of SALOMEDS_AttributeParameter
32  * Use code of SALOMEDS_AttributeParameter.cxx
33  */
34 void SALOMEDSTest::testAttributeParameter()
35 {
36   //Create or find the Study manager
37   _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
38
39   CPPUNIT_ASSERT(sm);
40
41   //Create a new study
42   _PTR(Study) study = sm->NewStudy("Test");
43
44   CPPUNIT_ASSERT(study);
45
46   //Create Study Builder
47   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
48
49   CPPUNIT_ASSERT(studyBuilder);
50
51   //Create a SObject with entry 0:1:1
52   _PTR(SObject) so = study->CreateObjectID("0:1:1");
53
54   CPPUNIT_ASSERT(so);
55
56   //Create an attribute AttributeParameter
57   _PTR(AttributeParameter) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeParameter");
58
59   //Check the attribute creation
60   CPPUNIT_ASSERT(_attr);
61
62   //Try to retreive a value with invalid ID
63   bool isRaised = false;
64   CPPUNIT_ASSERT(!_attr->IsSet("invalid ID", PT_INTEGER));
65   try {
66     _attr->GetInt("invalid ID");
67   }
68   catch(...) {
69     isRaised = true;
70   }
71   CPPUNIT_ASSERT(isRaised);
72
73   //Check method SetInt and GetInt
74   _attr->SetInt("IntValue", 1);
75   CPPUNIT_ASSERT(_attr->IsSet("IntValue", PT_INTEGER));
76   CPPUNIT_ASSERT(_attr->GetInt("IntValue") == 1);
77
78   //Check method SetReal an GetReal
79   _attr->SetReal("RealValue", 1.2);
80   CPPUNIT_ASSERT(_attr->IsSet("RealValue", PT_REAL));
81   CPPUNIT_ASSERT(_attr->GetReal("RealValue") == 1.2);
82
83   //Check method SetString and GetString
84   _attr->SetString("StringValue", "hello");
85   CPPUNIT_ASSERT(_attr->IsSet("StringValue", PT_STRING));
86   CPPUNIT_ASSERT(_attr->GetString("StringValue") == "hello");
87
88   //Check method SetBool and GetBool
89   _attr->SetBool("BoolValue", 0);
90   CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN));
91   CPPUNIT_ASSERT(!_attr->GetBool("BoolValue"));
92
93   _attr->SetBool("BoolValue", 0);
94   CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN));
95   CPPUNIT_ASSERT(!_attr->GetBool("BoolValue"));
96
97   vector<int> intArray;
98   intArray.push_back(0);
99   intArray.push_back(1);
100
101   //Check method SetIntArray and GetIntArray
102   _attr->SetIntArray("IntArray", intArray);
103   CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY));
104   CPPUNIT_ASSERT(_attr->GetIntArray("IntArray")[0] == 0);
105   CPPUNIT_ASSERT(_attr->GetIntArray("IntArray")[1] == 1); 
106
107   vector<double> realArray;
108   realArray.push_back(0.0);
109   realArray.push_back(1.1);
110   
111   //Check method SetRealArray and GetRealArray
112   _attr->SetRealArray("RealArray", realArray);
113   CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY));
114   CPPUNIT_ASSERT(_attr->GetRealArray("RealArray")[0] == 0.0);
115   CPPUNIT_ASSERT(_attr->GetRealArray("RealArray")[1] == 1.1); 
116
117   vector<string> strArray;
118   strArray.push_back("hello");
119   strArray.push_back("world");
120   
121   //Check method SetStrArray and GetStrArray
122   _attr->SetStrArray("StrArray", strArray);
123   CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY));
124   CPPUNIT_ASSERT(_attr->GetStrArray("StrArray")[0] == "hello");
125   CPPUNIT_ASSERT(_attr->GetStrArray("StrArray")[1] == "world"); 
126
127   /*
128   string saved = _attr->Save();
129   _attr->Load(saved);
130
131   CPPUNIT_ASSERT(_attr->IsSet("IntValue", PT_INTEGER) && _attr->GetInt("IntValue") == 1);
132   CPPUNIT_ASSERT(_attr->IsSet("RealValue", PT_REAL) && _attr->GetReal("IntValue") == 1.2);
133   CPPUNIT_ASSERT(_attr->IsSet("StringValue", PT_STRING) && _attr->GetString("StringValue") == "hello");
134   CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN) && _attr->GetBool("BoolValue") == 0);
135   CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY) && _attr->GetIntArray("IntArray")[0] == 0);
136   CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY) && _attr->GetIntArray("IntArray")[1] == 1);
137   CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY) && _attr->GetRealArray("RealArray")[0] == 0.0);
138   CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY) && _attr->GetRealArray("RealArray")[1] == 1.1);
139   CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY) && _attr->GetStrArray("StrArray")[0] == "hello");
140   CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY) && _attr->GetStrArray("StrArray")[1] == "world");
141   */
142
143   sm->Close(study);
144 }
145
146
147