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