unit_test_example_11.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // (C) Copyright Gennadiy Rozental 2002-2014.
  2. // (C) Copyright Gennadiy Rozental & Ullrich Koethe 2001.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org/libs/test for the library home page.
  7. // Boost.Test
  8. #include <boost/test/unit_test.hpp>
  9. #include <boost/test/parameterized_test.hpp>
  10. using namespace boost::unit_test;
  11. // STL
  12. #include <vector>
  13. #include <string>
  14. #define LOG_FATAL_ERROR( M ) \
  15. BOOST_TEST_LOG_ENTRY( ::boost::unit_test::log_fatal_errors ) \
  16. << (::boost::unit_test::lazy_ostream::instance() << M)
  17. //____________________________________________________________________________//
  18. // this free function is invoked with all parameters specified in a list
  19. void check_string( std::string const& s )
  20. {
  21. // reports 'error in "check_string": test s.substr( 0, 3 ) == "hdr" failed [actual_value != hdr]'
  22. BOOST_CHECK_EQUAL( s.substr( 0, 3 ), "hdr" );
  23. }
  24. //____________________________________________________________________________//
  25. test_suite*
  26. init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) {
  27. framework::master_test_suite().p_name.value = "Unit test example 11";
  28. LOG_FATAL_ERROR( "something happened" );
  29. // parameters have no requirements to stay alive beyond the next statement
  30. std::string const params[] = { "hdr1 ", "hdr2", "3 " };
  31. framework::master_test_suite().add(
  32. BOOST_PARAM_TEST_CASE( &check_string, (std::string const*)params, params+3 ) );
  33. return 0;
  34. }
  35. //____________________________________________________________________________//
  36. // EOF