Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/testing/test/BoostTest.cc @ 9020

Last change on this file since 9020 was 9020, checked in by landauf, 12 years ago

sample tests with boost test

File size: 915 bytes
Line 
1#include <boost/test/minimal.hpp>
2
3//____________________________________________________________________________//
4
5int add( int i, int j ) { return i+j; }
6
7//____________________________________________________________________________//
8
9int test_main( int, char *[] )             // note the name!
10{
11    // six ways to detect and report the same error:
12    BOOST_CHECK( add( 2,2 ) == 4 );        // #1 continues on error
13    BOOST_REQUIRE( add( 2,2 ) == 4 );      // #2 throws on error
14    if( add( 2,2 ) != 4 )
15        BOOST_ERROR( "Ouch..." );          // #3 continues on error
16    if( add( 2,2 ) != 4 )
17        BOOST_FAIL( "Ouch..." );           // #4 throws on error
18    if( add( 2,2 ) != 4 ) throw "Oops..."; // #5 throws on error
19
20    return add( 2, 2 ) == 4 ? 0 : 1;       // #6 returns error code
21}
22
23//____________________________________________________________________________//
Note: See TracBrowser for help on using the repository browser.