Skip to main content
gamedev.net
🔒 Locked

Boost Test Unit

Started by Xunil_RJ Dec 15, 2005 at 9:20 PM 0 replies 750+ views
Original Post
Xunil_RJ
Xunil_RJ
I made a simple framework to use with boost::test that use the concept of the TUT You just have to change the main.cpp, addin your functions and change one define to tell how many function you have.


// main.h

#include "boost/test/included/unit_test_framework.hpp"

using boost::unit_test_framework::test_suite;


template < unsigned int N> class TestCaller
{
public:
	static void Call ( test_suite * t );
};

template <unsigned int N> void Test (){}

template < unsigned int N> void TestCaller<N>::Call ( test_suite* t )
{
	t->add (  BOOST_TEST_CASE(&(Test<N>)), 0 );
	TestCaller < N + 1 >::Call ( t );
}

test_suite* init_unit_test_suite(int argc, char* argv[])
{
	test_suite* Test = BOOST_TEST_SUITE("Tests");
   
	TestCaller < 0 >:: Call ( Test );

    return (Test );
}






#include "main.h"
// CODE

#define QUANTITY_OF_TESTS 5

template <> void TestCaller<QUANTITY_OF_TESTS>::Call ( test_suite* t ){}

template <> void Test<0> ()
{
	BOOST_CHECK_EQUAL( 1, 0);
}
template <> void Test<1> ()
{
}
template <> void Test<2> ()
{
}
template <> void Test<3> ()
{
}
template <> void Test<4> ()
{
}



As you can see... it's pretty easy to add function to it. Any feedback would be great! :D Just editing to post this link... if anybody want to know what boost::test is: here

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.