KERNEL_PY \
ModuleGenerator \
Communication \
+ \
+ SALOMELocalTrace/Test \
+ SALOMETraceCollector/Test \
+ Utils/Test \
+ UnitTests
ifeq (@mpi_ok@,yes)
SUBDIRS+= MPIContainer TestMPIContainer
--- /dev/null
+# 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 : Paul RASCLE (EDF)
+# Module : SALOME
+# $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# header files
+EXPORT_HEADERS= SALOMELocalTraceTest.hxx
+
+EXPORT_PYSCRIPTS =
+
+# Libraries targets
+
+LIB = libSALOMELocalTraceTest.la
+LIB_SRC = SALOMELocalTraceTest.cxx
+
+LIBS= @LIBS@
+LDFLAGS+= -lSALOMELocalTrace
+
+
+@CONCLUDE@
--- /dev/null
+
+#include "SALOMELocalTraceTest.hxx"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cstdlib>
+#include "LocalTraceBufferPool.hxx"
+#include "utilities.h"
+
+using namespace std;
+
+// --- Registers the fixture into the 'registry'
+
+CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest );
+
+// ============================================================================
+/*!
+ *
+ */
+// ============================================================================
+
+void
+SALOMELocalTraceTest::setUp()
+{
+}
+
+// ============================================================================
+/*!
+ *
+ */
+// ============================================================================
+
+void
+SALOMELocalTraceTest::tearDown()
+{
+}
+
+#define TRACEFILE "/tmp/traceUnitTest.log"
+
+// ============================================================================
+/*!
+ * Open and close a trace on a file, test singleton
+ */
+// ============================================================================
+
+void
+SALOMELocalTraceTest::testSingletonBufferPool()
+{
+ // --- 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::trunc);
+ CPPUNIT_ASSERT(traceFile); // file created empty, then closed
+ traceFile.close();
+
+ LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+ LocalTraceBufferPool* bp2 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1 == bp2);
+ bp1->deleteInstance(bp1);
+}
+
+
+
+#define NUM_THREADS 2
+#define NUM_MESSAGES 5
+void *PrintHello(void *threadid);
+
+// ============================================================================
+/*!
+ * open a trace on console, multithread writing on file, close
+ */
+// ============================================================================
+
+void
+SALOMELocalTraceTest::testLoadBufferPoolLocal()
+{
+ string s = "local";
+ CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
+
+ // --- numThread thread creation for trace generation.
+ int numThread = 2;
+ pthread_t threads[numThread];
+ int rc, t;
+ for(t=0;t<numThread;t++)
+ {
+ MESSAGE("Creating thread " << t);
+ rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t) ;
+ CPPUNIT_ASSERT( !rc);
+ }
+
+ // --- wait for end of each thread producing trace.
+
+ for(t=0;t<numThread;t++)
+ {
+ int ret = pthread_join(threads[t], NULL);
+ MESSAGE("--------------------- end of PrintHello thread " << t);
+ }
+ MESSAGE(" ---- end of PrintHello threads ---- ");
+
+ LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+ bp1->deleteInstance(bp1);
+}
+
+// ============================================================================
+/*!
+ * open a trace on a file, multithread writing on file, close
+ */
+// ============================================================================
+
+void
+SALOMELocalTraceTest::testLoadBufferPoolFile()
+{
+ char *theFileName = TRACEFILE;
+
+ string s = "file:";
+ s += theFileName;
+ //s = "local";
+ CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
+
+ ofstream traceFile;
+ traceFile.open(theFileName, ios::out | ios::trunc);
+ CPPUNIT_ASSERT(traceFile); // file created empty, then closed
+ traceFile.close();
+
+ // --- NUM_THREADS thread creation for trace generation.
+
+ pthread_t threads[NUM_THREADS];
+ int rc, t;
+ for(t=0;t<NUM_THREADS;t++)
+ {
+ MESSAGE("Creating thread " << t);
+ rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t) ;
+ CPPUNIT_ASSERT( !rc);
+ }
+
+ // --- wait for end of each thread producing trace.
+
+ for(t=0;t<NUM_THREADS;t++)
+ {
+ int ret = pthread_join(threads[t], NULL);
+ MESSAGE("--------------------- end of PrintHello thread " << t);
+ }
+ MESSAGE(" ---- end of PrintHello threads ---- ");
+
+ LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+ bp1->deleteInstance(bp1);
+}
+
+// ============================================================================
+/*!
+ * NUM_THREAD are created with function PrintHello,
+ * which produces NUM_MESSAGES traces.
+ */
+// ============================================================================
+
+void *PrintHello(void *threadid)
+{
+ int id_thread = (int)threadid;
+ for (int i=0; i<NUM_MESSAGES;i++)
+ MESSAGE("Hello World! This is a trace test : " << id_thread
+ << " - iter " << i);
+ pthread_exit(NULL);
+}
--- /dev/null
+
+#ifndef _SALOMELOCALTRACETEST_HXX_
+#define _SALOMELOCALTRACETEST_HXX_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class SALOMELocalTraceTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( SALOMELocalTraceTest );
+ CPPUNIT_TEST( testSingletonBufferPool );
+ CPPUNIT_TEST( testLoadBufferPoolLocal );
+ CPPUNIT_TEST( testLoadBufferPoolFile );
+ CPPUNIT_TEST( testLoadBufferPoolFile );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+ void tearDown();
+
+ void testSingletonBufferPool();
+ void testLoadBufferPoolLocal();
+ void testLoadBufferPoolFile();
+};
+
+#endif
--- /dev/null
+# 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 : Paul RASCLE (EDF)
+# Module : SALOME
+# $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# header files
+EXPORT_HEADERS= SALOMETraceCollectorTest.hxx
+
+EXPORT_PYSCRIPTS =
+
+# Libraries targets
+
+LIB = libSALOMETraceCollectorTest.la
+LIB_SRC = SALOMETraceCollectorTest.cxx
+
+LIBS= @LIBS@
+LDFLAGS+=
+
+@CONCLUDE@
--- /dev/null
+
+#include "SALOMETraceCollectorTest.hxx"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cstdlib>
+#include "LocalTraceBufferPool.hxx"
+#include "utilities.h"
+
+using namespace std;
+
+// --- Registers the fixture into the 'registry'
+
+CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest );
+
+// ============================================================================
+/*!
+ *
+ */
+// ============================================================================
+
+void
+SALOMETraceCollectorTest::setUp()
+{
+}
+
+// ============================================================================
+/*!
+ *
+ */
+// ============================================================================
+
+void
+SALOMETraceCollectorTest::tearDown()
+{
+}
+
+#define NUM_THREADS 20
+#define NUM_MESSAGES 20
+void *PrintHello(void *threadid);
+
+// ============================================================================
+/*!
+ * open a trace on a CORBA, multithread writing on file, close
+ */
+// ============================================================================
+
+void
+SALOMETraceCollectorTest::testLoadBufferPoolCORBA()
+{
+ string s = "with_logger";
+ CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
+
+ // --- NUM_THREADS thread creation for trace generation.
+
+ pthread_t threads[NUM_THREADS];
+ int rc, t;
+ for(t=0;t<NUM_THREADS;t++)
+ {
+ MESSAGE("Creating thread " << t);
+ rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t) ;
+ CPPUNIT_ASSERT( !rc);
+ }
+
+ // --- wait for end of each thread producing trace.
+
+ for(t=0;t<NUM_THREADS;t++)
+ {
+ int ret = pthread_join(threads[t], NULL);
+ MESSAGE("--------------------- end of PrintHello thread " << t);
+ }
+ MESSAGE(" ---- end of PrintHello threads ---- ");
+
+ LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+ bp1->deleteInstance(bp1);
+}
+
+// ============================================================================
+/*!
+ * NUM_THREAD are created with function PrintHello,
+ * which produces NUM_MESSAGES traces.
+ */
+// ============================================================================
+
+void *PrintHello(void *threadid)
+{
+ int id_thread = (int)threadid;
+ for (int i=0; i<NUM_MESSAGES;i++)
+ MESSAGE("Hello World! This is a trace test : " << id_thread
+ << " - iter " << i);
+ pthread_exit(NULL);
+}
--- /dev/null
+
+#ifndef _SALOMETRACECOLLECTORTTEST_HXX_
+#define _SALOMETRACECOLLECTORTTEST_HXX_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class SALOMETraceCollectorTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( SALOMETraceCollectorTest );
+ CPPUNIT_TEST( testLoadBufferPoolCORBA );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void setUp();
+ void tearDown();
+
+ void testLoadBufferPoolCORBA();
+};
+
+#endif
--- /dev/null
+#
+# 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 : Paul RASCLE (EDF)
+# Module : SALOME
+# $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# header files
+EXPORT_HEADERS=
+
+EXPORT_PYSCRIPTS =
+
+# Libraries targets
+
+LIB =
+LIB_SRC =
+
+# Executables targets
+
+BIN = UnitTests
+BIN_SRC =
+
+
+LIBS= @LIBS@
+LDFLAGSFORBIN+= \
+ -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \
+ -lSALOMETraceCollectorTest \
+ -lUtilsTest -lOpUtil \
+ -lcppunit
+# -lefence
+
+
+@CONCLUDE@
--- /dev/null
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TextTestProgressListener.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+//#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/TestRunner.h>
+#include <stdexcept>
+
+#include "SALOMELocalTraceTest.hxx"
+#include "SALOMETraceCollectorTest.hxx"
+
+#include "UtilsTest.hxx"
+
+int main(int argc, char* argv[])
+{
+ // Create the event manager and test controller
+ CPPUNIT_NS::TestResult controller;
+
+ // Add a listener that colllects test result
+ CPPUNIT_NS::TestResultCollector result;
+ controller.addListener( &result );
+
+ // Add a listener that print dots as test run.
+#ifdef WIN32
+ CPPUNIT_NS::TextTestProgressListener progress;
+#else
+ CPPUNIT_NS::BriefTestProgressListener progress;
+#endif
+ controller.addListener( &progress );
+
+ // Get the top level suite from the registry
+ //CppUnit::Test *suite =CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+ CPPUNIT_NS::Test *suite =
+ CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
+
+ // Adds the test to the list of test to run
+ //CppUnit::TextUi::TestRunner runner;
+ CPPUNIT_NS::TestRunner runner;
+ runner.addTest( suite );
+ runner.run( controller);
+ // Print test in a compiler compatible format.
+ CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
+ outputter.write();
+
+ // Change the default outputter to a compiler error format outputter
+ // runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
+ // std::cerr ) );
+
+ // Run the tests.
+ //bool wasSucessful = runner.run();
+ bool wasSucessful = result.wasSuccessful();
+
+ // Return error code 1 if the one of test failed.
+ return wasSucessful ? 0 : 1;
+}
--- /dev/null
+# 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 : Paul RASCLE (EDF)
+# Module : SALOME
+# $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# header files
+EXPORT_HEADERS= UtilsTest.hxx
+
+EXPORT_PYSCRIPTS =
+
+# Libraries targets
+
+LIB = libUtilsTest.la
+LIB_SRC = UtilsTest.cxx
+
+LIBS= @LIBS@
+LDFLAGS+=
+
+@CONCLUDE@
--- /dev/null
+
+#include "UtilsTest.hxx"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cstdlib>
+#include "Utils_SALOME_Exception.hxx"
+#include "utilities.h"
+
+using namespace std;
+
+// --- Registers the fixture into the 'registry'
+
+CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest );
+
+#define TRACEFILE "/tmp/traceUnitTest.log"
+
+// ============================================================================
+/*!
+ * Set Trace mecanism
+ * - delete preexisting trace classes if any
+ * - set trace on file
+ */
+// ============================================================================
+
+void
+UtilsTest::setUp()
+{
+ LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+ bp1->deleteInstance(bp1);
+
+ // --- 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::trunc);
+ CPPUNIT_ASSERT(traceFile); // file created empty, then closed
+ traceFile.close();
+
+ bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+}
+
+// ============================================================================
+/*!
+ * - delete trace classes
+ */
+// ============================================================================
+
+void
+UtilsTest::tearDown()
+{
+ LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
+ CPPUNIT_ASSERT(bp1);
+ bp1->deleteInstance(bp1);
+}
+
+int genExcept()
+{
+ throw SALOME_Exception("a message");
+};
+
+// ============================================================================
+/*!
+ * Check basic SALOME_exception mecanism
+ */
+// ============================================================================
+
+void
+UtilsTest::testSALOME_ExceptionThrow()
+{
+ CPPUNIT_ASSERT_THROW(genExcept(), SALOME_Exception);
+}
+
+// ============================================================================
+/*!
+ * Check message on catch
+ */
+// ============================================================================
+
+void
+UtilsTest::testSALOME_ExceptionMessage()
+{
+#define EXAMPLE_EXCEPTION_MESSAGE "something for the end user"
+ try
+ {
+ throw SALOME_Exception(EXAMPLE_EXCEPTION_MESSAGE);
+ }
+ catch (const SALOME_Exception &ex)
+ {
+ string expectedMessage = EXAMPLE_EXCEPTION_MESSAGE;
+ string actualMessage = ex.what();
+ CPPUNIT_ASSERT(actualMessage.find(expectedMessage) != string::npos);
+ }
+}
--- /dev/null
+
+#ifndef _UTILSTEST_HXX_
+#define _UTILSTEST_HXX_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class UtilsTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE( UtilsTest );
+ CPPUNIT_TEST( testSALOME_ExceptionThrow );
+ CPPUNIT_TEST( testSALOME_ExceptionMessage );
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+
+ void setUp();
+ void tearDown();
+
+ void testSALOME_ExceptionThrow();
+ void testSALOME_ExceptionMessage();
+};
+
+#endif