]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/test/pathology/recursion_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / regex / test / pathology / recursion_test.cpp
1 /*
2 *
3 * Copyright (c) 1998-2002
4 * John Maddock
5 *
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 *
10 */
11
12 /*
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE: recursion_test.cpp
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Test for indefinite recursion and/or stack overrun.
17 */
18
19 #include <string>
20 #include <boost/regex.hpp>
21 #include <boost/detail/lightweight_main.hpp>
22 #include "../test_macros.hpp"
23
24 #ifdef BOOST_INTEL
25 #pragma warning(disable:1418 981 983 383)
26 #endif
27
28 int cpp_main( int , char* [] )
29 {
30 // this regex will recurse twice for each whitespace character matched:
31 boost::regex e("([[:space:]]|.)+");
32
33 std::string bad_text(1024*1024*4, ' ');
34 std::string good_text(200, ' ');
35
36 boost::smatch what;
37
38 //
39 // Over and over: We want to make sure that after a stack error has
40 // been triggered, that we can still conduct a good search and that
41 // subsequent stack failures still do the right thing:
42 //
43 BOOST_CHECK(boost::regex_search(good_text, what, e));
44 BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
45 BOOST_CHECK(boost::regex_search(good_text, what, e));
46 BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
47 BOOST_CHECK(boost::regex_search(good_text, what, e));
48 BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
49 BOOST_CHECK(boost::regex_search(good_text, what, e));
50 BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e), std::runtime_error);
51 BOOST_CHECK(boost::regex_search(good_text, what, e));
52
53 BOOST_CHECK(boost::regex_match(good_text, what, e));
54 BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
55 BOOST_CHECK(boost::regex_match(good_text, what, e));
56 BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
57 BOOST_CHECK(boost::regex_match(good_text, what, e));
58 BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
59 BOOST_CHECK(boost::regex_match(good_text, what, e));
60 BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e), std::runtime_error);
61 BOOST_CHECK(boost::regex_match(good_text, what, e));
62
63 return 0;
64 }
65