unit_test_example_07.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // (C) Copyright Gennadiy Rozental 2005-2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. // Boost.Test
  7. #define BOOST_TEST_MODULE Unit_test_example_07
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/mpl/list.hpp>
  10. //____________________________________________________________________________//
  11. struct F {
  12. F() : i( 9 ) { BOOST_TEST_MESSAGE( "setup fixture" ); }
  13. ~F() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
  14. int i;
  15. };
  16. //____________________________________________________________________________//
  17. BOOST_FIXTURE_TEST_SUITE( s, F )
  18. typedef boost::mpl::list<char,int const,float,const double> test_types;
  19. // this test case template produce a separate test case for each type listed in test_types
  20. // each produced test case uses struct F as a fixture
  21. BOOST_AUTO_TEST_CASE_TEMPLATE( my_test, T, test_types )
  22. {
  23. T t = static_cast<T>(i);
  24. // usually it's a bad idea to use BOOST_CHECK_EQUAL for checking equality values of
  25. // floating point types. This check may or may not produce an error report
  26. BOOST_TEST( (t*t+t)/10 == 9 );
  27. }
  28. BOOST_AUTO_TEST_SUITE_END()
  29. //____________________________________________________________________________//
  30. // EOF