File: test_tools_example.cpp

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (19 lines) | stat: -rw-r--r-- 767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//  boost test_main example program  ----------------------------------------//

#define BOOST_INCLUDE_MAIN  // for testing, include rather than link
#include <boost/test/test_tools.hpp>

int add( int i, int j ) { return i+j; }

int test_main( int, char *[] )  // note the name!
{
  // six ways to detect and report the same error:
  BOOST_TEST( add(2,2) == 4 );           // #1 continues on error
  BOOST_CRITICAL_TEST( add(2,2) == 4 );  // #2 throws on error
  if ( add(2,2) != 4 )
    BOOST_ERROR( "Ouch...");             // #3 continues on error
  if ( add(2,2) != 4 )
    BOOST_CRITICAL_ERROR( "Ouch..." );   // #4 throws on error
  if ( add(2,2) != 4 ) throw "Oops...";  // #5 throws on error
  return add(2,2) == 4 ? 0 : 1;          // #6 returns error code
}