From eecdcfaf39b3b7466a5a6059bcbc97d73176085a Mon Sep 17 00:00:00 2001 From: srn Date: Thu, 9 Mar 2006 12:38:58 +0000 Subject: [PATCH] Cppunit tests for SALOMEDS --- src/SALOMEDS/Test/Makefile.in | 63 ++++++++++ src/SALOMEDS/Test/SALOMEDSTest.cxx | 190 +++++++++++++++++++++++++++++ src/SALOMEDS/Test/SALOMEDSTest.hxx | 48 ++++++++ src/SALOMEDS/Test/TestSALOMEDS.cxx | 35 ++++++ src/SALOMEDS/Test/TestSALOMEDS.py | 29 +++++ 5 files changed, 365 insertions(+) create mode 100644 src/SALOMEDS/Test/Makefile.in create mode 100644 src/SALOMEDS/Test/SALOMEDSTest.cxx create mode 100644 src/SALOMEDS/Test/SALOMEDSTest.hxx create mode 100644 src/SALOMEDS/Test/TestSALOMEDS.cxx create mode 100644 src/SALOMEDS/Test/TestSALOMEDS.py diff --git a/src/SALOMEDS/Test/Makefile.in b/src/SALOMEDS/Test/Makefile.in new file mode 100644 index 000000000..1f019da07 --- /dev/null +++ b/src/SALOMEDS/Test/Makefile.in @@ -0,0 +1,63 @@ +# SALOMELocalTrace : log on local machine +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Sergey RUIN +# Module : SALOME + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= SALOMEDSTest.hxx + +EXPORT_PYSCRIPTS = TestSALOMEDS.py + +# Libraries targets + +LIB = libSALOMEDSTest.la +LIB_SRC = SALOMEDSTest.cxx +LIB_CLIENT_IDL = SALOME_Component.idl SALOME_Exception.idl SALOME_GenericObj.idl SALOMEDS.idl + +# Executables targets + +BIN = TestSALOMEDS +BIN_SRC = + +CXXFLAGS += $(OCC_CXXFLAGS) @CPPUNIT_INCLUDES@ +CPPFLAGS += $(OCC_INCLUDES) @CPPUNIT_INCLUDES@ + +LIBS= @LIBS@ @CPPUNIT_LIBS@ + +LDFLAGS+= -lSalomeDSClient + +LDFLAGSFORBIN+= -L$(KERNEL_ROOT_DIR)/lib/salome -lSalomeDSClient -lSALOMELocalTrace $(LDFLAGS) -lSALOMELocalTraceTest -lSALOMEDSTest -lSALOMEDSImplTest + +UNIT_TEST_PROG = TestSALOMEDS + +@CONCLUDE@ diff --git a/src/SALOMEDS/Test/SALOMEDSTest.cxx b/src/SALOMEDS/Test/SALOMEDSTest.cxx new file mode 100644 index 000000000..c67bddeb9 --- /dev/null +++ b/src/SALOMEDS/Test/SALOMEDSTest.cxx @@ -0,0 +1,190 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// + +#include "SALOMEDSTest.hxx" + +#include +#include +#include +#include +#include +#include "utilities.h" +#include "Utils_SALOME_Exception.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" +#include "OpUtil.hxx" + +#include "SALOMEDSClient.hxx" +#include "SALOMEDSClient_ClientFactory.hxx" + +#include + +using namespace std; + +#define PT_INTEGER 0 +#define PT_REAL 1 +#define PT_BOOLEAN 2 +#define PT_STRING 3 +#define PT_REALARRAY 4 +#define PT_INTARRAY 5 +#define PT_STRARRAY 6 + + +#define TRACEFILE "/tmp/traceUnitTest.log" + +// ============================================================================ +/*! + * Set up the environment + */ +// ============================================================================ + +void SALOMEDSTest::setUp() +{ + TCollection_AsciiString kernel(getenv("KERNEL_ROOT_DIR")); + TCollection_AsciiString subPath("/share/salome/resources"); + TCollection_AsciiString csf_var = (kernel+subPath); + setenv("CSF_PluginDefaults", csf_var.ToCString(), 0); + setenv("CSF_SALOMEDS_ResourcesDefaults", csf_var.ToCString(), 0); + + // --- trace on file + char *theFileName = TRACEFILE; + + string s = "file:"; + s += theFileName; + CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite + + ofstream traceFile; + traceFile.open(theFileName, ios::out | ios::app); + CPPUNIT_ASSERT(traceFile); // file created empty, then closed + traceFile.close(); + + LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); + CPPUNIT_ASSERT(bp1); + + // --- Get or initialize the orb + + int _argc = 1; + char* _argv[] = {""}; + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()); + _orb = init(_argc , _argv ) ; + + sleep(2); + + // --- Create a SALOME_NamingService instance + + _NS = new SALOME_NamingService; + + sleep(2); + + _NS->init_orb(_orb) ; +} + +// ============================================================================ +/*! + * - delete trace classes + */ +// ============================================================================ + +void +SALOMEDSTest::tearDown() +{ + LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); + CPPUNIT_ASSERT(bp1); + bp1->deleteInstance(bp1); + + delete _NS; +} + +// ============================================================================ +/*! + * Check AttributeParameter + */ +// ============================================================================ +void SALOMEDSTest::testAttributeParameter() +{ + CORBA::Object_var obj = _orb->resolve_initial_references( "RootPOA" ); + PortableServer::POA_var poa = PortableServer::POA::_narrow( obj ); + + PortableServer::POAManager_var pman = poa->the_POAManager(); + pman->activate() ; + + _PTR(StudyManager) sm = ClientFactory::createStudyManager(_orb, poa); + + CPPUNIT_ASSERT(sm); + + _PTR(Study) study = sm->NewStudy("Test"); + + CPPUNIT_ASSERT(study); + + _PTR(AttributeParameter) _ap = study->GetCommonParameters("TestComp", 0); + + CPPUNIT_ASSERT(_ap); + + _ap->SetInt("IntValue", 1); + CPPUNIT_ASSERT(_ap->IsSet("IntValue", PT_INTEGER)); + CPPUNIT_ASSERT(_ap->GetInt("IntValue") == 1); + + _ap->SetReal("RealValue", 1.2); + CPPUNIT_ASSERT(_ap->IsSet("RealValue", PT_REAL)); + CPPUNIT_ASSERT(_ap->GetReal("RealValue") == 1.2); + + _ap->SetString("StringValue", "hello"); + CPPUNIT_ASSERT(_ap->IsSet("StringValue", PT_STRING)); + CPPUNIT_ASSERT(_ap->GetString("StringValue") == "hello"); + + _ap->SetBool("BoolValue", 0); + CPPUNIT_ASSERT(_ap->IsSet("BoolValue", PT_BOOLEAN)); + CPPUNIT_ASSERT(!_ap->GetBool("BoolValue")); + + _ap->SetBool("BoolValue", 0); + CPPUNIT_ASSERT(_ap->IsSet("BoolValue", PT_BOOLEAN)); + CPPUNIT_ASSERT(!_ap->GetBool("BoolValue")); + + vector intArray; + intArray.push_back(0); + intArray.push_back(1); + + _ap->SetIntArray("IntArray", intArray); + CPPUNIT_ASSERT(_ap->IsSet("IntArray", PT_INTARRAY)); + CPPUNIT_ASSERT(_ap->GetIntArray("IntArray")[0] == 0); + CPPUNIT_ASSERT(_ap->GetIntArray("IntArray")[1] == 1); + + vector realArray; + realArray.push_back(0.0); + realArray.push_back(1.1); + + _ap->SetRealArray("RealArray", realArray); + CPPUNIT_ASSERT(_ap->IsSet("RealArray", PT_REALARRAY)); + CPPUNIT_ASSERT(_ap->GetRealArray("RealArray")[0] == 0.0); + CPPUNIT_ASSERT(_ap->GetRealArray("RealArray")[1] == 1.1); + + vector strArray; + strArray.push_back("hello"); + strArray.push_back("world"); + + _ap->SetStrArray("StrArray", strArray); + CPPUNIT_ASSERT(_ap->IsSet("StrArray", PT_STRARRAY)); + CPPUNIT_ASSERT(_ap->GetStrArray("StrArray")[0] == "hello"); + CPPUNIT_ASSERT(_ap->GetStrArray("StrArray")[1] == "world"); +} + + + diff --git a/src/SALOMEDS/Test/SALOMEDSTest.hxx b/src/SALOMEDS/Test/SALOMEDSTest.hxx new file mode 100644 index 000000000..35998193f --- /dev/null +++ b/src/SALOMEDS/Test/SALOMEDSTest.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2006 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// + +#ifndef _SALOMEDSTEST_HXX_ +#define _SALOMEDSTEST_HXX_ + +#include + +#include + +#include +#include "SALOME_NamingService.hxx" + +class SALOMEDSTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( SALOMEDSTest ); + CPPUNIT_TEST( testAttributeParameter ); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp(); + void tearDown(); + void testAttributeParameter(); + +protected: + CORBA::ORB_var _orb; + SALOME_NamingService* _NS; +}; + +#endif diff --git a/src/SALOMEDS/Test/TestSALOMEDS.cxx b/src/SALOMEDS/Test/TestSALOMEDS.cxx new file mode 100644 index 000000000..c2689eca2 --- /dev/null +++ b/src/SALOMEDS/Test/TestSALOMEDS.cxx @@ -0,0 +1,35 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// + +// --- include all SALOMEDS Test from basics until the present directory + +#include "SALOMELocalTraceTest.hxx" +#include "SALOMEDSImplTest.hxx" +#include "SALOMEDSTest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSImplTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMEDSTest ); + +// --- generic Main program from Basic/Test + +#include "BasicMainTest.hxx" diff --git a/src/SALOMEDS/Test/TestSALOMEDS.py b/src/SALOMEDS/Test/TestSALOMEDS.py new file mode 100644 index 000000000..faae31b6e --- /dev/null +++ b/src/SALOMEDS/Test/TestSALOMEDS.py @@ -0,0 +1,29 @@ + +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# execute Unit Test + +command = ['TestSALOMEDS'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill Test process + +TestKiller.killProcess(runSalome.process_id) -- 2.39.2