]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lexical_cast/test/lexical_cast_containers_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / lexical_cast / test / lexical_cast_containers_test.cpp
1 // Testing boost::lexical_cast with boost::container::string.
2 //
3 // See http://www.boost.org for most recent version, including documentation.
4 //
5 // Copyright Antony Polukhin, 2011.
6 //
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).
10
11 #include <boost/lexical_cast.hpp>
12 #include <boost/test/unit_test.hpp>
13 #include <boost/container/string.hpp>
14
15 void testing_boost_containers_basic_string();
16 void testing_boost_containers_string_std_string();
17 void testing_boost_containers_string_widening();
18
19
20 using namespace boost;
21
22 boost::unit_test::test_suite *init_unit_test_suite(int, char *[])
23 {
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));
29
30 return suite;
31 }
32
33 void testing_boost_containers_basic_string()
34 {
35 BOOST_CHECK("100" == lexical_cast<boost::container::string>("100"));
36 BOOST_CHECK(L"100" == lexical_cast<boost::container::wstring>(L"100"));
37
38 BOOST_CHECK("100" == lexical_cast<boost::container::string>(100));
39 boost::container::string str("1000");
40 BOOST_CHECK(1000 == lexical_cast<int>(str));
41 }
42
43 #if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
44 #define BOOST_LCAST_NO_WCHAR_T
45 #endif
46
47 void testing_boost_containers_string_std_string()
48 {
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");
53
54 #ifndef BOOST_LCAST_NO_WCHAR_T
55 std::wstring std_wstr(L"std_wstr");
56 boost::container::wstring boost_wstr(L"boost_wstr");
57
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");
60
61 #endif
62
63 }
64
65 void testing_boost_containers_string_widening()
66 {
67 const char char_array[] = "Test string";
68
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);
72 #endif
73
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);
77 #endif
78
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);
82 #endif
83 }