1 | //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. |
---|---|
2 | |
3 | //Distributed under the Boost Software License, Version 1.0. (See accompanying |
4 | //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
5 | |
6 | #include <boost/exception/to_string_stub.hpp> |
7 | #include <boost/detail/lightweight_test.hpp> |
8 | #include <iostream> |
9 | |
10 | namespace |
11 | n1 |
12 | { |
13 | class |
14 | c1 |
15 | { |
16 | }; |
17 | |
18 | std::string |
19 | to_string( c1 const & ) |
20 | { |
21 | return "c1"; |
22 | } |
23 | } |
24 | |
25 | namespace |
26 | n2 |
27 | { |
28 | class |
29 | c2 |
30 | { |
31 | }; |
32 | |
33 | std::ostream & |
34 | operator<<( std::ostream & s, c2 const & ) |
35 | { |
36 | s << "c2"; |
37 | return s; |
38 | } |
39 | } |
40 | |
41 | namespace |
42 | n3 |
43 | { |
44 | class |
45 | c3 |
46 | { |
47 | }; |
48 | |
49 | std::ostream & |
50 | operator<<( std::ostream & s, c3 const & ) |
51 | { |
52 | s << "bad"; |
53 | return s; |
54 | } |
55 | |
56 | std::string |
57 | to_string( c3 const & ) |
58 | { |
59 | return "c3"; |
60 | } |
61 | } |
62 | |
63 | namespace |
64 | boost |
65 | { |
66 | class |
67 | to_string_tester |
68 | { |
69 | }; |
70 | } |
71 | |
72 | template <class T> |
73 | struct |
74 | my_stub |
75 | { |
76 | std::string |
77 | operator()( T const & ) |
78 | { |
79 | return "stub"; |
80 | } |
81 | }; |
82 | |
83 | int |
84 | main() |
85 | { |
86 | using namespace boost; |
87 | BOOST_TEST( to_string(42)=="42"); |
88 | BOOST_TEST( to_string(n1::c1())=="c1"); |
89 | BOOST_TEST( to_string(n2::c2())=="c2"); |
90 | BOOST_TEST( to_string(n3::c3())=="c3"); |
91 | BOOST_TEST( to_string_stub(42)=="42"); |
92 | BOOST_TEST( to_string_stub(n1::c1())=="c1"); |
93 | BOOST_TEST( to_string_stub(n2::c2())=="c2"); |
94 | BOOST_TEST( to_string_stub(n3::c3())=="c3"); |
95 | BOOST_TEST( to_string_stub(to_string_tester(),my_stub<to_string_tester>())=="stub"); |
96 | BOOST_TEST( !to_string_stub(to_string_tester()).empty() ); |
97 | return boost::report_errors(); |
98 | } |
99 |