]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lexical_cast/test/lexical_cast_vc8_bug_test.cpp
1 // Unit test for boost::lexical_cast.
3 // See http://www.boost.org for most recent version, including documentation.
5 // Copyright Alexander Nasonov, 2007.
7 // Distributed under the Boost
8 // Software License, Version 1.0. (See accompanying file
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
11 // This tests now must pass on vc8, because lexical_cast
12 // implementation has changed and it does not use stringstream for casts
15 #include <boost/config.hpp>
16 #include <boost/lexical_cast.hpp>
17 #include <boost/cstdint.hpp>
18 #include <boost/test/unit_test.hpp>
23 # pragma warning(disable: 4127) // conditional expression is constant
26 using namespace boost
;
28 // See also test_conversion_from_string_to_integral(CharT)
29 // in libs/conversion/lexical_cast_test.cpp
30 template<class T
, class CharT
>
31 void test_too_long_number(CharT zero
)
33 typedef std::numeric_limits
<T
> limits
;
35 std::basic_string
<CharT
> s
;
37 std::basic_ostringstream
<CharT
> o
;
38 o
<< (limits::max
)() << zero
;
40 BOOST_CHECK_THROW(lexical_cast
<T
>(s
), bad_lexical_cast
);
41 s
[s
.size()-1] += static_cast<CharT
>(9); // '0' -> '9'
42 BOOST_CHECK_THROW(lexical_cast
<T
>(s
), bad_lexical_cast
);
44 if (limits::is_signed
)
46 std::basic_ostringstream
<CharT
> o2
;
47 o2
<< (limits::min
)() << zero
;
49 BOOST_CHECK_THROW(lexical_cast
<T
>(s
), bad_lexical_cast
);
50 s
[s
.size()-1] += static_cast<CharT
>(9); // '0' -> '9'
51 BOOST_CHECK_THROW(lexical_cast
<T
>(s
), bad_lexical_cast
);
57 test_too_long_number
<boost::intmax_t>('0');
58 test_too_long_number
<boost::uintmax_t>('0');
59 #if !defined(BOOST_LCAST_NO_WCHAR_T)
60 test_too_long_number
<boost::intmax_t>(L
'0');
61 test_too_long_number
<boost::uintmax_t>(L
'0');
65 unit_test::test_suite
*init_unit_test_suite(int, char *[])
67 unit_test::test_suite
*suite
=
68 BOOST_TEST_SUITE("lexical_cast vc8 bug unit test");
69 suite
->add(BOOST_TEST_CASE(test_vc8_bug
));