]>
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 occurance:
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
);
135 // now try the RegEx class:
137 if ( test_info
< char >:: syntax_options () & ~ boost :: regex :: icase
)
139 #ifndef BOOST_NO_EXCEPTIONS
143 boost :: RegEx
e ( expression
, ( test_info
< char >:: syntax_options () & boost :: regex :: icase
) != 0 );
146 BOOST_REGEX_TEST_ERROR ( "Expression did not compile when it should have done, error code = " << e
. error_code (), char );
148 if ( e
. Search ( search_text
, test_info
< char >:: match_options ()))
151 while ( results
[ i
* 2 ] != - 2 )
155 if ( results
[ 2 * i
] != static_cast < int >( e
. Position ( i
)))
157 BOOST_REGEX_TEST_ERROR ( "Mismatch in start of subexpression " << i
<< " found with the RegEx class (found " << e
. Position ( i
) << " expected " << results
[ 2 * i
] << ")." , char );
159 if ( results
[ 2 * i
+ 1 ] != static_cast < int >( e
. Position ( i
) + e
. Length ( i
)))
161 BOOST_REGEX_TEST_ERROR ( "Mismatch in end of subexpression " << i
<< " found with the RegEx class (found " << e
. Position ( i
) + e
. Length ( i
) << " expected " << results
[ 2 * i
+ 1 ] << ")." , char );
166 if ( results
[ 2 * i
] >= 0 )
168 BOOST_REGEX_TEST_ERROR ( "Mismatch in start of subexpression " << i
<< " found with the RegEx class (found " << e
. Position ( i
) << " expected " << results
[ 2 * i
] << ")." , char );
170 if ( results
[ 2 * i
+ 1 ] >= 0 )
172 BOOST_REGEX_TEST_ERROR ( "Mismatch in end of subexpression " << i
<< " found with the RegEx class (found " << e
. Position ( i
) + e
. Length ( i
) << " expected " << results
[ 2 * i
+ 1 ] << ")." , char );
182 BOOST_REGEX_TEST_ERROR ( "Expression : \" " << expression
. c_str () << " \" was not found with class RegEx." , char );
186 #ifndef BOOST_NO_EXCEPTIONS
187 catch ( const boost :: bad_expression
& r
)
189 BOOST_REGEX_TEST_ERROR ( "Expression did not compile with RegEx class: " << r
. what (), char );
191 catch ( const std :: runtime_error
& r
)
193 BOOST_REGEX_TEST_ERROR ( "Unexpected std::runtime_error : " << r
. what (), char );
195 catch ( const std :: exception
& r
)
197 BOOST_REGEX_TEST_ERROR ( "Unexpected std::exception: " << r
. what (), char );
201 BOOST_REGEX_TEST_ERROR ( "Unexpected exception of unknown type" , char );
206 void test_deprecated ( const wchar_t &, const test_regex_search_tag
&)
208 #ifndef BOOST_NO_WREGEX
209 const std :: wstring
& expression
= test_info
< wchar_t >:: expression ();
210 if ( expression
. find ( L
'\0' ) != std :: wstring :: npos
)
212 const std :: wstring
& search_text
= test_info
< wchar_t >:: search_text ();
213 if ( search_text
. find ( L
'\0' ) != std :: wstring :: npos
)
215 int posix_options
= get_posix_compile_options ( test_info
< wchar_t >:: syntax_options ());
216 if ( posix_options
< 0 )
218 int posix_match_options
= get_posix_match_flags ( test_info
< wchar_t >:: match_options ());
219 if ( posix_match_options
< 0 )
221 const int * results
= test_info
< wchar_t >:: answer_table ();
223 // OK try and compile the expression:
225 if ( boost :: regcompW (& re
, expression
. c_str (), posix_options
) != 0 )
227 BOOST_REGEX_TEST_ERROR ( "Expression : \" " << expression
. c_str () << " \" did not compile with the POSIX C API." , wchar_t );
230 // try and find the first occurance:
231 static const unsigned max_subs
= 100 ;
232 boost :: regmatch_t matches
[ max_subs
];
233 if ( boost :: regexecW (& re
, search_text
. c_str (), max_subs
, matches
, posix_match_options
) == 0 )
236 while ( results
[ 2 * i
] != - 2 )
238 if (( int ) max_subs
> i
)
240 if ( results
[ 2 * i
] != matches
[ i
]. rm_so
)
242 BOOST_REGEX_TEST_ERROR ( "Mismatch in start of subexpression " << i
<< " found with the POSIX C API." , wchar_t );
244 if ( results
[ 2 * i
+ 1 ] != matches
[ i
]. rm_eo
)
246 BOOST_REGEX_TEST_ERROR ( "Mismatch in end of subexpression " << i
<< " found with the POSIX C API." , wchar_t );
256 BOOST_REGEX_TEST_ERROR ( "Expression : \" " << expression
. c_str () << " \" was not found with the POSIX C API." , wchar_t );
259 // clean up whatever:
260 boost :: regfreeW (& re
);
264 void test_deprecated ( const char &, const test_invalid_regex_tag
&)
266 const std :: string
& expression
= test_info
< char >:: expression ();
267 if ( expression
. find ( '\0' ) != std :: string :: npos
)
269 int posix_options
= get_posix_compile_options ( test_info
< char >:: syntax_options ());
270 if ( posix_options
< 0 )
273 // OK try and compile the expression:
275 int code
= boost :: regcompA (& re
, expression
. c_str (), posix_options
);
278 boost :: regfreeA (& re
);
279 BOOST_REGEX_TEST_ERROR ( "Expression : \" " << expression
. c_str () << " \" unexpectedly compiled with the POSIX C API." , char );
284 int s
= boost :: regerrorA ( code
, & re
, 0 , 0 );
286 s
= boost :: regerrorA ( code
, & re
, buf
, 100 );
287 s
= boost :: regerrorA ( code
| boost :: REG_ITOA
, & re
, 0 , 0 );
290 s
= boost :: regerrorA ( code
| boost :: REG_ITOA
, & re
, buf
, 100 );
292 s
= boost :: regerrorA ( code
| boost :: REG_ATOI
, & re
, buf
, 100 );
295 int code2
= std :: atoi ( buf
);
298 BOOST_REGEX_TEST_ERROR ( "Got a bad error code from regerrA with REG_ATOI set: " , char );
304 // now try the RegEx class:
306 if ( test_info
< char >:: syntax_options () & ~ boost :: regex :: icase
)
308 bool have_catch
= false ;
309 #ifndef BOOST_NO_EXCEPTIONS
313 boost :: RegEx
e ( expression
, ( test_info
< char >:: syntax_options () & boost :: regex :: icase
) != 0 );
317 #ifndef BOOST_NO_EXCEPTIONS
318 catch ( const boost :: bad_expression
&)
322 catch ( const std :: runtime_error
& r
)
325 BOOST_REGEX_TEST_ERROR ( "Expected a bad_expression exception, but a std::runtime_error instead: " << r
. what (), char );
327 catch ( const std :: exception
& r
)
330 BOOST_REGEX_TEST_ERROR ( "Expected a bad_expression exception, but a std::exception instead: " << r
. what (), char );
335 BOOST_REGEX_TEST_ERROR ( "Expected a bad_expression exception, but got an exception of unknown type instead" , char );
340 // oops expected exception was not thrown:
341 BOOST_REGEX_TEST_ERROR ( "Expected an exception, but didn't find one." , char );
345 void test_deprecated ( const wchar_t &, const test_invalid_regex_tag
&)
347 #ifndef BOOST_NO_WREGEX
348 const std :: wstring
& expression
= test_info
< wchar_t >:: expression ();
349 if ( expression
. find ( L
'\0' ) != std :: string :: npos
)
351 int posix_options
= get_posix_compile_options ( test_info
< wchar_t >:: syntax_options ());
352 if ( posix_options
< 0 )
355 // OK try and compile the expression:
357 int code
= boost :: regcompW (& re
, expression
. c_str (), posix_options
);
360 boost :: regfreeW (& re
);
361 BOOST_REGEX_TEST_ERROR ( "Expression : \" " << expression
. c_str () << " \" unexpectedly compiled with the POSIX C API." , wchar_t );
366 int s
= boost :: regerrorW ( code
, & re
, 0 , 0 );
368 s
= boost :: regerrorW ( code
, & re
, buf
, 100 );
369 s
= boost :: regerrorW ( code
| boost :: REG_ITOA
, & re
, 0 , 0 );
372 s
= boost :: regerrorW ( code
| boost :: REG_ITOA
, & re
, buf
, 100 );
374 s
= boost :: regerrorW ( code
| boost :: REG_ATOI
, & re
, buf
, 100 );
377 long code2
= std :: wcstol ( buf
, 0 , 10 );
380 BOOST_REGEX_TEST_ERROR ( "Got a bad error code from regerrW with REG_ATOI set: " , char );