]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/test/regress/test_deprecated.cpp
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)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE test_deprecated.cpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Tests for deprecated interfaces.
20 #include <boost/cregex.hpp>
23 #pragma warning(disable:4267)
26 #ifdef BOOST_NO_STDC_NAMESPACE
33 int get_posix_compile_options(boost::regex_constants::syntax_option_type opts
)
35 using namespace boost
;
37 switch(opts
& regbase::main_option_type
)
40 result
= (opts
& regbase::no_perl_ex
) ? REG_EXTENDED
: REG_PERL
;
41 if(opts
& (regbase::no_bk_refs
|regbase::no_mod_m
|regbase::mod_x
|regbase::mod_s
|regbase::no_mod_s
|regbase::no_escape_in_lists
|regbase::no_empty_expressions
))
46 if(opts
& (regbase::no_char_classes
|regbase::no_intervals
|regbase::bk_plus_qm
|regbase::bk_vbar
))
48 if((opts
& regbase::no_escape_in_lists
) == 0)
55 if(opts
& regbase::icase
)
57 if(opts
& regbase::nosubs
)
59 if(opts
& regbase::newline_alt
)
60 result
|= REG_NEWLINE
;
61 if((opts
& regbase::collate
) == 0)
62 result
|= REG_NOCOLLATE
;
67 int get_posix_match_flags(boost::regex_constants::match_flag_type f
)
70 if(f
& boost::regex_constants::match_not_bol
)
71 result
|= boost::REG_NOTBOL
;
72 if(f
& boost::regex_constants::match_not_eol
)
73 result
|= boost::REG_NOTEOL
;
74 if(f
& ~(boost::regex_constants::match_not_bol
|boost::regex_constants::match_not_eol
))
79 void test_deprecated(const char&, const test_regex_search_tag
&)
81 const std::string
& expression
= test_info
<char>::expression();
82 if(expression
.find('\0') != std::string::npos
)
84 const std::string
& search_text
= test_info
<char>::search_text();
85 if(search_text
.find('\0') != std::string::npos
)
87 int posix_options
= get_posix_compile_options(test_info
<char>::syntax_options());
90 int posix_match_options
= get_posix_match_flags(test_info
<char>::match_options());
91 if(posix_match_options
< 0)
93 const int* results
= test_info
<char>::answer_table();
95 // OK try and compile the expression:
97 if(boost::regcompA(&re
, expression
.c_str(), posix_options
) != 0)
99 BOOST_REGEX_TEST_ERROR("Expression : \"" << expression
.c_str() << "\" did not compile with the POSIX C API.", char);
102 // try and find the first occurrence:
103 static const unsigned max_subs
= 100;
104 boost::regmatch_t matches
[max_subs
];
105 if(boost::regexecA(&re
, search_text
.c_str(), max_subs
, matches
, posix_match_options
) == 0)
108 while(results
[2*i
] != -2)
110 if((int)max_subs
> i
)
112 if(results
[2*i
] != matches
[i
].rm_so
)
114 BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i
<< " found with the POSIX C API.", char);
116 if(results
[2*i
+1] != matches
[i
].rm_eo
)
118 BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i
<< " found with the POSIX C API.", char);
128 BOOST_REGEX_TEST_ERROR("Expression : \"" << expression
.c_str() << "\" was not found with the POSIX C API.", char);
131 // clean up whatever:
132 boost::regfreeA(&re
);
136 std::string
to_narrow_string(std::wstring
const& w
)
138 return std::string(w
.begin(), w
.end());
141 void test_deprecated(const wchar_t&, const test_regex_search_tag
&)
143 #ifndef BOOST_NO_WREGEX
144 const std::wstring
& expression
= test_info
<wchar_t>::expression();
145 if(expression
.find(L
'\0') != std::wstring::npos
)
147 const std::wstring
& search_text
= test_info
<wchar_t>::search_text();
148 if(search_text
.find(L
'\0') != std::wstring::npos
)
150 int posix_options
= get_posix_compile_options(test_info
<wchar_t>::syntax_options());
151 if(posix_options
< 0)
153 int posix_match_options
= get_posix_match_flags(test_info
<wchar_t>::match_options());
154 if(posix_match_options
< 0)
156 const int* results
= test_info
<wchar_t>::answer_table();
158 // OK try and compile the expression:
160 if(boost::regcompW(&re
, expression
.c_str(), posix_options
) != 0)
162 BOOST_REGEX_TEST_ERROR("Expression : \"" << to_narrow_string(expression
.c_str()) << "\" did not compile with the POSIX C API.", wchar_t);
165 // try and find the first occurrence:
166 static const unsigned max_subs
= 100;
167 boost::regmatch_t matches
[max_subs
];
168 if(boost::regexecW(&re
, search_text
.c_str(), max_subs
, matches
, posix_match_options
) == 0)
171 while(results
[2*i
] != -2)
173 if((int)max_subs
> i
)
175 if(results
[2*i
] != matches
[i
].rm_so
)
177 BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i
<< " found with the POSIX C API.", wchar_t);
179 if(results
[2*i
+1] != matches
[i
].rm_eo
)
181 BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i
<< " found with the POSIX C API.", wchar_t);
191 BOOST_REGEX_TEST_ERROR("Expression : \"" << to_narrow_string(expression
.c_str()) << "\" was not found with the POSIX C API.", wchar_t);
194 // clean up whatever:
195 boost::regfreeW(&re
);
199 void test_deprecated(const char&, const test_invalid_regex_tag
&)
201 const std::string
& expression
= test_info
<char>::expression();
202 if(expression
.find('\0') != std::string::npos
)
204 int posix_options
= get_posix_compile_options(test_info
<char>::syntax_options());
205 if(posix_options
< 0)
208 // OK try and compile the expression:
210 int code
= boost::regcompA(&re
, expression
.c_str(), posix_options
);
213 boost::regfreeA(&re
);
214 BOOST_REGEX_TEST_ERROR("Expression : \"" << expression
.c_str() << "\" unexpectedly compiled with the POSIX C API.", char);
219 int s
= boost::regerrorA(code
, &re
, 0, 0);
221 s
= boost::regerrorA(code
, &re
, buf
, 100);
222 s
= boost::regerrorA(code
| boost::REG_ITOA
, &re
, 0, 0);
225 s
= boost::regerrorA(code
| boost::REG_ITOA
, &re
, buf
, 100);
227 s
= boost::regerrorA(code
| boost::REG_ATOI
, &re
, buf
, 100);
230 int code2
= std::atoi(buf
);
233 BOOST_REGEX_TEST_ERROR("Got a bad error code from regerrA with REG_ATOI set: ", char);
240 void test_deprecated(const wchar_t&, const test_invalid_regex_tag
&)
242 #ifndef BOOST_NO_WREGEX
243 const std::wstring
& expression
= test_info
<wchar_t>::expression();
244 if(expression
.find(L
'\0') != std::string::npos
)
246 int posix_options
= get_posix_compile_options(test_info
<wchar_t>::syntax_options());
247 if(posix_options
< 0)
250 // OK try and compile the expression:
252 int code
= boost::regcompW(&re
, expression
.c_str(), posix_options
);
255 boost::regfreeW(&re
);
256 BOOST_REGEX_TEST_ERROR("Expression : \"" << to_narrow_string(expression
.c_str()) << "\" unexpectedly compiled with the POSIX C API.", wchar_t);
261 int s
= boost::regerrorW(code
, &re
, 0, 0);
263 s
= boost::regerrorW(code
, &re
, buf
, 100);
264 s
= boost::regerrorW(code
| boost::REG_ITOA
, &re
, 0, 0);
267 s
= boost::regerrorW(code
| boost::REG_ITOA
, &re
, buf
, 100);
269 s
= boost::regerrorW(code
| boost::REG_ATOI
, &re
, buf
, 100);
272 long code2
= std::wcstol(buf
, 0, 10);
275 BOOST_REGEX_TEST_ERROR("Got a bad error code from regerrW with REG_ATOI set: ", char);