File: lightweight_test_test.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (116 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Test for lightweight_test.hpp
//
// Copyright (c) 2014 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//

#if defined(_MSC_VER)
# pragma warning( disable: 4702 ) // unreachable code
# pragma warning( disable: 4530 ) // unwind without /EHsc from <ostream>
# pragma warning( disable: 4577 ) // noexcept without /EHsc from <exception>
#endif

#include <boost/core/lightweight_test.hpp>
#include <vector>

struct X
{
};

#if !defined( BOOST_NO_EXCEPTIONS )
# define LWT_THROW( x ) throw x
#else
# define LWT_THROW( x ) ((void)(x))
#endif

void f( bool x )
{
    if( x )
    {
        LWT_THROW( X() );
    }
    else
    {
        LWT_THROW( 5 );
    }
}

#if defined(__GNUC__)
# pragma GCC diagnostic ignored "-Waddress"
#endif

#if defined(__clang__) && defined(__has_warning)
# if __has_warning( "-Wstring-plus-int" )
#  pragma clang diagnostic ignored "-Wstring-plus-int"
# endif
#endif

int main()
{
    int x = 0;

    // BOOST_TEST

    BOOST_TEST( x == 0 );
    BOOST_TEST( ++x == 1 );
    BOOST_TEST( x++ == 1 );
    BOOST_TEST( x == 2? true: false );
    BOOST_TEST( x == 2? &x: 0 );
    
    // BOOST_TEST_NOT
    
    BOOST_TEST_NOT( x == 1 );
    BOOST_TEST_NOT( ++x == 2 );
    BOOST_TEST_NOT( x++ == 2 );
    BOOST_TEST_NOT( --x == 2 );
    BOOST_TEST_NOT( x-- == 2 );
    BOOST_TEST_NOT( x == 2? false: true );
    BOOST_TEST_NOT( x == 2? 0: &x );

    // BOOST_TEST_EQ

    BOOST_TEST_EQ( x, 2 );
    BOOST_TEST_EQ( ++x, 3 );
    BOOST_TEST_EQ( x++, 3 );

    int y = 4;

    BOOST_TEST_EQ( ++x, ++y );
    BOOST_TEST_EQ( x++, y++ );
    BOOST_TEST_CSTR_EQ("xabc"+1, "yabc"+1); // equal cstrings, different addresses
    BOOST_TEST_EQ( &y, &y );

    // BOOST_TEST_NE

    BOOST_TEST_NE( ++x, y );
    BOOST_TEST_NE( &x, &y );
    BOOST_TEST_NE("xabc"+1, "yabc"+1); // equal cstrings, different addresses
    BOOST_TEST_CSTR_NE("x", "y");

    // BOOST_TEST_ALL_EQ
    {
        std::vector<int> xarray;
        xarray.push_back(1);
        xarray.push_back(2);
        std::vector<int> yarray(xarray);
        BOOST_TEST_ALL_EQ(xarray.begin(), xarray.end(), yarray.begin(), yarray.end());
    }

    // BOOST_TEST_THROWS

    BOOST_TEST_THROWS( throw X(), X );
    BOOST_TEST_THROWS( throw 1, int );

    BOOST_TEST_THROWS( f(true), X );
    BOOST_TEST_THROWS( f(false), int );

    // BOOST_TEST_NO_THROW

    BOOST_TEST_NO_THROW(++y);

    return boost::report_errors();
}