bad_expression_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE: recursion_test.cpp
  14. * VERSION: see <boost/version.hpp>
  15. * DESCRIPTION: Test for indefinite recursion and/or stack overrun.
  16. */
  17. #include <boost/regex.hpp>
  18. #include <boost/detail/lightweight_main.hpp>
  19. #include "../test_macros.hpp"
  20. #include <string>
  21. #ifdef BOOST_INTEL
  22. #pragma warning(disable:1418 981 983 383)
  23. #endif
  24. int cpp_main( int , char* [] )
  25. {
  26. std::string bad_text(1024, ' ');
  27. std::string good_text(200, ' ');
  28. good_text.append("xyz");
  29. boost::smatch what;
  30. boost::regex e1("(.+)+xyz");
  31. BOOST_CHECK(boost::regex_search(good_text, what, e1));
  32. BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e1), std::runtime_error);
  33. BOOST_CHECK(boost::regex_search(good_text, what, e1));
  34. BOOST_CHECK(boost::regex_match(good_text, what, e1));
  35. BOOST_CHECK_THROW(boost::regex_match(bad_text, what, e1), std::runtime_error);
  36. BOOST_CHECK(boost::regex_match(good_text, what, e1));
  37. boost::regex e2("abc|[[:space:]]+(xyz)?[[:space:]]+xyz");
  38. BOOST_CHECK(boost::regex_search(good_text, what, e2));
  39. BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e2), std::runtime_error);
  40. BOOST_CHECK(boost::regex_search(good_text, what, e2));
  41. bad_text.assign((std::string::size_type)500000, 'a');
  42. e2.assign("aaa*@");
  43. BOOST_CHECK_THROW(boost::regex_search(bad_text, what, e2), std::runtime_error);
  44. good_text.assign((std::string::size_type)5000, 'a');
  45. BOOST_CHECK(0 == boost::regex_search(good_text, what, e2));
  46. return 0;
  47. }