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