[boost::test] running unit tests from DLL with automatic registration facility

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

Ovanes Markarian <om_boost <at> keywallet.com> writes:
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
The right way to construct your test module for now is to follow an example located in boost-trunk\libs\test\tools\console_test_runner\test\test_runner_test.cpp I do agree that it should probably work with regular definition as well. Unix implementation would be nice either ;) I was hoping we'd have Boost.Process/Boost.Extension by now. If I have a time I'll fix it before the release. As for the docs they are pretty much absent for this usage variant. And it doesn't look like I'll have time and endurance to pull it through for this component. Gennadiy
participants (2)
-
Gennadiy Rozental
-
Ovanes Markarian