1 // Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/
21 #include "SALOMEDSTest.hxx"
28 #include "utilities.h"
29 #include "Utils_SALOME_Exception.hxx"
30 #include "Utils_ORB_INIT.hxx"
31 #include "Utils_SINGLETON.hxx"
34 #include "SALOMEDSClient.hxx"
35 #include "SALOMEDSClient_ClientFactory.hxx"
37 #include <TCollection_AsciiString.hxx>
45 #define PT_REALARRAY 4
50 #define TRACEFILE "/tmp/traceUnitTest.log"
52 // ============================================================================
54 * Set up the environment
56 // ============================================================================
58 void SALOMEDSTest::setUp()
60 TCollection_AsciiString kernel(getenv("KERNEL_ROOT_DIR"));
61 TCollection_AsciiString subPath("/share/salome/resources");
62 TCollection_AsciiString csf_var = (kernel+subPath);
63 setenv("CSF_PluginDefaults", csf_var.ToCString(), 0);
64 setenv("CSF_SALOMEDS_ResourcesDefaults", csf_var.ToCString(), 0);
67 char *theFileName = TRACEFILE;
71 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
74 traceFile.open(theFileName, ios::out | ios::app);
75 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
78 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
81 // --- Get or initialize the orb
85 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
86 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
87 _orb = init(_argc , _argv ) ;
91 // --- Create a SALOME_NamingService instance
93 _NS = new SALOME_NamingService;
100 // ============================================================================
102 * - delete trace classes
104 // ============================================================================
107 SALOMEDSTest::tearDown()
109 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
111 bp1->deleteInstance(bp1);
116 // ============================================================================
118 * Check AttributeParameter
120 // ============================================================================
121 void SALOMEDSTest::testAttributeParameter()
123 CORBA::Object_var obj = _orb->resolve_initial_references( "RootPOA" );
124 PortableServer::POA_var poa = PortableServer::POA::_narrow( obj );
126 PortableServer::POAManager_var pman = poa->the_POAManager();
129 _PTR(StudyManager) sm = ClientFactory::createStudyManager(_orb, poa);
133 _PTR(Study) study = sm->NewStudy("Test");
135 CPPUNIT_ASSERT(study);
137 _PTR(AttributeParameter) _ap = study->GetCommonParameters("TestComp", 0);
141 _ap->SetInt("IntValue", 1);
142 CPPUNIT_ASSERT(_ap->IsSet("IntValue", PT_INTEGER));
143 CPPUNIT_ASSERT(_ap->GetInt("IntValue") == 1);
145 _ap->SetReal("RealValue", 1.2);
146 CPPUNIT_ASSERT(_ap->IsSet("RealValue", PT_REAL));
147 CPPUNIT_ASSERT(_ap->GetReal("RealValue") == 1.2);
149 _ap->SetString("StringValue", "hello");
150 CPPUNIT_ASSERT(_ap->IsSet("StringValue", PT_STRING));
151 CPPUNIT_ASSERT(_ap->GetString("StringValue") == "hello");
153 _ap->SetBool("BoolValue", 0);
154 CPPUNIT_ASSERT(_ap->IsSet("BoolValue", PT_BOOLEAN));
155 CPPUNIT_ASSERT(!_ap->GetBool("BoolValue"));
157 _ap->SetBool("BoolValue", 0);
158 CPPUNIT_ASSERT(_ap->IsSet("BoolValue", PT_BOOLEAN));
159 CPPUNIT_ASSERT(!_ap->GetBool("BoolValue"));
161 vector<int> intArray;
162 intArray.push_back(0);
163 intArray.push_back(1);
165 _ap->SetIntArray("IntArray", intArray);
166 CPPUNIT_ASSERT(_ap->IsSet("IntArray", PT_INTARRAY));
167 CPPUNIT_ASSERT(_ap->GetIntArray("IntArray")[0] == 0);
168 CPPUNIT_ASSERT(_ap->GetIntArray("IntArray")[1] == 1);
170 vector<double> realArray;
171 realArray.push_back(0.0);
172 realArray.push_back(1.1);
174 _ap->SetRealArray("RealArray", realArray);
175 CPPUNIT_ASSERT(_ap->IsSet("RealArray", PT_REALARRAY));
176 CPPUNIT_ASSERT(_ap->GetRealArray("RealArray")[0] == 0.0);
177 CPPUNIT_ASSERT(_ap->GetRealArray("RealArray")[1] == 1.1);
179 vector<string> strArray;
180 strArray.push_back("hello");
181 strArray.push_back("world");
183 _ap->SetStrArray("StrArray", strArray);
184 CPPUNIT_ASSERT(_ap->IsSet("StrArray", PT_STRARRAY));
185 CPPUNIT_ASSERT(_ap->GetStrArray("StrArray")[0] == "hello");
186 CPPUNIT_ASSERT(_ap->GetStrArray("StrArray")[1] == "world");