1 // Testing boost::lexical_cast with boost::container::string.
3 // See http://www.boost.org for most recent version, including documentation.
5 // Copyright Antony Polukhin, 2011.
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 #include <boost/lexical_cast.hpp>
12 #include <boost/test/unit_test.hpp>
13 #include <boost/container/string.hpp>
15 void testing_boost_containers_basic_string();
16 void testing_boost_containers_string_std_string();
17 void testing_boost_containers_string_widening();
20 using namespace boost
;
22 boost::unit_test::test_suite
*init_unit_test_suite(int, char *[])
24 unit_test::test_suite
*suite
=
25 BOOST_TEST_SUITE("Testing boost::lexical_cast with boost::container::string");
26 suite
->add(BOOST_TEST_CASE(testing_boost_containers_basic_string
));
27 suite
->add(BOOST_TEST_CASE(testing_boost_containers_string_std_string
));
28 suite
->add(BOOST_TEST_CASE(testing_boost_containers_string_widening
));
33 void testing_boost_containers_basic_string()
35 BOOST_CHECK("100" == lexical_cast
<boost::container::string
>("100"));
36 BOOST_CHECK(L
"100" == lexical_cast
<boost::container::wstring
>(L
"100"));
38 BOOST_CHECK("100" == lexical_cast
<boost::container::string
>(100));
39 boost::container::string
str("1000");
40 BOOST_CHECK(1000 == lexical_cast
<int>(str
));
43 #if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
44 #define BOOST_LCAST_NO_WCHAR_T
47 void testing_boost_containers_string_std_string()
49 std::string
std_str("std_str");
50 boost::container::string
boost_str("boost_str");
51 BOOST_CHECK(boost::lexical_cast
<std::string
>(boost_str
) == "boost_str");
52 BOOST_CHECK(boost::lexical_cast
<boost::container::string
>(std_str
) == "std_str");
54 #ifndef BOOST_LCAST_NO_WCHAR_T
55 std::wstring
std_wstr(L
"std_wstr");
56 boost::container::wstring
boost_wstr(L
"boost_wstr");
58 BOOST_CHECK(boost::lexical_cast
<std::wstring
>(boost_wstr
) == L
"boost_wstr");
59 BOOST_CHECK(boost::lexical_cast
<boost::container::wstring
>(std_wstr
) == L
"std_wstr");
65 void testing_boost_containers_string_widening()
67 const char char_array
[] = "Test string";
69 #ifndef BOOST_LCAST_NO_WCHAR_T
70 const wchar_t wchar_array
[] = L
"Test string";
71 BOOST_CHECK(boost::lexical_cast
<boost::container::wstring
>(char_array
) == wchar_array
);
74 #if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
75 const char16_t char16_array
[] = u
"Test string";
76 BOOST_CHECK(boost::lexical_cast
<boost::container::basic_string
<char16_t
> >(char_array
) == char16_array
);
79 #if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES)
80 const char32_t char32_array
[] = U
"Test string";
81 BOOST_CHECK(boost::lexical_cast
<boost::container::basic_string
<char32_t
> >(char_array
) == char32_array
);