unit_test_example_02.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. using namespace boost::unit_test;
  10. //____________________________________________________________________________//
  11. // you could easily implement test cases as a free functions
  12. // this test case will need to be explecetely registered in test tree
  13. void free_test_function()
  14. {
  15. // reports 'error in "free_test_function": test 2 == 1 failed'
  16. BOOST_CHECK(2 == 1); // non-critical test => continue after failure
  17. // reports 'unknown location(0): fatal error in "free_test_function": memory access violation
  18. // d:\source code\boost\libs\test\example\unit_test_example_02.cpp(25): last checkpoint'
  19. int* p = (int*)0x01;
  20. BOOST_CHECK( *p == 0 );
  21. }
  22. //____________________________________________________________________________//
  23. test_suite*
  24. init_unit_test_suite( int, char* [] ) {
  25. framework::master_test_suite().p_name.value = "Unit test example 02";
  26. // register the test case in test tree and specify number of expected failures so
  27. // this example will pass at runtime. We expect 2 errors: one from failed check and
  28. // one from memory acces violation
  29. framework::master_test_suite().add( BOOST_TEST_CASE( &free_test_function ), 2 );
  30. return 0;
  31. }
  32. //____________________________________________________________________________//
  33. // EOF