Line | |
---|
1 | // (C) Copyright Gennadiy Rozental 2001-2005. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. |
---|
3 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
4 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | // See http://www.boost.org/libs/test for the library home page. |
---|
7 | |
---|
8 | // Boost.Test |
---|
9 | #include <boost/test/test_tools.hpp> |
---|
10 | |
---|
11 | int add( int i, int j ) { return i+j; } |
---|
12 | |
---|
13 | int test_main( int, char* [] ) // note the name! |
---|
14 | { |
---|
15 | // six ways to detect and report the same error: |
---|
16 | BOOST_CHECK( add(2,2) == 4 ); // #1 continues on error |
---|
17 | |
---|
18 | BOOST_REQUIRE( add(2,2) == 4 ); // #2 throws on error |
---|
19 | |
---|
20 | if ( add(2,2) != 4 ) |
---|
21 | BOOST_ERROR( "Ouch..."); // #3 continues on error |
---|
22 | |
---|
23 | if ( add(2,2) != 4 ) |
---|
24 | BOOST_FAIL( "Ouch..." ); // #4 throws on error |
---|
25 | |
---|
26 | if ( add(2,2) != 4 ) |
---|
27 | throw "Oops..."; // #5 throws on error |
---|
28 | |
---|
29 | return add(2,2) == 4 ? 0 : 1; // #6 returns error code |
---|
30 | } |
---|
31 | |
---|
32 | // EOF |
---|
Note: See
TracBrowser
for help on using the repository browser.