]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/xpressive/test/test_cycles.cpp
1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // defining this causes regex_impl objects to be counted, allowing us to detect
10 #define BOOST_XPRESSIVE_DEBUG_CYCLE_TEST
13 #include <boost/test/unit_test.hpp>
14 #include <boost/xpressive/xpressive.hpp>
16 #if defined(_MSC_VER) && defined(_DEBUG)
17 # define _CRTDBG_MAP_ALLOC
21 using namespace boost::unit_test
;
22 using namespace boost::xpressive
;
24 ///////////////////////////////////////////////////////////////////////////////
26 // regexes referred to by other regexes are kept alive via reference counting.
27 // but cycles are handled naturally. the following works as expected and doesn't leak.
34 a
= 'a' >> !by_ref(b
);
35 //std::cout << a << std::endl;
36 //std::cout << b << std::endl;
37 //std::cout << c << std::endl;
43 b
= epsilon
>> by_ref(c
);
44 //std::cout << a << std::endl;
45 //std::cout << b << std::endl;
46 //std::cout << c << std::endl;
48 c
= epsilon
>> by_ref(a
);
49 //std::cout << a << std::endl;
50 //std::cout << b << std::endl;
51 //std::cout << c << std::endl;
55 std::string
const s("aaa");
57 if(!regex_match(s
, m
, v
))
59 BOOST_ERROR("cycle test 1 failed");
63 if(0 != detail::regex_impl
<std::string::const_iterator
>::instances
)
65 BOOST_ERROR("leaks detected (cycle test 1)");
66 detail::regex_impl
<std::string::const_iterator
>::instances
= 0;
73 b
= epsilon
>> by_ref(c
);
74 a
= 'a' >> !by_ref(b
);
75 c
= epsilon
>> by_ref(a
);
77 //std::cout << a << std::endl;
78 //std::cout << b << std::endl;
79 //std::cout << c << std::endl;
83 std::string
const s("aaa");
85 if(!regex_match(s
, m
, v
))
87 BOOST_ERROR("cycle test 2 failed");
91 if(0 != detail::regex_impl
<std::string::const_iterator
>::instances
)
93 BOOST_ERROR("leaks detected (cycle test 2)");
94 detail::regex_impl
<std::string::const_iterator
>::instances
= 0;
102 b
= epsilon
>> by_ref(c
);
103 c
= epsilon
>> by_ref(a
);
104 a
= 'a' >> !by_ref(b
);
106 //std::cout << a << std::endl;
107 //std::cout << b << std::endl;
108 //std::cout << c << std::endl;
112 std::string
const s("aaa");
114 if(!regex_match(s
, m
, v
))
116 BOOST_ERROR("cycle test 3 failed");
120 if(0 != detail::regex_impl
<std::string::const_iterator
>::instances
)
122 BOOST_ERROR("leaks detected (cycle test 3)");
123 detail::regex_impl
<std::string::const_iterator
>::instances
= 0;
130 c
= epsilon
>> by_ref(a
);
131 b
= epsilon
>> by_ref(c
);
132 a
= 'a' >> !by_ref(b
);
134 //std::cout << a << std::endl;
135 //std::cout << b << std::endl;
136 //std::cout << c << std::endl;
140 std::string
const s("aaa");
142 if(!regex_match(s
, m
, v
))
144 BOOST_ERROR("cycle test 4 failed");
148 if(0 != detail::regex_impl
<std::string::const_iterator
>::instances
)
150 BOOST_ERROR("leaks detected (cycle test 4)");
151 detail::regex_impl
<std::string::const_iterator
>::instances
= 0;
158 a
= 'a' >> !by_ref(b
);
159 b
= epsilon
>> by_ref(c
);
160 c
= epsilon
>> by_ref(a
);
163 d
= epsilon
>> by_ref(e
);
168 //std::cout << a << std::endl;
169 //std::cout << b << std::endl;
170 //std::cout << c << std::endl;
171 //std::cout << e << std::endl;
173 e
= 'a' >> by_ref(c
);
175 //std::cout << "-new loop!\n";
176 //std::cout << a << std::endl;
177 //std::cout << b << std::endl;
178 //std::cout << c << std::endl;
179 //std::cout << e << std::endl;
183 //std::cout << v << std::endl;
186 std::string
const s("aaa");
188 if(regex_match(s
, m
, v
)) // OK, this shouldn't match
190 BOOST_ERROR("cycle test 5 failed");
194 if(0 != detail::regex_impl
<std::string::const_iterator
>::instances
)
196 BOOST_ERROR("leaks detected (cycle test 5)");
197 detail::regex_impl
<std::string::const_iterator
>::instances
= 0;
201 ///////////////////////////////////////////////////////////////////////////////
202 // init_unit_test_suite
204 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
206 test_suite
*test
= BOOST_TEST_SUITE("test_cycles");
207 test
->add(BOOST_TEST_CASE(&test_main
));
211 ///////////////////////////////////////////////////////////////////////////////
216 const struct debug_init
221 // Send warnings, errors and asserts to STDERR
222 _CrtSetReportMode(_CRT_WARN
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
223 _CrtSetReportFile(_CRT_WARN
, _CRTDBG_FILE_STDERR
);
224 _CrtSetReportMode(_CRT_ERROR
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
225 _CrtSetReportFile(_CRT_ERROR
, _CRTDBG_FILE_STDERR
);
226 _CrtSetReportMode(_CRT_ASSERT
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
227 _CrtSetReportFile(_CRT_ASSERT
, _CRTDBG_FILE_STDERR
);
229 // Check for leaks at program termination
230 _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF
| _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG
));
232 //_CrtSetBreakAlloc(221);