1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #define PT_REALARRAY 4
32 * Check all methods of SALOMEDS_AttributeParameter
33 * Use code of SALOMEDS_AttributeParameter.cxx
35 void SALOMEDSTest::testAttributeParameter()
37 //Create or find the Study manager
38 _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );
43 _PTR(Study) study = sm->NewStudy("Test");
45 CPPUNIT_ASSERT(study);
47 //Create Study Builder
48 _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
50 CPPUNIT_ASSERT(studyBuilder);
52 //Create a SObject with entry 0:1:1
53 _PTR(SObject) so = study->CreateObjectID("0:1:1");
57 //Create an attribute AttributeParameter
58 _PTR(AttributeParameter) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeParameter");
60 //Check the attribute creation
61 CPPUNIT_ASSERT(_attr);
63 //Try to retreive a value with invalid ID
64 bool isRaised = false;
65 CPPUNIT_ASSERT(!_attr->IsSet("invalid ID", PT_INTEGER));
67 _attr->GetInt("invalid ID");
72 CPPUNIT_ASSERT(isRaised);
74 //Check method SetInt and GetInt
75 _attr->SetInt("IntValue", 1);
76 CPPUNIT_ASSERT(_attr->IsSet("IntValue", PT_INTEGER));
77 CPPUNIT_ASSERT(_attr->GetInt("IntValue") == 1);
79 //Check method SetReal an GetReal
80 _attr->SetReal("RealValue", 1.2);
81 CPPUNIT_ASSERT(_attr->IsSet("RealValue", PT_REAL));
82 CPPUNIT_ASSERT(_attr->GetReal("RealValue") == 1.2);
84 //Check method SetString and GetString
85 _attr->SetString("StringValue", "hello");
86 CPPUNIT_ASSERT(_attr->IsSet("StringValue", PT_STRING));
87 CPPUNIT_ASSERT(_attr->GetString("StringValue") == "hello");
89 //Check method SetBool and GetBool
90 _attr->SetBool("BoolValue", 0);
91 CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN));
92 CPPUNIT_ASSERT(!_attr->GetBool("BoolValue"));
94 _attr->SetBool("BoolValue", 0);
95 CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN));
96 CPPUNIT_ASSERT(!_attr->GetBool("BoolValue"));
98 std::vector<int> intArray;
99 intArray.push_back(0);
100 intArray.push_back(1);
102 //Check method SetIntArray and GetIntArray
103 _attr->SetIntArray("IntArray", intArray);
104 CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY));
105 CPPUNIT_ASSERT(_attr->GetIntArray("IntArray")[0] == 0);
106 CPPUNIT_ASSERT(_attr->GetIntArray("IntArray")[1] == 1);
108 std::vector<double> realArray;
109 realArray.push_back(0.0);
110 realArray.push_back(1.1);
112 //Check method SetRealArray and GetRealArray
113 _attr->SetRealArray("RealArray", realArray);
114 CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY));
115 CPPUNIT_ASSERT(_attr->GetRealArray("RealArray")[0] == 0.0);
116 CPPUNIT_ASSERT(_attr->GetRealArray("RealArray")[1] == 1.1);
118 std::vector<std::string> strArray;
119 strArray.push_back("hello");
120 strArray.push_back("world");
122 //Check method SetStrArray and GetStrArray
123 _attr->SetStrArray("StrArray", strArray);
124 CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY));
125 CPPUNIT_ASSERT(_attr->GetStrArray("StrArray")[0] == "hello");
126 CPPUNIT_ASSERT(_attr->GetStrArray("StrArray")[1] == "world");
129 string saved = _attr->Save();
132 CPPUNIT_ASSERT(_attr->IsSet("IntValue", PT_INTEGER) && _attr->GetInt("IntValue") == 1);
133 CPPUNIT_ASSERT(_attr->IsSet("RealValue", PT_REAL) && _attr->GetReal("IntValue") == 1.2);
134 CPPUNIT_ASSERT(_attr->IsSet("StringValue", PT_STRING) && _attr->GetString("StringValue") == "hello");
135 CPPUNIT_ASSERT(_attr->IsSet("BoolValue", PT_BOOLEAN) && _attr->GetBool("BoolValue") == 0);
136 CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY) && _attr->GetIntArray("IntArray")[0] == 0);
137 CPPUNIT_ASSERT(_attr->IsSet("IntArray", PT_INTARRAY) && _attr->GetIntArray("IntArray")[1] == 1);
138 CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY) && _attr->GetRealArray("RealArray")[0] == 0.0);
139 CPPUNIT_ASSERT(_attr->IsSet("RealArray", PT_REALARRAY) && _attr->GetRealArray("RealArray")[1] == 1.1);
140 CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY) && _attr->GetStrArray("StrArray")[0] == "hello");
141 CPPUNIT_ASSERT(_attr->IsSet("StrArray", PT_STRARRAY) && _attr->GetStrArray("StrArray")[1] == "world");