unit_test_example_03.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // this test case is automatically registered
  12. BOOST_AUTO_TEST_CASE( force_division_by_zero )
  13. {
  14. BOOST_CHECK( false );
  15. // unit test framework can catch operating system signals
  16. BOOST_TEST_CHECKPOINT("About to force division by zero!");
  17. int i = 1, j = 0;
  18. // reports 'unknown location(0): fatal error in "force_division_by_zero": integer divide by zero'
  19. i = i / j;
  20. }
  21. //____________________________________________________________________________//
  22. // this test case will have tobe registered manually
  23. void infinite_loop()
  24. {
  25. // unit test framework can break infinite loops by timeout
  26. #ifdef __unix // don't have timeout on other platforms
  27. BOOST_TEST_CHECKPOINT("About to enter an infinite loop!");
  28. while(1);
  29. #else
  30. BOOST_TEST_MESSAGE( "Timeout support is not implemented on your platform" );
  31. #endif
  32. }
  33. //____________________________________________________________________________//
  34. test_suite*
  35. init_unit_test_suite( int , char* [] )
  36. {
  37. framework::master_test_suite().p_name.value = "Unit test example 03";
  38. // with explicit registration we could specify a test case timeout
  39. framework::master_test_suite().add( BOOST_TEST_CASE( &infinite_loop ), 0, /* timeout */ 2 );
  40. return 0;
  41. }
  42. //____________________________________________________________________________//
  43. // EOF