Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/kernel.git] / src / SALOMEDSImpl / Test / SALOMEDSImplTest.cxx
1 // Copyright (C) 2006  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include "SALOMEDSImplTest.hxx"
22
23 #include <iostream>
24 #include <fstream>
25 #include <string>
26 #include <vector>
27 #include <cstdlib>
28 #include "utilities.h"
29
30 #include "SALOMEDSImpl_AttributeParameter.hxx"
31 #include "SALOMEDSImpl_StudyManager.hxx"
32 #include "SALOMEDSImpl_Study.hxx"
33 #include "SALOMEDSImpl_StudyBuilder.hxx"
34 #include "SALOMEDSImpl_GenericAttribute.hxx"
35
36 using namespace std;
37
38 // ============================================================================
39 /*!
40  * Set up the environment
41  */
42 // ============================================================================
43
44 void SALOMEDSImplTest::setUp()
45 {
46 }
47
48 // ============================================================================
49 /*!
50  *  - delete trace classes
51  */
52 // ============================================================================
53
54 void 
55 SALOMEDSImplTest::tearDown()
56 {
57 }
58
59 // ============================================================================
60 /*!
61  * Check setting int value
62  */
63 // ============================================================================
64 void SALOMEDSImplTest::testAttributeParameter()
65 {
66   SALOMEDSImpl_StudyManager* sm = new SALOMEDSImpl_StudyManager();
67   SALOMEDSImpl_Study* study = sm->NewStudy("Test");
68   SALOMEDSImpl_AttributeParameter* _ap = study->GetCommonParameters("TestComp", 0);
69
70   CPPUNIT_ASSERT(_ap);
71
72   _ap->SetInt("IntValue", 1);
73   CPPUNIT_ASSERT(_ap->IsSet("IntValue", PT_INTEGER));
74   CPPUNIT_ASSERT(_ap->GetInt("IntValue") == 1);
75
76   _ap->SetReal("RealValue", 1.2);
77   CPPUNIT_ASSERT(_ap->IsSet("RealValue", PT_REAL));
78   CPPUNIT_ASSERT(_ap->GetReal("RealValue") == 1.2);
79
80   _ap->SetString("StringValue", "hello");
81   CPPUNIT_ASSERT(_ap->IsSet("StringValue", PT_STRING));
82   CPPUNIT_ASSERT(_ap->GetString("StringValue") == "hello");
83
84   _ap->SetBool("BoolValue", 0);
85   CPPUNIT_ASSERT(_ap->IsSet("BoolValue", PT_BOOLEAN));
86   CPPUNIT_ASSERT(!_ap->GetBool("BoolValue"));
87
88   _ap->SetBool("BoolValue", 0);
89   CPPUNIT_ASSERT(_ap->IsSet("BoolValue", PT_BOOLEAN));
90   CPPUNIT_ASSERT(!_ap->GetBool("BoolValue"));
91
92   vector<int> intArray;
93   intArray.push_back(0);
94   intArray.push_back(1);
95
96   _ap->SetIntArray("IntArray", intArray);
97   CPPUNIT_ASSERT(_ap->IsSet("IntArray", PT_INTARRAY));
98   CPPUNIT_ASSERT(_ap->GetIntArray("IntArray")[0] == 0);
99   CPPUNIT_ASSERT(_ap->GetIntArray("IntArray")[1] == 1); 
100
101   vector<double> realArray;
102   realArray.push_back(0.0);
103   realArray.push_back(1.1);
104   
105   _ap->SetRealArray("RealArray", realArray);
106   CPPUNIT_ASSERT(_ap->IsSet("RealArray", PT_REALARRAY));
107   CPPUNIT_ASSERT(_ap->GetRealArray("RealArray")[0] == 0.0);
108   CPPUNIT_ASSERT(_ap->GetRealArray("RealArray")[1] == 1.1); 
109
110   vector<string> strArray;
111   strArray.push_back("hello");
112   strArray.push_back("world");
113   
114   _ap->SetStrArray("StrArray", strArray);
115   CPPUNIT_ASSERT(_ap->IsSet("StrArray", PT_STRARRAY));
116   CPPUNIT_ASSERT(_ap->GetStrArray("StrArray")[0] == "hello");
117   CPPUNIT_ASSERT(_ap->GetStrArray("StrArray")[1] == "world"); 
118
119 }
120
121
122