Boost logo

Boost Users :

From: Tomislav Adamic (tomislav.adamic_at_[hidden])
Date: 2008-03-11 10:47:56


Code below doesn't compile. Workaround is provided also but is not satisfactory

-------------------------------------------------------------------------------

#include <boost/test/unit_test.hpp>
#include <boost/shared_ptr.hpp>

using namespace boost::unit_test;

class ToBeTested {
public:
    ToBeTested() {}

    int feature1() const { return 1; }
    int feature2() const { return 2; }
};

class ComplexTest {
public:
    ComplexTest() {}

    void test1() const {
        ToBeTested t;
        BOOST_CHECK (t.feature1() == 1);
    }

    void test2() {
        ToBeTested t;
        BOOST_CHECK (t.feature2() == 2);
    }
};

class TestSuite : public boost::unit_test::test_suite {
public:
    typedef boost::shared_ptr<ComplexTest> ComplexTestPtr;

    TestSuite () : boost::unit_test::test_suite ("test suite") {
        ComplexTestPtr instance (new ComplexTest);

        test_case* t1 = BOOST_CLASS_TEST_CASE (&ComplexTest::test1, instance);
        test_case* t2 = BOOST_CLASS_TEST_CASE (&ComplexTest::test2, instance);

        add (t1); add(t2);
    }
};

boost::unit_test::test_suite* init_unit_test_suite( int argc, char * argv[] )
{
    framework::master_test_suite().add(new TestSuite);

    return 0;
}
-------------------------------------------------------------------------------

MSVC 2005 gives following compile time message:

test_case* t1 = BOOST_CLASS_TEST_CASE (&ComplexTest::test1, instance);
: 'boost::unit_test::make_test_case' : function does not take 3 arguments

Problem:
ComplexTest::test1() is const method. BOOST_CLASS_TEST_CASE refuses to work
properly
with const methods. ComplexTest::test2() is not const and works as expected.

Workaround
Methods from test classes that will be used by BOOST_CLASS_TEST_CASE should
not be
const.

Information applies to:
                boost v1.34.1
                WinXP SP2
                Microsoft Visual Studio 2005 SP1
                


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