Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Test on Non Exported Dll Classes
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-02-26 11:31:04


AMDG

Jon Black wrote:
> I have a bunch of dll projects that make up an application. I'd like
> to unit test these projects, but I have two problems:
>
> 1) The classes I'd like to test are in the dll and not all of them are
> exported;
> 2) Boost.Test doesn't have a main entry point, so if I solve 1 by
> packing my tests in the dll, how can I run them?
>
> If there is a better solution to 1, I'd love to hear it. Otherwise,
> how can I solve 2?

As long as you make sure that the dll is loaded before main,
you can use the auto-registration mechanism. This works
with msvc:

// test.cpp (compiled into a dll)
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test1) {
    BOOST_CHECK(true);
}
__declspec(dllexport) int f() {return 0;}

// main.cpp
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
__declspec(dllimport) int f();
static const int i = f();

In Christ,
Steven Watanabe


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