Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/regex/test/regress/test.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 7.7 KB
Line 
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//
36template <class charT, class tagT>
37void do_test(const charT& c, const tagT& tag);
38
39template <class charT, class tagT>
40void 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//
47void test(const char&, const test_regex_replace_tag&);
48void test(const char&, const test_regex_search_tag&);
49void test(const char&, const test_invalid_regex_tag&);
50
51#ifndef BOOST_NO_WREGEX
52void test(const wchar_t&, const test_regex_replace_tag&);
53void test(const wchar_t&, const test_regex_search_tag&);
54void test(const wchar_t&, const test_invalid_regex_tag&);
55#endif
56
57template <class charT, class tagT>
58void 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//
108const 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//
217void basic_tests();
218void test_simple_repeats();
219void test_alt();
220void test_sets();
221void test_sets2();
222void test_anchors();
223void test_backrefs();
224void test_character_escapes();
225void test_assertion_escapes();
226void test_tricky_cases();
227void test_grep();
228void test_replace();
229void test_non_greedy_repeats();
230void test_non_marking_paren();
231void test_partial_match();
232void test_forward_lookahead_asserts();
233void test_fast_repeats();
234void test_fast_repeats2();
235void test_tricky_cases2();
236void test_independent_subs();
237void test_nosubs();
238void test_conditionals();
239void test_options();
240void test_options2();
241void test_en_locale();
242void test_emacs();
243void test_operators();
244void test_overloads();
245void test_unicode();
246
247
248#endif
Note: See TracBrowser for help on using the repository browser.