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 #if defined(_MSC_VER)
12 # pragma warning( disable: 4702 ) // unreachable code
13 # pragma warning( disable: 4530 ) // unwind without /EHsc from <ostream>
14 # pragma warning( disable: 4577 ) // noexcept without /EHsc from <exception>
15 #endif
16
17 #include <boost/core/lightweight_test.hpp>
18 #include <vector>
19
20 struct X
21 {
22 };
23
24 #if !defined( BOOST_NO_EXCEPTIONS )
25 # define LWT_THROW( x ) throw x
26 #else
27 # define LWT_THROW( x ) ((void)(x))
28 #endif
29
f(bool x)30 void f( bool x )
31 {
32 if( x )
33 {
34 LWT_THROW( X() );
35 }
36 else
37 {
38 LWT_THROW( 5 );
39 }
40 }
41
42 #if defined(__GNUC__)
43 # pragma GCC diagnostic ignored "-Waddress"
44 #endif
45
46 #if defined(__clang__) && defined(__has_warning)
47 # if __has_warning( "-Wstring-plus-int" )
48 # pragma clang diagnostic ignored "-Wstring-plus-int"
49 # endif
50 #endif
51
main()52 int main()
53 {
54 int x = 0;
55
56 // BOOST_TEST
57
58 BOOST_TEST( x == 0 );
59 BOOST_TEST( ++x == 1 );
60 BOOST_TEST( x++ == 1 );
61 BOOST_TEST( x == 2? true: false );
62 BOOST_TEST( x == 2? &x: 0 );
63
64 // BOOST_TEST_NOT
65
66 BOOST_TEST_NOT( x == 1 );
67 BOOST_TEST_NOT( ++x == 2 );
68 BOOST_TEST_NOT( x++ == 2 );
69 BOOST_TEST_NOT( --x == 2 );
70 BOOST_TEST_NOT( x-- == 2 );
71 BOOST_TEST_NOT( x == 2? false: true );
72 BOOST_TEST_NOT( x == 2? 0: &x );
73
74 // BOOST_TEST_EQ
75
76 BOOST_TEST_EQ( x, 2 );
77 BOOST_TEST_EQ( ++x, 3 );
78 BOOST_TEST_EQ( x++, 3 );
79
80 int y = 4;
81
82 BOOST_TEST_EQ( ++x, ++y );
83 BOOST_TEST_EQ( x++, y++ );
84 BOOST_TEST_CSTR_EQ("xabc"+1, "yabc"+1); // equal cstrings, different addresses
85 BOOST_TEST_EQ( &y, &y );
86
87 // BOOST_TEST_NE
88
89 BOOST_TEST_NE( ++x, y );
90 BOOST_TEST_NE( &x, &y );
91 BOOST_TEST_NE("xabc"+1, "yabc"+1); // equal cstrings, different addresses
92 BOOST_TEST_CSTR_NE("x", "y");
93
94 // BOOST_TEST_ALL_EQ
95 {
96 std::vector<int> xarray;
97 xarray.push_back(1);
98 xarray.push_back(2);
99 std::vector<int> yarray(xarray);
100 BOOST_TEST_ALL_EQ(xarray.begin(), xarray.end(), yarray.begin(), yarray.end());
101 }
102
103 // BOOST_TEST_THROWS
104
105 BOOST_TEST_THROWS( throw X(), X );
106 BOOST_TEST_THROWS( throw 1, int );
107
108 BOOST_TEST_THROWS( f(true), X );
109 BOOST_TEST_THROWS( f(false), int );
110
111 // BOOST_TEST_NO_THROW
112
113 BOOST_TEST_NO_THROW(++y);
114
115 return boost::report_errors();
116 }
117