Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-05-28 13:31:50


Hello Gennadiy,

using boost 1.35 & console runner and MSVC 2005 we did the following test:

   FunctionalityDLL
            ^
            |
      UnitTestDLL
            ^
            |
ConsoleTestRunner.EXE (as distributed in the example directory)

UnitTest.DLL
had the following defines:

#ifndef BOOST_TEST_DYN_LINK
# define BOOST_TEST_DYN_LINK
#endif

#ifndef BOOST_TEST_MODULE
# define BOOST_TEST_MODULE example
#endif

#include <boost/test/unit_test.hpp>

We spent some time to figure out how to cause ConsoleTestRunner.exe to find
the init_unit_test function. Finally we end up looking to preprocessed code:
There we found the function:

bool init_unit_test()
{
    using namespace ::boost::unit_test;
    assign_op( framework::master_test_suite().p_name.value,
boost::unit_test::const_string( "example", sizeof( "example" ) - 1 ).trim(
"\"" ), 0 );
    return true;
}

Only after taking the function over to the cpp module (removing
BOOST_TEST_MODULE define) adding the DLL export statement and adding the
C-Linkage ConsoleTestRunner was able to find the address of this function.

So the compilation unit looked like:

#ifndef BOOST_TEST_DYN_LINK
# define BOOST_TEST_DYN_LINK
#endif

#include <boost/test/unit_test.hpp>

#include "TestsDLL.h"

extern "C"
__declspec(dllexport) bool init_unit_test()
{
    using namespace ::boost::unit_test;
    assign_op( framework::master_test_suite().p_name.value,
boost::unit_test::const_string( "example", sizeof( "example" ) - 1 ).trim(
"\"" ), 0 );
    return true;
}

BOOST_AUTO_TEST_SUITE( FunctionalityDLLTest )

BOOST_AUTO_TEST_CASE( test1 )
{
    BOOST_WARN( sizeof(int) < 4 );
}

BOOST_AUTO_TEST_CASE( test2 )
{
    BOOST_REQUIRE_EQUAL( 1, 2 );
    BOOST_FAIL( "Should never reach this line" );
}

BOOST_AUTO_TEST_SUITE_END()

Only after these modifications we were able to compile and run unit tests.
Is there any chance to either update the docs with this example so that it
becomes a sort of guarantee how it might work, or let the combination of
BOOST_TEST_MODULE and BOOST_TEST_DYN_LINK generate the right linkage
specification and export the symbol, otherwise this symbol was not found
with GetProcAddress.

With Kind Regards,
Ovanes



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net