From cac0e2b731df1ca558e60fe52f062d45f5edd28d Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Wed, 10 Aug 2016 10:54:12 +0200 Subject: [PATCH] Use real temporary file name for unit tests trace --- .../Test/LifeCycleCORBATest.cxx | 28 +++++--- .../Test/LifeCycleCORBATest.hxx | 4 ++ src/NamingService/Test/NamingServiceTest.cxx | 70 ++++++++++--------- src/NamingService/Test/NamingServiceTest.hxx | 4 ++ .../Test/SALOMELocalTraceTest.cxx | 31 ++++---- .../Test/SALOMELocalTraceTest.hxx | 4 ++ src/Utils/Test/UtilsTest.cxx | 20 ++++-- src/Utils/Test/UtilsTest.hxx | 4 ++ 8 files changed, 103 insertions(+), 62 deletions(-) diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx index 6381ab2ab..9d7a5db9e 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx @@ -26,6 +26,7 @@ #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "Basics_Utils.hxx" +#include "Basics_DirUtils.hxx" #include "utilities.h" #include @@ -47,9 +48,14 @@ #endif #ifdef WIN32 #define setenv Kernel_Utils::setenv -#endif +#endif -#define TRACEFILE "/tmp/traceUnitTest.log" +std::string +LifeCycleCORBATest::_getTraceFileName() +{ + std::string dir = Kernel_Utils::GetTmpDir(); + return dir + "traceUnitTest-LifeCycleCORBATest.log"; +} // ============================================================================ /*! @@ -61,7 +67,7 @@ */ // ============================================================================ -void +void LifeCycleCORBATest::setUp() { LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); @@ -69,7 +75,7 @@ LifeCycleCORBATest::setUp() bp1->deleteInstance(bp1); // --- trace on file - const char *theFileName = TRACEFILE; + std::string theFileName = _getTraceFileName(); std::string s = "file:"; s += theFileName; @@ -79,7 +85,7 @@ LifeCycleCORBATest::setUp() std::ofstream traceFile; // traceFile.open(theFileName, std::ios::out | std::ios::trunc); - traceFile.open(theFileName, std::ios::out | std::ios::app); + traceFile.open(theFileName.c_str(), std::ios::out | std::ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); @@ -105,7 +111,7 @@ LifeCycleCORBATest::setUp() */ // ============================================================================ -void +void LifeCycleCORBATest::tearDown() { @@ -262,7 +268,7 @@ LifeCycleCORBATest::testFindOrLoad_Component_PythonSameInstance() /*! * Check FindOrLoad_Component with a component name not in catalog. * See list of catalog given to module catalog server. - * Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains + * Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains * only KERNEL, SalomeTestComponent and SALOME_TestComponentPy */ // ============================================================================ @@ -435,7 +441,7 @@ LifeCycleCORBATest::testFindOrLoad_Component_ParamsEmpty() // ============================================================================ /*! - * Check FindOrLoad_Component params = local container + * Check FindOrLoad_Component params = local container */ // ============================================================================ @@ -541,7 +547,7 @@ LifeCycleCORBATest::testFindOrLoad_Component_RemoteComputer() // ============================================================================ /*! * Check FindOrLoad_Component with params on remote computer - * params empty except hostname + * params empty except hostname */ // ============================================================================ @@ -553,7 +559,7 @@ LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer() std::string remoteHost = GetRemoteHost(); Engines::ContainerParameters params; - _LCC.preSet(params); + _LCC.preSet(params); params.resource_params.hostname = remoteHost.c_str(); Engines::EngineComponent_var mycompo1 = @@ -591,7 +597,7 @@ LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer2() std::string remoteHost = GetRemoteHost(); Engines::ContainerParameters params; - _LCC.preSet(params); + _LCC.preSet(params); params.resource_params.hostname = remoteHost.c_str(); params.container_name = "anotherContainer"; diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx index d97b48a0a..bd6535651 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx @@ -24,6 +24,7 @@ #define _LIFECYCLECORBATEST_HXX_ #include +#include #include #include CORBA_CLIENT_HEADER(SALOME_Component) @@ -92,6 +93,9 @@ public: // void testFindOrLoad_Component_(); // void testFindOrLoad_Component_(); + private: + std::string _getTraceFileName(); + protected: std::string GetRemoteHost(); CORBA::ORB_var _orb; diff --git a/src/NamingService/Test/NamingServiceTest.cxx b/src/NamingService/Test/NamingServiceTest.cxx index 1f9b93f2e..9daff2e34 100644 --- a/src/NamingService/Test/NamingServiceTest.cxx +++ b/src/NamingService/Test/NamingServiceTest.cxx @@ -24,6 +24,7 @@ #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" #include "Basics_Utils.hxx" +#include "Basics_DirUtils.hxx" #include "SALOME_LifeCycleCORBA.hxx" #include "utilities.h" @@ -48,9 +49,7 @@ #ifdef WIN32 #define setenv Kernel_Utils::setenv -#endif - -#define TRACEFILE "/tmp/traceUnitTest.log" +#endif // ============================================================================ /*! @@ -111,7 +110,14 @@ NSTEST::echo_ptr NSTEST_aFactory_i::createInstance() */ // ============================================================================ -void +std::string +NamingServiceTest::_getTraceFileName() +{ + std::string dir = Kernel_Utils::GetTmpDir(); + return dir + "traceUnitTest-NamingServiceTest.log"; +} + +void NamingServiceTest::setUp() { LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); @@ -119,7 +125,7 @@ NamingServiceTest::setUp() bp1->deleteInstance(bp1); // --- trace on file - const char *theFileName = TRACEFILE; + std::string theFileName = _getTraceFileName(); std::string s = "file:"; s += theFileName; @@ -129,7 +135,7 @@ NamingServiceTest::setUp() std::ofstream traceFile; // traceFile.open(theFileName, ios::out | ios::trunc); - traceFile.open(theFileName, std::ios::out | std::ios::app); + traceFile.open(theFileName.c_str(), std::ios::out | std::ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); @@ -159,7 +165,7 @@ NamingServiceTest::setUp() _factoryRef = _myFactory->_this(); _pman->activate(); _myFactory->_remove_ref(); - + } // ============================================================================ @@ -168,7 +174,7 @@ NamingServiceTest::setUp() */ // ============================================================================ -void +void NamingServiceTest::tearDown() { @@ -456,7 +462,7 @@ NamingServiceTest::testResolveFirst() * Test register and resolve multiple objects, test resolveFirst, relative path * Register a few objects in /nstestfirstrel/echo_n where n is the object id. * Resolve all the objects. - * ResolveFirst echo with a relative path /nstestfirstrel must give + * ResolveFirst echo with a relative path /nstestfirstrel must give * /nstestfirst/echo_i, corresponding to the first object. */ // ============================================================================ @@ -684,7 +690,7 @@ NamingServiceTest::testResolveComponentEmptyContainerName() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -716,7 +722,7 @@ NamingServiceTest::testResolveComponentUnknownContainerName() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -744,7 +750,7 @@ NamingServiceTest::testResolveComponentEmptyComponentName() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -768,7 +774,7 @@ NamingServiceTest::testResolveComponentUnknownComponentName() // ============================================================================ /*! - * Test with a false number nbproc. + * Test with a false number nbproc. * A positive number not corresponding to a registered component gives nil ref. * A negative number is not taken into account and may give a non nil ref. */ @@ -801,7 +807,7 @@ NamingServiceTest::testResolveComponentFalseNbproc() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -819,7 +825,7 @@ NamingServiceTest::testContainerName() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -841,7 +847,7 @@ NamingServiceTest::testContainerNameParams() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -859,7 +865,7 @@ NamingServiceTest::testBuildContainerNameForNS() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -882,7 +888,7 @@ NamingServiceTest::testBuildContainerNameForNSParams() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -925,7 +931,7 @@ NamingServiceTest::testFind() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -972,7 +978,7 @@ NamingServiceTest::testCreateDirectory() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -999,11 +1005,11 @@ NamingServiceTest::testChangeDirectory() NSTEST::echo_var anEchoRef4 = myFactory->createInstance(); _NS.Register(anEchoRef4, "/Containers/anHostName/oneContainerName/theComponentName"); - + _NS.Change_Directory("/Containers/theHostName/otherContainerName"); obj = _NS.Resolve("theComponentName"); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); - + NSTEST::echo_var anEchoRefa = NSTEST::echo::_narrow(obj); CPPUNIT_ASSERT(!CORBA::is_nil(anEchoRefa)); CPPUNIT_ASSERT(anEchoRefa->getId() == anEchoRef3->getId()); @@ -1011,7 +1017,7 @@ NamingServiceTest::testChangeDirectory() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1031,7 +1037,7 @@ NamingServiceTest::testCurrentDirectory() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1046,7 +1052,7 @@ NamingServiceTest::testList() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1061,7 +1067,7 @@ NamingServiceTest::testListDirectory() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1079,7 +1085,7 @@ NamingServiceTest::testListDirectoryRecurs() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1095,7 +1101,7 @@ NamingServiceTest::testListSubdirs() } // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1122,7 +1128,7 @@ NamingServiceTest::testDestroyName() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1193,7 +1199,7 @@ NamingServiceTest::testDestroyFullDirectory() // ============================================================================ /*! - * Test + * Test */ // ============================================================================ @@ -1202,12 +1208,12 @@ NamingServiceTest::testGetIorAddr() { CORBA::String_var root = _NS.getIORaddr(); CORBA::Object_var obj = _orb->string_to_object(root); - CPPUNIT_ASSERT(!CORBA::is_nil(obj)); + CPPUNIT_ASSERT(!CORBA::is_nil(obj)); } // ============================================================================ /*! - * Test + * Test */ // ============================================================================ diff --git a/src/NamingService/Test/NamingServiceTest.hxx b/src/NamingService/Test/NamingServiceTest.hxx index 775dd4c92..e1fc23ffd 100644 --- a/src/NamingService/Test/NamingServiceTest.hxx +++ b/src/NamingService/Test/NamingServiceTest.hxx @@ -25,6 +25,7 @@ #include #include "SALOME_NamingService.hxx" +#include #include #include CORBA_SERVER_HEADER(nstest) @@ -149,6 +150,9 @@ public: void testDestroyFullDirectory(); void testGetIorAddr(); + private: + std::string _getTraceFileName(); + protected: void _destroyDirectoryRecurs(std::string path); diff --git a/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx b/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx index 63b7413ea..2934ce036 100644 --- a/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx +++ b/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx @@ -26,13 +26,15 @@ #include #include #include +#include #include "LocalTraceBufferPool.hxx" #include "utilities.h" #include "Basics_Utils.hxx" +#include "Basics_DirUtils.hxx" #ifdef WIN32 #define setenv Kernel_Utils::setenv -#endif +#endif // ============================================================================ /*! @@ -40,7 +42,7 @@ */ // ============================================================================ -void +void SALOMELocalTraceTest::setUp() { } @@ -51,12 +53,17 @@ SALOMELocalTraceTest::setUp() */ // ============================================================================ -void +void SALOMELocalTraceTest::tearDown() { } -#define TRACEFILE "/tmp/traceUnitTest.log" +std::string +SALOMELocalTraceTest::_getTraceFileName() +{ + std::string dir = Kernel_Utils::GetTmpDir(); + return dir + "traceUnitTest-SALOMELocalTraceTest.log"; +} // ============================================================================ /*! @@ -64,18 +71,18 @@ SALOMELocalTraceTest::tearDown() */ // ============================================================================ -void +void SALOMELocalTraceTest::testSingletonBufferPool() { // --- trace on file - const char *theFileName = TRACEFILE; + std::string theFileName = _getTraceFileName(); std::string s = "file:"; s += theFileName; CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite std::ofstream traceFile; - traceFile.open(theFileName, std::ios::out | std::ios::app); + traceFile.open(theFileName.c_str(), std::ios::out | std::ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); @@ -98,7 +105,7 @@ void *PrintHello(void *threadid); */ // ============================================================================ -void +void SALOMELocalTraceTest::testLoadBufferPoolLocal() { std::string s = "local"; @@ -134,10 +141,10 @@ SALOMELocalTraceTest::testLoadBufferPoolLocal() */ // ============================================================================ -void +void SALOMELocalTraceTest::testLoadBufferPoolFile() { - const char *theFileName = TRACEFILE; + std::string theFileName = _getTraceFileName(); std::string s = "file:"; s += theFileName; @@ -145,7 +152,7 @@ SALOMELocalTraceTest::testLoadBufferPoolFile() CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite std::ofstream traceFile; - traceFile.open(theFileName, std::ios::out | std::ios::trunc); + traceFile.open(theFileName.c_str(), std::ios::out | std::ios::trunc); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); @@ -186,7 +193,7 @@ void *PrintHello(void *threadid) #if defined(_DEBUG_) || defined(_DEBUG) long id_thread = (long)threadid; for (int i=0; i +#include #ifdef WIN32 # if defined SALOMELOCALTRACETEST_EXPORTS || defined SALOMELocalTraceTest_EXPORTS @@ -50,6 +51,9 @@ public: void testSingletonBufferPool(); void testLoadBufferPoolLocal(); void testLoadBufferPoolFile(); + + private: + std::string _getTraceFileName(); }; #endif diff --git a/src/Utils/Test/UtilsTest.cxx b/src/Utils/Test/UtilsTest.cxx index b4ea58cbe..8091c2f82 100644 --- a/src/Utils/Test/UtilsTest.cxx +++ b/src/Utils/Test/UtilsTest.cxx @@ -28,13 +28,12 @@ #include #include "Utils_SALOME_Exception.hxx" #include "Basics_Utils.hxx" +#include "Basics_DirUtils.hxx" #include "utilities.h" #ifdef WIN32 #define setenv Kernel_Utils::setenv -#endif - -#define TRACEFILE "/tmp/traceUnitTest.log" +#endif // ============================================================================ /*! @@ -44,7 +43,14 @@ */ // ============================================================================ -void +std::string +UtilsTest::_getTraceFileName() +{ + std::string dir = Kernel_Utils::GetTmpDir(); + return dir + "traceUnitTest-UtilsTest.log"; +} + +void UtilsTest::setUp() { LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); @@ -52,14 +58,14 @@ UtilsTest::setUp() bp1->deleteInstance(bp1); // --- trace on file - const char *theFileName = TRACEFILE; + std::string theFileName = _getTraceFileName(); std::string s = "file:"; s += theFileName; CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite std::ofstream traceFile; - traceFile.open(theFileName, std::ios::out | std::ios::app); + traceFile.open(theFileName.c_str(), std::ios::out | std::ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); @@ -73,7 +79,7 @@ UtilsTest::setUp() */ // ============================================================================ -void +void UtilsTest::tearDown() { LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); diff --git a/src/Utils/Test/UtilsTest.hxx b/src/Utils/Test/UtilsTest.hxx index d6b483bfe..d3a46b3a9 100644 --- a/src/Utils/Test/UtilsTest.hxx +++ b/src/Utils/Test/UtilsTest.hxx @@ -24,6 +24,7 @@ #define _UTILSTEST_HXX_ #include +#include #ifdef WIN32 # if defined UTILSTEST_EXPORTS || defined UtilsTest_EXPORTS @@ -49,6 +50,9 @@ public: void testSALOME_ExceptionThrow(); void testSALOME_ExceptionMessage(); + + private: + std::string _getTraceFileName(); }; #endif -- 2.39.2