| 1 | /* |
|---|
| 2 | * |
|---|
| 3 | * Copyright (c) 2004 |
|---|
| 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 test.hpp |
|---|
| 15 | * VERSION see <boost/version.hpp> |
|---|
| 16 | * DESCRIPTION: Macros for test cases. |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef BOOST_REGEX_REGRESS_TEST_HPP |
|---|
| 21 | #define BOOST_REGEX_REGRESS_TEST_HPP |
|---|
| 22 | #include <typeinfo> |
|---|
| 23 | #include "test_not_regex.hpp" |
|---|
| 24 | #include "test_regex_search.hpp" |
|---|
| 25 | #include "test_regex_replace.hpp" |
|---|
| 26 | #include "test_deprecated.hpp" |
|---|
| 27 | #include "test_mfc.hpp" |
|---|
| 28 | #include "test_icu.hpp" |
|---|
| 29 | #include "test_locale.hpp" |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | // |
|---|
| 33 | // define test entry proc, this forwards on to the appropriate |
|---|
| 34 | // real test: |
|---|
| 35 | // |
|---|
| 36 | template <class charT, class tagT> |
|---|
| 37 | void do_test(const charT& c, const tagT& tag); |
|---|
| 38 | |
|---|
| 39 | template <class charT, class tagT> |
|---|
| 40 | void test(const charT& c, const tagT& tag) |
|---|
| 41 | { |
|---|
| 42 | do_test(c, tag); |
|---|
| 43 | } |
|---|
| 44 | // |
|---|
| 45 | // make these non-templates to speed up compilation times: |
|---|
| 46 | // |
|---|
| 47 | void test(const char&, const test_regex_replace_tag&); |
|---|
| 48 | void test(const char&, const test_regex_search_tag&); |
|---|
| 49 | void test(const char&, const test_invalid_regex_tag&); |
|---|
| 50 | |
|---|
| 51 | #ifndef BOOST_NO_WREGEX |
|---|
| 52 | void test(const wchar_t&, const test_regex_replace_tag&); |
|---|
| 53 | void test(const wchar_t&, const test_regex_search_tag&); |
|---|
| 54 | void test(const wchar_t&, const test_invalid_regex_tag&); |
|---|
| 55 | #endif |
|---|
| 56 | |
|---|
| 57 | template <class charT, class tagT> |
|---|
| 58 | void do_test(const charT& c, const tagT& tag) |
|---|
| 59 | { |
|---|
| 60 | #ifndef BOOST_NO_STD_LOCALE |
|---|
| 61 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) && defined(TEST_THREADS) |
|---|
| 62 | // typeid appears to fail in multithreaded environments: |
|---|
| 63 | test_info<charT>::set_typename(""); |
|---|
| 64 | #else |
|---|
| 65 | test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::cpp_regex_traits<charT> >).name()); |
|---|
| 66 | #endif |
|---|
| 67 | boost::basic_regex<charT, boost::cpp_regex_traits<charT> > e1; |
|---|
| 68 | static bool done_empty_test = false; |
|---|
| 69 | if(done_empty_test == false) |
|---|
| 70 | { |
|---|
| 71 | test_empty(e1); |
|---|
| 72 | done_empty_test = true; |
|---|
| 73 | } |
|---|
| 74 | if(test_locale::cpp_locale_state() == test_locale::test_with_locale) |
|---|
| 75 | e1.imbue(test_locale::cpp_locale()); |
|---|
| 76 | if(test_locale::cpp_locale_state() != test_locale::no_test) |
|---|
| 77 | test(e1, tag); |
|---|
| 78 | #endif |
|---|
| 79 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560) |
|---|
| 80 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) && defined(TEST_THREADS) |
|---|
| 81 | // typeid appears to fail in multithreaded environments: |
|---|
| 82 | test_info<charT>::set_typename(""); |
|---|
| 83 | #else |
|---|
| 84 | test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::c_regex_traits<charT> >).name()); |
|---|
| 85 | #endif |
|---|
| 86 | boost::basic_regex<charT, boost::c_regex_traits<charT> > e2; |
|---|
| 87 | if(test_locale::c_locale_state() != test_locale::no_test) |
|---|
| 88 | test(e2, tag); |
|---|
| 89 | #endif |
|---|
| 90 | #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) |
|---|
| 91 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) && defined(TEST_THREADS) |
|---|
| 92 | // typeid appears to fail in multithreaded environments: |
|---|
| 93 | test_info<charT>::set_typename(""); |
|---|
| 94 | #else |
|---|
| 95 | test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::w32_regex_traits<charT> >).name()); |
|---|
| 96 | #endif |
|---|
| 97 | boost::basic_regex<charT, boost::w32_regex_traits<charT> > e3; |
|---|
| 98 | if(test_locale::win_locale_state() == test_locale::test_with_locale) |
|---|
| 99 | e3.imbue(test_locale::win_locale()); |
|---|
| 100 | if(test_locale::win_locale_state() != test_locale::no_test) |
|---|
| 101 | test(e3, tag); |
|---|
| 102 | #endif |
|---|
| 103 | // test old depecated code: |
|---|
| 104 | test_info<charT>::set_typename("Deprecated interfaces"); |
|---|
| 105 | if((test_locale::win_locale_state() == test_locale::test_no_locale) |
|---|
| 106 | && (test_locale::c_locale_state() == test_locale::test_no_locale) |
|---|
| 107 | &&(test_locale::cpp_locale_state() == test_locale::test_no_locale)) |
|---|
| 108 | test_deprecated(c, tag); |
|---|
| 109 | // test MFC/ATL wrappers: |
|---|
| 110 | test_info<charT>::set_typename("MFC/ATL interfaces"); |
|---|
| 111 | if((test_locale::win_locale_state() == test_locale::test_no_locale) |
|---|
| 112 | && (test_locale::c_locale_state() == test_locale::test_no_locale) |
|---|
| 113 | &&(test_locale::cpp_locale_state() == test_locale::test_no_locale)) |
|---|
| 114 | test_mfc(c, tag); |
|---|
| 115 | // test ICU code: |
|---|
| 116 | test_info<charT>::set_typename("ICU interfaces"); |
|---|
| 117 | test_icu(c, tag); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | // |
|---|
| 121 | // define function to pack args into an array: |
|---|
| 122 | // |
|---|
| 123 | const int* make_array(int first, ...); |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | // |
|---|
| 127 | // define macros for testing invalid regexes: |
|---|
| 128 | // |
|---|
| 129 | #define TEST_INVALID_REGEX_N(s, f)\ |
|---|
| 130 | do{\ |
|---|
| 131 | const char e[] = { s };\ |
|---|
| 132 | std::string se(e, sizeof(e) - 1);\ |
|---|
| 133 | test_info<char>::set_info(__FILE__, __LINE__, se, f);\ |
|---|
| 134 | test(char(0), test_invalid_regex_tag());\ |
|---|
| 135 | }while(0) |
|---|
| 136 | |
|---|
| 137 | #ifndef BOOST_NO_WREGEX |
|---|
| 138 | #define TEST_INVALID_REGEX_W(s, f)\ |
|---|
| 139 | do{\ |
|---|
| 140 | const wchar_t e[] = { s };\ |
|---|
| 141 | std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\ |
|---|
| 142 | test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f);\ |
|---|
| 143 | test(wchar_t(0), test_invalid_regex_tag());\ |
|---|
| 144 | }while(0) |
|---|
| 145 | #else |
|---|
| 146 | #define TEST_INVALID_REGEX_W(s, f) |
|---|
| 147 | #endif |
|---|
| 148 | |
|---|
| 149 | #define TEST_INVALID_REGEX(s, f)\ |
|---|
| 150 | TEST_INVALID_REGEX_N(s, f);\ |
|---|
| 151 | TEST_INVALID_REGEX_W(BOOST_JOIN(L, s), f) |
|---|
| 152 | |
|---|
| 153 | // |
|---|
| 154 | // define macros for testing regex searches: |
|---|
| 155 | // |
|---|
| 156 | #define TEST_REGEX_SEARCH_N(s, f, t, m, a)\ |
|---|
| 157 | do{\ |
|---|
| 158 | const char e[] = { s };\ |
|---|
| 159 | std::string se(e, sizeof(e) - 1);\ |
|---|
| 160 | const char st[] = { t };\ |
|---|
| 161 | std::string sst(st, sizeof(st) - 1);\ |
|---|
| 162 | test_info<char>::set_info(__FILE__, __LINE__, se, f, sst, m, a);\ |
|---|
| 163 | test(char(0), test_regex_search_tag());\ |
|---|
| 164 | }while(0) |
|---|
| 165 | |
|---|
| 166 | #ifndef BOOST_NO_WREGEX |
|---|
| 167 | #define TEST_REGEX_SEARCH_W(s, f, t, m, a)\ |
|---|
| 168 | do{\ |
|---|
| 169 | const wchar_t e[] = { s };\ |
|---|
| 170 | std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\ |
|---|
| 171 | const wchar_t st[] = { t };\ |
|---|
| 172 | std::wstring sst(st, (sizeof(st) / sizeof(wchar_t)) - 1);\ |
|---|
| 173 | test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f, sst, m, a);\ |
|---|
| 174 | test(wchar_t(0), test_regex_search_tag());\ |
|---|
| 175 | }while(0) |
|---|
| 176 | #else |
|---|
| 177 | #define TEST_REGEX_SEARCH_W(s, f, t, m, a) |
|---|
| 178 | #endif |
|---|
| 179 | |
|---|
| 180 | #define TEST_REGEX_SEARCH(s, f, t, m, a)\ |
|---|
| 181 | TEST_REGEX_SEARCH_N(s, f, t, m, a);\ |
|---|
| 182 | TEST_REGEX_SEARCH_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, a) |
|---|
| 183 | |
|---|
| 184 | #if (defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)) |
|---|
| 185 | #define TEST_REGEX_SEARCH_L(s, f, t, m, a) TEST_REGEX_SEARCH_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, a) |
|---|
| 186 | #else |
|---|
| 187 | #define TEST_REGEX_SEARCH_L(s, f, t, m, a) TEST_REGEX_SEARCH(s, f, t, m, a) |
|---|
| 188 | #endif |
|---|
| 189 | |
|---|
| 190 | // |
|---|
| 191 | // define macros for testing regex replaces: |
|---|
| 192 | // |
|---|
| 193 | #define TEST_REGEX_REPLACE_N(s, f, t, m, fs, r)\ |
|---|
| 194 | do{\ |
|---|
| 195 | const char e[] = { s };\ |
|---|
| 196 | std::string se(e, sizeof(e) - 1);\ |
|---|
| 197 | const char st[] = { t };\ |
|---|
| 198 | std::string sst(st, sizeof(st) - 1);\ |
|---|
| 199 | const char ft[] = { fs };\ |
|---|
| 200 | std::string sft(ft, sizeof(ft) - 1);\ |
|---|
| 201 | const char rt[] = { r };\ |
|---|
| 202 | std::string srt(rt, sizeof(rt) - 1);\ |
|---|
| 203 | test_info<char>::set_info(__FILE__, __LINE__, se, f, sst, m, 0, sft, srt);\ |
|---|
| 204 | test(char(0), test_regex_replace_tag());\ |
|---|
| 205 | }while(0) |
|---|
| 206 | |
|---|
| 207 | #ifndef BOOST_NO_WREGEX |
|---|
| 208 | #define TEST_REGEX_REPLACE_W(s, f, t, m, fs, r)\ |
|---|
| 209 | do{\ |
|---|
| 210 | const wchar_t e[] = { s };\ |
|---|
| 211 | std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\ |
|---|
| 212 | const wchar_t st[] = { t };\ |
|---|
| 213 | std::wstring sst(st, (sizeof(st) / sizeof(wchar_t)) - 1);\ |
|---|
| 214 | const wchar_t ft[] = { fs };\ |
|---|
| 215 | std::wstring sft(ft, (sizeof(ft) / sizeof(wchar_t)) - 1);\ |
|---|
| 216 | const wchar_t rt[] = { r };\ |
|---|
| 217 | std::wstring srt(rt, (sizeof(rt) / sizeof(wchar_t)) - 1);\ |
|---|
| 218 | test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f, sst, m, 0, sft, srt);\ |
|---|
| 219 | test(wchar_t(0), test_regex_replace_tag());\ |
|---|
| 220 | }while(0) |
|---|
| 221 | #else |
|---|
| 222 | #define TEST_REGEX_REPLACE_W(s, f, t, m, fs, r) |
|---|
| 223 | #endif |
|---|
| 224 | |
|---|
| 225 | #define TEST_REGEX_REPLACE(s, f, t, m, fs, r)\ |
|---|
| 226 | TEST_REGEX_REPLACE_N(s, f, t, m, fs, r);\ |
|---|
| 227 | TEST_REGEX_REPLACE_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, BOOST_JOIN(L, fs), BOOST_JOIN(L, r)) |
|---|
| 228 | |
|---|
| 229 | // |
|---|
| 230 | // define the test group proceedures: |
|---|
| 231 | // |
|---|
| 232 | void basic_tests(); |
|---|
| 233 | void test_simple_repeats(); |
|---|
| 234 | void test_alt(); |
|---|
| 235 | void test_sets(); |
|---|
| 236 | void test_sets2(); |
|---|
| 237 | void test_anchors(); |
|---|
| 238 | void test_backrefs(); |
|---|
| 239 | void test_character_escapes(); |
|---|
| 240 | void test_assertion_escapes(); |
|---|
| 241 | void test_tricky_cases(); |
|---|
| 242 | void test_grep(); |
|---|
| 243 | void test_replace(); |
|---|
| 244 | void test_non_greedy_repeats(); |
|---|
| 245 | void test_non_marking_paren(); |
|---|
| 246 | void test_partial_match(); |
|---|
| 247 | void test_forward_lookahead_asserts(); |
|---|
| 248 | void test_fast_repeats(); |
|---|
| 249 | void test_fast_repeats2(); |
|---|
| 250 | void test_tricky_cases2(); |
|---|
| 251 | void test_independent_subs(); |
|---|
| 252 | void test_nosubs(); |
|---|
| 253 | void test_conditionals(); |
|---|
| 254 | void test_options(); |
|---|
| 255 | void test_options2(); |
|---|
| 256 | void test_en_locale(); |
|---|
| 257 | void test_emacs(); |
|---|
| 258 | void test_operators(); |
|---|
| 259 | void test_overloads(); |
|---|
| 260 | void test_unicode(); |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | #endif |
|---|
| 264 | |
|---|