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 | test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::cpp_regex_traits<charT> >).name()); |
---|
62 | boost::basic_regex<charT, boost::cpp_regex_traits<charT> > e1; |
---|
63 | static bool done_empty_test = false; |
---|
64 | if(done_empty_test == false) |
---|
65 | { |
---|
66 | test_empty(e1); |
---|
67 | done_empty_test = true; |
---|
68 | } |
---|
69 | if(test_locale::cpp_locale_state() == test_locale::test_with_locale) |
---|
70 | e1.imbue(test_locale::cpp_locale()); |
---|
71 | if(test_locale::cpp_locale_state() != test_locale::no_test) |
---|
72 | test(e1, tag); |
---|
73 | #endif |
---|
74 | #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560) |
---|
75 | test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::c_regex_traits<charT> >).name()); |
---|
76 | boost::basic_regex<charT, boost::c_regex_traits<charT> > e2; |
---|
77 | if(test_locale::c_locale_state() != test_locale::no_test) |
---|
78 | test(e2, tag); |
---|
79 | #endif |
---|
80 | #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) |
---|
81 | test_info<charT>::set_typename(typeid(boost::basic_regex<charT, boost::w32_regex_traits<charT> >).name()); |
---|
82 | boost::basic_regex<charT, boost::w32_regex_traits<charT> > e3; |
---|
83 | if(test_locale::win_locale_state() == test_locale::test_with_locale) |
---|
84 | e3.imbue(test_locale::win_locale()); |
---|
85 | if(test_locale::win_locale_state() != test_locale::no_test) |
---|
86 | test(e3, tag); |
---|
87 | #endif |
---|
88 | // test old depecated code: |
---|
89 | test_info<charT>::set_typename("Deprecated interfaces"); |
---|
90 | if((test_locale::win_locale_state() == test_locale::test_no_locale) |
---|
91 | && (test_locale::c_locale_state() == test_locale::test_no_locale) |
---|
92 | &&(test_locale::cpp_locale_state() == test_locale::test_no_locale)) |
---|
93 | test_deprecated(c, tag); |
---|
94 | // test MFC/ATL wrappers: |
---|
95 | test_info<charT>::set_typename("MFC/ATL interfaces"); |
---|
96 | if((test_locale::win_locale_state() == test_locale::test_no_locale) |
---|
97 | && (test_locale::c_locale_state() == test_locale::test_no_locale) |
---|
98 | &&(test_locale::cpp_locale_state() == test_locale::test_no_locale)) |
---|
99 | test_mfc(c, tag); |
---|
100 | // test ICU code: |
---|
101 | test_info<charT>::set_typename("ICU interfaces"); |
---|
102 | test_icu(c, tag); |
---|
103 | } |
---|
104 | |
---|
105 | // |
---|
106 | // define function to pack args into an array: |
---|
107 | // |
---|
108 | const int* make_array(int first, ...); |
---|
109 | |
---|
110 | |
---|
111 | // |
---|
112 | // define macros for testing invalid regexes: |
---|
113 | // |
---|
114 | #define TEST_INVALID_REGEX_N(s, f)\ |
---|
115 | do{\ |
---|
116 | const char e[] = { s };\ |
---|
117 | std::string se(e, sizeof(e) - 1);\ |
---|
118 | test_info<char>::set_info(__FILE__, __LINE__, se, f);\ |
---|
119 | test(char(0), test_invalid_regex_tag());\ |
---|
120 | }while(0) |
---|
121 | |
---|
122 | #ifndef BOOST_NO_WREGEX |
---|
123 | #define TEST_INVALID_REGEX_W(s, f)\ |
---|
124 | do{\ |
---|
125 | const wchar_t e[] = { s };\ |
---|
126 | std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\ |
---|
127 | test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f);\ |
---|
128 | test(wchar_t(0), test_invalid_regex_tag());\ |
---|
129 | }while(0) |
---|
130 | #else |
---|
131 | #define TEST_INVALID_REGEX_W(s, f) |
---|
132 | #endif |
---|
133 | |
---|
134 | #define TEST_INVALID_REGEX(s, f)\ |
---|
135 | TEST_INVALID_REGEX_N(s, f);\ |
---|
136 | TEST_INVALID_REGEX_W(BOOST_JOIN(L, s), f) |
---|
137 | |
---|
138 | // |
---|
139 | // define macros for testing regex searches: |
---|
140 | // |
---|
141 | #define TEST_REGEX_SEARCH_N(s, f, t, m, a)\ |
---|
142 | do{\ |
---|
143 | const char e[] = { s };\ |
---|
144 | std::string se(e, sizeof(e) - 1);\ |
---|
145 | const char st[] = { t };\ |
---|
146 | std::string sst(st, sizeof(st) - 1);\ |
---|
147 | test_info<char>::set_info(__FILE__, __LINE__, se, f, sst, m, a);\ |
---|
148 | test(char(0), test_regex_search_tag());\ |
---|
149 | }while(0) |
---|
150 | |
---|
151 | #ifndef BOOST_NO_WREGEX |
---|
152 | #define TEST_REGEX_SEARCH_W(s, f, t, m, a)\ |
---|
153 | do{\ |
---|
154 | const wchar_t e[] = { s };\ |
---|
155 | std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\ |
---|
156 | const wchar_t st[] = { t };\ |
---|
157 | std::wstring sst(st, (sizeof(st) / sizeof(wchar_t)) - 1);\ |
---|
158 | test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f, sst, m, a);\ |
---|
159 | test(wchar_t(0), test_regex_search_tag());\ |
---|
160 | }while(0) |
---|
161 | #else |
---|
162 | #define TEST_REGEX_SEARCH_W(s, f, t, m, a) |
---|
163 | #endif |
---|
164 | |
---|
165 | #define TEST_REGEX_SEARCH(s, f, t, m, a)\ |
---|
166 | TEST_REGEX_SEARCH_N(s, f, t, m, a);\ |
---|
167 | TEST_REGEX_SEARCH_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, a) |
---|
168 | |
---|
169 | #if (defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)) |
---|
170 | #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) |
---|
171 | #else |
---|
172 | #define TEST_REGEX_SEARCH_L(s, f, t, m, a) TEST_REGEX_SEARCH(s, f, t, m, a) |
---|
173 | #endif |
---|
174 | |
---|
175 | // |
---|
176 | // define macros for testing regex replaces: |
---|
177 | // |
---|
178 | #define TEST_REGEX_REPLACE_N(s, f, t, m, fs, r)\ |
---|
179 | do{\ |
---|
180 | const char e[] = { s };\ |
---|
181 | std::string se(e, sizeof(e) - 1);\ |
---|
182 | const char st[] = { t };\ |
---|
183 | std::string sst(st, sizeof(st) - 1);\ |
---|
184 | const char ft[] = { fs };\ |
---|
185 | std::string sft(ft, sizeof(ft) - 1);\ |
---|
186 | const char rt[] = { r };\ |
---|
187 | std::string srt(rt, sizeof(rt) - 1);\ |
---|
188 | test_info<char>::set_info(__FILE__, __LINE__, se, f, sst, m, 0, sft, srt);\ |
---|
189 | test(char(0), test_regex_replace_tag());\ |
---|
190 | }while(0) |
---|
191 | |
---|
192 | #ifndef BOOST_NO_WREGEX |
---|
193 | #define TEST_REGEX_REPLACE_W(s, f, t, m, fs, r)\ |
---|
194 | do{\ |
---|
195 | const wchar_t e[] = { s };\ |
---|
196 | std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\ |
---|
197 | const wchar_t st[] = { t };\ |
---|
198 | std::wstring sst(st, (sizeof(st) / sizeof(wchar_t)) - 1);\ |
---|
199 | const wchar_t ft[] = { fs };\ |
---|
200 | std::wstring sft(ft, (sizeof(ft) / sizeof(wchar_t)) - 1);\ |
---|
201 | const wchar_t rt[] = { r };\ |
---|
202 | std::wstring srt(rt, (sizeof(rt) / sizeof(wchar_t)) - 1);\ |
---|
203 | test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f, sst, m, 0, sft, srt);\ |
---|
204 | test(wchar_t(0), test_regex_replace_tag());\ |
---|
205 | }while(0) |
---|
206 | #else |
---|
207 | #define TEST_REGEX_REPLACE_W(s, f, t, m, fs, r) |
---|
208 | #endif |
---|
209 | |
---|
210 | #define TEST_REGEX_REPLACE(s, f, t, m, fs, r)\ |
---|
211 | TEST_REGEX_REPLACE_N(s, f, t, m, fs, r);\ |
---|
212 | TEST_REGEX_REPLACE_W(BOOST_JOIN(L, s), f, BOOST_JOIN(L, t), m, BOOST_JOIN(L, fs), BOOST_JOIN(L, r)) |
---|
213 | |
---|
214 | // |
---|
215 | // define the test group proceedures: |
---|
216 | // |
---|
217 | void basic_tests(); |
---|
218 | void test_simple_repeats(); |
---|
219 | void test_alt(); |
---|
220 | void test_sets(); |
---|
221 | void test_sets2(); |
---|
222 | void test_anchors(); |
---|
223 | void test_backrefs(); |
---|
224 | void test_character_escapes(); |
---|
225 | void test_assertion_escapes(); |
---|
226 | void test_tricky_cases(); |
---|
227 | void test_grep(); |
---|
228 | void test_replace(); |
---|
229 | void test_non_greedy_repeats(); |
---|
230 | void test_non_marking_paren(); |
---|
231 | void test_partial_match(); |
---|
232 | void test_forward_lookahead_asserts(); |
---|
233 | void test_fast_repeats(); |
---|
234 | void test_fast_repeats2(); |
---|
235 | void test_tricky_cases2(); |
---|
236 | void test_independent_subs(); |
---|
237 | void test_nosubs(); |
---|
238 | void test_conditionals(); |
---|
239 | void test_options(); |
---|
240 | void test_options2(); |
---|
241 | void test_en_locale(); |
---|
242 | void test_emacs(); |
---|
243 | void test_operators(); |
---|
244 | void test_overloads(); |
---|
245 | void test_unicode(); |
---|
246 | |
---|
247 | |
---|
248 | #endif |
---|