|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75283 - in trunk: boost libs/conversion/test
From: antoshkka_at_[hidden]
Date: 2011-11-03 00:34:01
Author: apolukhin
Date: 2011-11-03 00:33:58 EDT (Thu, 03 Nov 2011)
New Revision: 75283
URL: http://svn.boost.org/trac/boost/changeset/75283
Log:
Fix for error noticed by Olaf van der Spek (ticket #6083)
Added test case for that error
Added:
trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp (contents, props changed)
Text files modified:
trunk/boost/lexical_cast.hpp | 2 +-
trunk/libs/conversion/test/Jamfile.v2 | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
Modified: trunk/boost/lexical_cast.hpp
==============================================================================
--- trunk/boost/lexical_cast.hpp (original)
+++ trunk/boost/lexical_cast.hpp 2011-11-03 00:33:58 EDT (Thu, 03 Nov 2011)
@@ -1181,7 +1181,7 @@
bool const result = !(stream << input).fail();
start = stringbuffer.pbase();
finish = stringbuffer.pptr();
- return result;
+ return result && (start != finish);
}
template <class T>
Modified: trunk/libs/conversion/test/Jamfile.v2
==============================================================================
--- trunk/libs/conversion/test/Jamfile.v2 (original)
+++ trunk/libs/conversion/test/Jamfile.v2 2011-11-03 00:33:58 EDT (Thu, 03 Nov 2011)
@@ -29,6 +29,7 @@
[ run lexical_cast_float_types_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
[ run lexical_cast_inf_nan_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
[ run lexical_cast_containers_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
+ [ run lexical_cast_empty_input_test.cpp ../../test/build//boost_unit_test_framework/<link>static ]
;
Added: trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/conversion/test/lexical_cast_empty_input_test.cpp 2011-11-03 00:33:58 EDT (Thu, 03 Nov 2011)
@@ -0,0 +1,58 @@
+// Unit test for boost::lexical_cast.
+//
+// See http://www.boost.org for most recent version, including documentation.
+//
+// Copyright Antony Polukhin, 2011.
+//
+// Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
+
+#include <boost/config.hpp>
+
+#if defined(__INTEL_COMPILER)
+#pragma warning(disable: 193 383 488 981 1418 1419)
+#elif defined(BOOST_MSVC)
+#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
+#endif
+
+#include <boost/lexical_cast.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/range/iterator_range.hpp>
+
+using namespace boost;
+
+void test_empty_iterator_range()
+{
+ boost::iterator_range<const char*> v;
+ BOOST_CHECK_THROW(lexical_cast<int>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<float>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<double>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<long double>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned int>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<std::string>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned short>(v), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<char>(v), bad_lexical_cast);
+}
+
+void test_empty_string()
+{
+ BOOST_CHECK_THROW(lexical_cast<int>(std::string()), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<float>(std::string()), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<double>(std::string()), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<long double>(std::string()), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<unsigned int>(std::string()), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(lexical_cast<std::string>(std::string()), std::string());
+ BOOST_CHECK_THROW(lexical_cast<unsigned short>(std::string()), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<char>(std::string()), bad_lexical_cast);
+}
+
+unit_test::test_suite *init_unit_test_suite(int, char *[])
+{
+ unit_test::test_suite *suite =
+ BOOST_TEST_SUITE("lexical_cast. Empty input unit test");
+ suite->add(BOOST_TEST_CASE(&test_empty_iterator_range));
+ suite->add(BOOST_TEST_CASE(&test_empty_string));
+
+ return suite;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk