From 8d373a0c9957e33359ffec416a6d8c772a56203d Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Sun, 23 Sep 2012 17:19:05 +0000 Subject: [PATCH] Merge updated tests from trunk (now float types tests are less strict, workaround MSVC2012 bug) [SVN r80672] --- lexical_cast_test.cpp | 12 ++++++++++++ test/lexical_cast_float_types_test.cpp | 15 ++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lexical_cast_test.cpp b/lexical_cast_test.cpp index e12cfe7..bc4184f 100644 --- a/lexical_cast_test.cpp +++ b/lexical_cast_test.cpp @@ -474,6 +474,11 @@ void test_wtraits() void test_allocator() { +// Following test cause compilation error on MSVC2012: +// (Reason: cannot convert from 'std::_Wrap_alloc<_Alloc>' to 'const my_allocator') +// +// MSVC developer is notified about this issue +#if !defined(_MSC_VER) || (_MSC_VER < 1700) typedef std::basic_string< char , std::char_traits , my_allocator @@ -486,10 +491,16 @@ void test_allocator() BOOST_CHECK(boost::lexical_cast(1) == "1"); BOOST_CHECK(boost::lexical_cast("s") == s); BOOST_CHECK(boost::lexical_cast(std::string("s")) == s); +#endif } void test_wallocator() { +// Following test cause compilation error on MSVC2012: +// (Reason: cannot convert from 'std::_Wrap_alloc<_Alloc>' to 'const my_allocator') +// +// MSVC developer is notified about this issue +#if !defined(_MSC_VER) || (_MSC_VER < 1700) typedef std::basic_string< wchar_t , std::char_traits , my_allocator @@ -502,6 +513,7 @@ void test_wallocator() BOOST_CHECK(boost::lexical_cast(1) == L"1"); BOOST_CHECK(boost::lexical_cast(L"s") == s); BOOST_CHECK(boost::lexical_cast(std::wstring(L"s")) == s); +#endif } #endif diff --git a/test/lexical_cast_float_types_test.cpp b/test/lexical_cast_float_types_test.cpp index 827b6ec..3df245b 100755 --- a/test/lexical_cast_float_types_test.cpp +++ b/test/lexical_cast_float_types_test.cpp @@ -105,13 +105,13 @@ void test_conversion_from_to_float_for_locale() /* - * Converts char* [and wchar_t] to float number type and checks, that generated - * number is in interval [base_value-epsilon, base_value+epsilon]. + * Converts char* [and wchar_t*] to float number type and checks, that generated + * number does not exceeds allowed epsilon. */ #ifndef BOOST_LCAST_NO_WCHAR_T #define CHECK_CLOSE_ABS_DIFF(VAL,PREFIX) \ converted_val = lexical_cast(#VAL); \ - BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits::epsilon()), \ + BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits::epsilon()), \ (converted_val ? converted_val : std::numeric_limits::epsilon()), \ std::numeric_limits::epsilon() \ ); \ @@ -120,7 +120,7 @@ void test_conversion_from_to_float_for_locale() #else #define CHECK_CLOSE_ABS_DIFF(VAL,TYPE) \ converted_val = lexical_cast(#VAL); \ - BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits::epsilon()), \ + BOOST_CHECK_CLOSE_FRACTION( (VAL ## L? VAL ## L : std::numeric_limits::epsilon()), \ (converted_val ? converted_val : std::numeric_limits::epsilon()), \ std::numeric_limits::epsilon() \ ); @@ -287,7 +287,7 @@ void test_float_typess_for_overflows() test_t minvalue = (std::numeric_limits::min)(); std::string s_min_value = lexical_cast(minvalue); BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast(minvalue), (std::numeric_limits::epsilon())); - BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast(s_min_value), (std::numeric_limits::epsilon())); + BOOST_CHECK_CLOSE_FRACTION(minvalue, lexical_cast(s_min_value), (std::numeric_limits::epsilon() * 2)); test_t maxvalue = (std::numeric_limits::max)(); std::string s_max_value = lexical_cast(maxvalue); @@ -326,13 +326,14 @@ void test_float_typess_for_overflows() #undef CHECK_CLOSE_ABS_DIFF +// Epsilon is multiplied by 2 because of two lexical conversions #define TEST_TO_FROM_CAST_AROUND_TYPED(VAL,STRING_TYPE) \ test_value = VAL + std::numeric_limits::epsilon() * i ; \ converted_val = lexical_cast( lexical_cast(test_value) ); \ - BOOST_CHECK_CLOSE_FRACTION( \ + BOOST_CHECK_CLOSE_FRACTION( \ test_value, \ converted_val, \ - std::numeric_limits::epsilon() \ + std::numeric_limits::epsilon() * 2 \ ); /*