[Boost.Test]Possible BOOST_CLASS_TEST_CASE bug
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
Tomislav Adamic <tomislav.adamic <at> gmail.com> writes:
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.
Yes. This looks like boost.test issue. I'll fix it. You'll have to stick with non-const test case methods for now. What the big deal BTW? Gennadiy
Gennadiy Rozental wrote:
Tomislav Adamic <tomislav.adamic <at> gmail.com> writes:
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.
Yes. This looks like boost.test issue. I'll fix it. You'll have to stick with non-const test case methods for now. What the big deal BTW?
Gennadiy
It is not a big deal, these are only tests... On the other hand, I am forced to change constnes of my method only to be able to use it in Boost.Test; not because my method actually needs to become non-const because of internal class matters... This is not good C++, don't you agree? Anyway, like I said, I can live with that... BTW, sorry if this has been posted before...
participants (2)
-
Gennadiy Rozental
-
Tomislav Adamic