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 7 // See http://www.boost.org/libs/test for the library home page. 8 9 // Boost.Test 10 #include <boost/test/unit_test.hpp> 11 using namespace boost::unit_test; 12 13 //____________________________________________________________________________// 14 15 // this test case is automatically registered BOOST_AUTO_TEST_CASE(force_division_by_zero)16BOOST_AUTO_TEST_CASE( force_division_by_zero ) 17 { 18 BOOST_CHECK( false ); 19 20 // unit test framework can catch operating system signals 21 BOOST_TEST_CHECKPOINT("About to force division by zero!"); 22 int i = 1, j = 0; 23 24 // reports 'unknown location(0): fatal error in "force_division_by_zero": integer divide by zero' 25 i = i / j; 26 } 27 28 //____________________________________________________________________________// 29 30 // this test case will have tobe registered manually infinite_loop()31void infinite_loop() 32 { 33 // unit test framework can break infinite loops by timeout 34 #ifdef __unix // don't have timeout on other platforms 35 BOOST_TEST_CHECKPOINT("About to enter an infinite loop!"); 36 while(1); 37 #else 38 BOOST_TEST_MESSAGE( "Timeout support is not implemented on your platform" ); 39 #endif 40 } 41 42 //____________________________________________________________________________// 43 44 test_suite* init_unit_test_suite(int,char * [])45init_unit_test_suite( int , char* [] ) 46 { 47 framework::master_test_suite().p_name.value = "Unit test example 03"; 48 49 // with explicit registration we could specify a test case timeout 50 framework::master_test_suite().add( BOOST_TEST_CASE( &infinite_loop ), 0, /* timeout */ 2 ); 51 52 return 0; 53 } 54 55 //____________________________________________________________________________// 56 57 // EOF 58