$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r48848 - in trunk/libs/test/tools/console_test_runner: . src test
From: gennadiy.rozental_at_[hidden]
Date: 2008-09-18 01:05:04
Author: rogeeff
Date: 2008-09-18 01:05:03 EDT (Thu, 18 Sep 2008)
New Revision: 48848
URL: http://svn.boost.org/trac/boost/changeset/48848
Log:
Linux port
Jamfile introduced
Added:
   trunk/libs/test/tools/console_test_runner/Jamfile.v2   (contents, props changed)
Text files modified: 
   trunk/libs/test/tools/console_test_runner/src/console_test_runner.cpp |   145 ++++++++++++++++++++++++++++++++++----- 
   trunk/libs/test/tools/console_test_runner/test/test_runner_test.cpp   |     7 +                                       
   2 files changed, 132 insertions(+), 20 deletions(-)
Added: trunk/libs/test/tools/console_test_runner/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/test/tools/console_test_runner/Jamfile.v2	2008-09-18 01:05:03 EDT (Thu, 18 Sep 2008)
@@ -0,0 +1,31 @@
+#  (C) Copyright Gennadiy Rozental 2008-2008.
+#  Use, modification, and distribution are subject to the 
+#  Boost Software License, Version 1.0. (See accompanying file 
+#  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#
+#  See http://www.boost.org/libs/test for the library home page.
+
+# Project
+project libs/test/tools/console_test_runner ;
+import os ;
+
+alias unit_test_framework
+    : # sources
+        /boost//unit_test_framework
+    ;        
+
+# make aliases explicit so the libraries will only be built when requested
+explicit unit_test_framework ;
+
+if [ os.name ] != NT
+{
+  lib dl ; 
+}
+
+
+lib test_runner_test : test/test_runner_test.cpp unit_test_framework ; 
+
+exe console_test_runner 
+    : src/console_test_runner.cpp unit_test_framework 
+    : <os>LINUX:<library>dl 
+    ;
Modified: trunk/libs/test/tools/console_test_runner/src/console_test_runner.cpp
==============================================================================
--- trunk/libs/test/tools/console_test_runner/src/console_test_runner.cpp	(original)
+++ trunk/libs/test/tools/console_test_runner/src/console_test_runner.cpp	2008-09-18 01:05:03 EDT (Thu, 18 Sep 2008)
@@ -6,7 +6,9 @@
 //  See http://www.boost.org/libs/test for the library home page.
 
 // Boost.Test
+#ifndef BOOST_TEST_DYN_LINK
 #define BOOST_TEST_DYN_LINK
+#endif
 #include <boost/test/unit_test.hpp>
 
 // Boost.Runtime.Param
@@ -19,38 +21,144 @@
 // STL
 #include <iostream>
 
-// PLATFORM HEADER
-#if defined(BOOST_WINDOWS) && !defined(BOOST_DISABLE_WIN32)
-#define USE_WIN32_API
+//_________________________________________________________________//
+
+// System API
+
+namespace dyn_lib {
+
+#if defined(BOOST_WINDOWS) && !defined(BOOST_DISABLE_WIN32) // WIN32 API
+
 #include <windows.h>
+
+typedef HINSTANCE handle;
+
+inline handle
+open( std::string const& file_name )
+{
+    return LoadLibrary( file_name.c_str() );
+}
+
+//_________________________________________________________________//
+
+template<typename TargType>
+inline TargType
+locate_symbol( handle h, std::string const& symbol )
+{
+    return reinterpret_cast<TargType>( GetProcAddress( h, symbol.c_str() ) );
+}
+
+//_________________________________________________________________//
+
+inline void
+close( handle h )
+{
+    if( h )
+        FreeLibrary( h );
+}
+
+//_________________________________________________________________//
+
+inline std::string
+error()
+{
+    LPTSTR msg = NULL;
+
+    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+                   NULL, 
+                   GetLastError(), 
+                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                   (LPTSTR)&msg, 
+                   0, NULL );
+
+    std::string res( msg );
+
+    if( msg )
+        LocalFree( msg );
+
+    return res;    
+}
+
+//_________________________________________________________________//
+
+#elif defined(BOOST_HAS_UNISTD_H) // POSIX API
+
+#include <dlfcn.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
+typedef void* handle;
+
+inline handle
+open( std::string const& file_name )
+{
+    return dlopen( file_name.c_str(), RTLD_LOCAL | RTLD_LAZY );
+}
+
+//_________________________________________________________________//
+
+template<typename TargType>
+inline TargType
+locate_symbol( handle h, std::string const& symbol )
+{
+    return reinterpret_cast<TargType>( dlsym( h, symbol.c_str() ) );
+}
+
+//_________________________________________________________________//
+
+inline void
+close( handle h )
+{
+    if( h )
+        dlclose( h );
+}
+
+//_________________________________________________________________//
+
+inline std::string
+error()
+{
+    return dlerror();
+}
+
+//_________________________________________________________________//
+
+#else
+
+#error "Dynamic library API is unknown"
+
 #endif
 
+} // namespace dyn_lib
+
 //____________________________________________________________________________//
 
 static std::string test_lib_name;
 static std::string init_func_name( "init_unit_test" );
-#ifdef USE_WIN32_API
-static HINSTANCE test_lib_handle;
-#endif
+
+dyn_lib::handle test_lib_handle;
 
 bool load_test_lib()
 {
     typedef bool (*init_func_ptr)();
     init_func_ptr init_func;
 
-#ifdef USE_WIN32_API
-    HINSTANCE test_lib_handle = LoadLibrary( test_lib_name.c_str() );
+    test_lib_handle = dyn_lib::open( test_lib_name );
     if( !test_lib_handle )
-        throw std::logic_error( std::string("Fail to load test library ").append( test_lib_name ) );
+        throw std::logic_error( std::string("Fail to load test library: ")
+                                    .append( dyn_lib::error() ) );
 
-    init_func = 
-        reinterpret_cast<init_func_ptr>( ::GetProcAddress( test_lib_handle, init_func_name.c_str() ) );
+    init_func =  dyn_lib::locate_symbol<init_func_ptr>( test_lib_handle, init_func_name );
     
     if( !init_func )
         throw std::logic_error( std::string("Couldn't locate test initilization function ")
-                                .append( init_func_name ) );
-#endif
-
+                                    .append( init_func_name )
+                                    .append( ": " )
+                                    .append( dyn_lib::error() ) );
+   
     return (*init_func)();
 }
 
@@ -71,12 +179,11 @@
         if( P["init"] )
             assign_op( init_func_name, P.get( "init" ), 0 );
 
-        bool res = ::boost::unit_test::unit_test_main( &load_test_lib, argc, argv );
+        int res = ::boost::unit_test::unit_test_main( &load_test_lib, argc, argv );
+
+        ::boost::unit_test::framework::clear();
+        dyn_lib::close( test_lib_handle );
 
-#ifdef USE_WIN32_API
-        if( test_lib_handle )
-            FreeLibrary( test_lib_handle );
-#endif
         return res;
     }
     catch( rt::logic_error const& ex ) {
Modified: trunk/libs/test/tools/console_test_runner/test/test_runner_test.cpp
==============================================================================
--- trunk/libs/test/tools/console_test_runner/test/test_runner_test.cpp	(original)
+++ trunk/libs/test/tools/console_test_runner/test/test_runner_test.cpp	2008-09-18 01:05:03 EDT (Thu, 18 Sep 2008)
@@ -6,7 +6,9 @@
 //  See http://www.boost.org/libs/test for the library home page.
 
 // Boost.Test
+#ifndef BOOST_TEST_DYN_LINK 
 #define BOOST_TEST_DYN_LINK
+#endif
 #include <boost/test/unit_test.hpp>
 using namespace boost::unit_test;
 
@@ -33,7 +35,10 @@
 
 extern "C" {
 
-__declspec(dllexport) bool
+#ifdef BOOST_WINDOWS
+__declspec(dllexport)
+#endif
+ bool
 init_unit_test()
 {
     framework::master_test_suite().p_name.value = "Test runner test";