]>
Commit | Line | Data |
---|---|---|
1 | // | |
2 | // Test for lightweight_test.hpp | |
3 | // | |
4 | // Copyright (c) 2014 Peter Dimov | |
5 | // | |
6 | // Distributed under the Boost Software License, Version 1.0. | |
7 | // See accompanying file LICENSE_1_0.txt or copy at | |
8 | // http://www.boost.org/LICENSE_1_0.txt | |
9 | // | |
10 | ||
11 | #include <vector> | |
12 | #include <boost/detail/lightweight_test.hpp> | |
13 | ||
14 | struct X | |
15 | { | |
16 | }; | |
17 | ||
18 | #if !defined( BOOST_NO_EXCEPTIONS ) | |
19 | # define LWT_THROW( x ) throw x | |
20 | #else | |
21 | # define LWT_THROW( x ) ((void)(x)) | |
22 | #endif | |
23 | ||
24 | void f( bool x ) | |
25 | { | |
26 | if( x ) | |
27 | { | |
28 | LWT_THROW( X() ); | |
29 | } | |
30 | else | |
31 | { | |
32 | LWT_THROW( 5 ); | |
33 | } | |
34 | } | |
35 | ||
36 | int main() | |
37 | { | |
38 | int x = 0; | |
39 | ||
40 | // BOOST_TEST | |
41 | ||
42 | BOOST_TEST( x == 0 ); | |
43 | BOOST_TEST( ++x == 1 ); | |
44 | BOOST_TEST( x++ == 1 ); | |
45 | BOOST_TEST( x == 2? true: false ); | |
46 | BOOST_TEST( x == 2? &x: 0 ); | |
47 | ||
48 | // BOOST_TEST_NOT | |
49 | ||
50 | BOOST_TEST_NOT( x == 1 ); | |
51 | BOOST_TEST_NOT( ++x == 2 ); | |
52 | BOOST_TEST_NOT( x++ == 2 ); | |
53 | BOOST_TEST_NOT( --x == 2 ); | |
54 | BOOST_TEST_NOT( x-- == 2 ); | |
55 | BOOST_TEST_NOT( x == 2? false: true ); | |
56 | BOOST_TEST_NOT( x == 2? 0: &x ); | |
57 | ||
58 | // BOOST_TEST_EQ | |
59 | ||
60 | BOOST_TEST_EQ( x, 2 ); | |
61 | BOOST_TEST_EQ( ++x, 3 ); | |
62 | BOOST_TEST_EQ( x++, 3 ); | |
63 | ||
64 | int y = 4; | |
65 | ||
66 | BOOST_TEST_EQ( ++x, ++y ); | |
67 | BOOST_TEST_EQ( x++, y++ ); | |
68 | BOOST_TEST_CSTR_EQ("xabc"+1, "yabc"+1); // equal cstrings, different addresses | |
69 | BOOST_TEST_EQ( &y, &y ); | |
70 | ||
71 | // BOOST_TEST_NE | |
72 | ||
73 | BOOST_TEST_NE( ++x, y ); | |
74 | BOOST_TEST_NE( &x, &y ); | |
75 | BOOST_TEST_NE("xabc"+1, "yabc"+1); // equal cstrings, different addresses | |
76 | BOOST_TEST_CSTR_NE("x", "y"); | |
77 | ||
78 | // BOOST_TEST_ALL_EQ | |
79 | { | |
80 | std::vector<int> xarray; | |
81 | xarray.push_back(1); | |
82 | xarray.push_back(2); | |
83 | std::vector<int> yarray(xarray); | |
84 | BOOST_TEST_ALL_EQ(xarray.begin(), xarray.end(), yarray.begin(), yarray.end()); | |
85 | } | |
86 | ||
87 | // BOOST_TEST_THROWS | |
88 | ||
89 | BOOST_TEST_THROWS( throw X(), X ); | |
90 | BOOST_TEST_THROWS( throw 1, int ); | |
91 | ||
92 | BOOST_TEST_THROWS( f(true), X ); | |
93 | BOOST_TEST_THROWS( f(false), int ); | |
94 | ||
95 | return boost::report_errors(); | |
96 | } |