| 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-2024. |
| 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 | |
| 13 | #include <boost/core/lightweight_test.hpp> |
| 14 | #include <boost/container/string.hpp> |
| 15 | |
| 16 | using namespace boost; |
| 17 | |
| 18 | void testing_boost_containers_basic_string() |
| 19 | { |
| 20 | BOOST_TEST("100"== lexical_cast<boost::container::string>( "100")); |
| 21 | BOOST_TEST(L"100"== lexical_cast<boost::container::wstring>(L "100")); |
| 22 | |
| 23 | BOOST_TEST("100"== lexical_cast<boost::container::string>(100)); |
| 24 | boost::container::string str("1000"); |
| 25 | BOOST_TEST(1000 == lexical_cast<int>(str)); |
| 26 | } |
| 27 | |
| 28 | #if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING) |
| 29 | #define BOOST_LCAST_NO_WCHAR_T |
| 30 | #endif |
| 31 | |
| 32 | void testing_boost_containers_string_std_string() |
| 33 | { |
| 34 | std::string std_str("std_str"); |
| 35 | boost::container::string boost_str("boost_str"); |
| 36 | BOOST_TEST(boost::lexical_cast<std::string>(boost_str) == "boost_str"); |
| 37 | BOOST_TEST(boost::lexical_cast<boost::container::string>(std_str) == "std_str"); |
| 38 | |
| 39 | #ifndef BOOST_LCAST_NO_WCHAR_T |
| 40 | std::wstring std_wstr(L"std_wstr"); |
| 41 | boost::container::wstring boost_wstr(L"boost_wstr"); |
| 42 | |
| 43 | BOOST_TEST(boost::lexical_cast<std::wstring>(boost_wstr) == L"boost_wstr"); |
| 44 | BOOST_TEST(boost::lexical_cast<boost::container::wstring>(std_wstr) == L"std_wstr"); |
| 45 | |
| 46 | #endif |
| 47 | |
| 48 | } |
| 49 | |
| 50 | void testing_boost_containers_string_widening() |
| 51 | { |
| 52 | const char char_array[] = "Test string"; |
| 53 | |
| 54 | #ifndef BOOST_LCAST_NO_WCHAR_T |
| 55 | const wchar_t wchar_array[] = L"Test string"; |
| 56 | BOOST_TEST(boost::lexical_cast<boost::container::wstring>(char_array) == wchar_array); |
| 57 | #endif |
| 58 | |
| 59 | #if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES) |
| 60 | const char16_t char16_array[] = u"Test string"; |
| 61 | BOOST_TEST(boost::lexical_cast<boost::container::basic_string<char16_t> >(char_array) == char16_array); |
| 62 | #endif |
| 63 | |
| 64 | #if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && defined(BOOST_STL_SUPPORTS_NEW_UNICODE_LOCALES) |
| 65 | const char32_t char32_array[] = U"Test string"; |
| 66 | BOOST_TEST(boost::lexical_cast<boost::container::basic_string<char32_t> >(char_array) == char32_array); |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | int main() |
| 71 | { |
| 72 | testing_boost_containers_basic_string(); |
| 73 | testing_boost_containers_string_std_string(); |
| 74 | testing_boost_containers_string_widening(); |
| 75 | |
| 76 | return boost::report_errors(); |
| 77 | } |
| 78 |
