Last change
on this file since 35 was
29,
checked in by landauf, 16 years ago
|
updated boost from 1_33_1 to 1_34_1
|
File size:
1.8 KB
|
Line | |
---|
1 | // |
---|
2 | // assert_test.cpp - a test for boost/assert.hpp |
---|
3 | // |
---|
4 | // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. |
---|
5 | // |
---|
6 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
7 | // accompanying file LICENSE_1_0.txt or copy at |
---|
8 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | // |
---|
10 | |
---|
11 | #include <boost/detail/lightweight_test.hpp> |
---|
12 | |
---|
13 | #include <boost/assert.hpp> |
---|
14 | |
---|
15 | void test_default() |
---|
16 | { |
---|
17 | int x = 1; |
---|
18 | |
---|
19 | BOOST_ASSERT(1); |
---|
20 | BOOST_ASSERT(x); |
---|
21 | BOOST_ASSERT(x == 1); |
---|
22 | BOOST_ASSERT(&x); |
---|
23 | } |
---|
24 | |
---|
25 | #define BOOST_DISABLE_ASSERTS |
---|
26 | #include <boost/assert.hpp> |
---|
27 | |
---|
28 | void test_disabled() |
---|
29 | { |
---|
30 | int x = 1; |
---|
31 | |
---|
32 | BOOST_ASSERT(1); |
---|
33 | BOOST_ASSERT(x); |
---|
34 | BOOST_ASSERT(x == 1); |
---|
35 | BOOST_ASSERT(&x); |
---|
36 | |
---|
37 | BOOST_ASSERT(0); |
---|
38 | BOOST_ASSERT(!x); |
---|
39 | BOOST_ASSERT(x == 0); |
---|
40 | |
---|
41 | void * p = 0; |
---|
42 | |
---|
43 | BOOST_ASSERT(p); |
---|
44 | |
---|
45 | // supress warnings |
---|
46 | p = &x; |
---|
47 | p = &p; |
---|
48 | } |
---|
49 | |
---|
50 | #undef BOOST_DISABLE_ASSERTS |
---|
51 | |
---|
52 | #define BOOST_ENABLE_ASSERT_HANDLER |
---|
53 | #include <boost/assert.hpp> |
---|
54 | #include <boost/config.hpp> |
---|
55 | #include <cstdio> |
---|
56 | |
---|
57 | int handler_invoked = 0; |
---|
58 | |
---|
59 | void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) |
---|
60 | { |
---|
61 | #if !defined(BOOST_NO_STDC_NAMESPACE) |
---|
62 | using std::printf; |
---|
63 | #endif |
---|
64 | |
---|
65 | printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); |
---|
66 | ++handler_invoked; |
---|
67 | } |
---|
68 | |
---|
69 | struct X |
---|
70 | { |
---|
71 | static void f() |
---|
72 | { |
---|
73 | BOOST_ASSERT(0); |
---|
74 | } |
---|
75 | }; |
---|
76 | |
---|
77 | void test_handler() |
---|
78 | { |
---|
79 | int x = 1; |
---|
80 | |
---|
81 | BOOST_ASSERT(1); |
---|
82 | BOOST_ASSERT(x); |
---|
83 | BOOST_ASSERT(x == 1); |
---|
84 | BOOST_ASSERT(&x); |
---|
85 | |
---|
86 | BOOST_ASSERT(0); |
---|
87 | BOOST_ASSERT(!x); |
---|
88 | BOOST_ASSERT(x == 0); |
---|
89 | |
---|
90 | void * p = 0; |
---|
91 | |
---|
92 | BOOST_ASSERT(p); |
---|
93 | |
---|
94 | X::f(); |
---|
95 | |
---|
96 | BOOST_ASSERT(handler_invoked == 5); |
---|
97 | BOOST_TEST(handler_invoked == 5); |
---|
98 | } |
---|
99 | |
---|
100 | #undef BOOST_ENABLE_ASSERT_HANDLER |
---|
101 | |
---|
102 | int main() |
---|
103 | { |
---|
104 | test_default(); |
---|
105 | test_disabled(); |
---|
106 | test_handler(); |
---|
107 | |
---|
108 | return boost::report_errors(); |
---|
109 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.