|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72952 - sandbox/coerce/libs/coerce/test
From: vexocide_at_[hidden]
Date: 2011-07-07 05:43:44
Author: vexocide
Date: 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
New Revision: 72952
URL: http://svn.boost.org/trac/boost/changeset/72952
Log:
More tests
Added:
sandbox/coerce/libs/coerce/test/char.cpp (contents, props changed)
sandbox/coerce/libs/coerce/test/default.cpp (contents, props changed)
sandbox/coerce/libs/coerce/test/wchar_t.cpp (contents, props changed)
Text files modified:
sandbox/coerce/libs/coerce/test/Jamfile.v2 | 9 ++++
sandbox/coerce/libs/coerce/test/bool.cpp | 75 ++++++++++++++++++++++++++++++++++++++-
sandbox/coerce/libs/coerce/test/integral.cpp | 73 ++++++++++++++++++++++++++++++++++++++
3 files changed, 154 insertions(+), 3 deletions(-)
Modified: sandbox/coerce/libs/coerce/test/Jamfile.v2
==============================================================================
--- sandbox/coerce/libs/coerce/test/Jamfile.v2 (original)
+++ sandbox/coerce/libs/coerce/test/Jamfile.v2 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
@@ -13,6 +13,12 @@
unit-test bool :
bool.cpp ;
+unit-test char :
+ char.cpp ;
+
+unit-test default_ :
+ default.cpp ;
+
unit-test integral :
integral.cpp ;
@@ -24,3 +30,6 @@
unit-test qi :
qi.cpp ;
+
+unit-test wchar_t :
+ wchar_t.cpp ;
Modified: sandbox/coerce/libs/coerce/test/bool.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/bool.cpp (original)
+++ sandbox/coerce/libs/coerce/test/bool.cpp 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
@@ -4,7 +4,7 @@
// (See accompanying file ../../../LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#define BOOST_TEST_MODULE bool_
+#define BOOST_TEST_MODULE bool
#include <boost/coerce.hpp>
#include <boost/test/unit_test.hpp>
@@ -19,11 +19,80 @@
BOOST_AUTO_TEST_CASE(target) {
using namespace boost;
+ BOOST_CHECK_THROW(coerce::as<bool>(""), coerce::bad_cast);
+
BOOST_CHECK_EQUAL(coerce::as<bool>("true"), true);
BOOST_CHECK_EQUAL(coerce::as<bool>("false"), false);
- BOOST_CHECK_THROW(coerce::as<bool>(""), coerce::bad_cast);
-
BOOST_CHECK_THROW(coerce::as<bool>("trueX"), coerce::bad_cast);
BOOST_CHECK_THROW(coerce::as<bool>("XXX"), coerce::bad_cast);
}
+
+/* lexical_cast
+
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>('1'));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>('0'));
+ BOOST_CHECK_THROW(lexical_cast<bool>('A'), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>(1));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>(0));
+ BOOST_CHECK_THROW(lexical_cast<bool>(123), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>(1.0));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>(0.0));
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>(true));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>(false));
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>("1"));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>("0"));
+ BOOST_CHECK_THROW(lexical_cast<bool>(""), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<bool>("Test"), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>("1"));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>("0"));
+ BOOST_CHECK_EQUAL(true, lexical_cast<bool>(std::string("1")));
+ BOOST_CHECK_EQUAL(false, lexical_cast<bool>(std::string("0")));
+
+ BOOST_CHECK_THROW(lexical_cast<bool>(1.0001L), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<bool>(2), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<bool>(2u), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<bool>(-1), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<bool>(-2), bad_lexical_cast);
+
+
+ BOOST_CHECK_THROW(
+ lexical_cast<bool>(std::string("")), bad_lexical_cast);
+ BOOST_CHECK_THROW(
+ lexical_cast<bool>(std::string("Test")), bad_lexical_cast);
+
+ BOOST_CHECK(lexical_cast<bool>("+1") == true );
+ BOOST_CHECK(lexical_cast<bool>("+0") == false );
+ BOOST_CHECK(lexical_cast<bool>("-0") == false );
+ BOOST_CHECK_THROW(lexical_cast<bool>("--0"), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<bool>("-+-0"), bad_lexical_cast);
+*/
+
+/* convert
+
+ convert<bool>::result bool_res1 = convert<bool>::from("1", false);
+ convert<bool>::result bool_res2 = convert<bool>::from("true", false);
+ convert<bool>::result bool_res3 = convert<bool>::from("yes", false);
+ convert<bool>::result bool_res4 = convert<bool>::from(L"1", false);
+ convert<bool>::result bool_res5 = convert<bool>::from(L"true", false);
+ convert<bool>::result bool_res6 = convert<bool>::from(L"yes", false);
+ convert<bool>::result bool_res7 = convert<bool>::from("junk", true);
+
+ BOOST_ASSERT( bool_res1 && bool_res1.value() == true);
+ BOOST_ASSERT( bool_res2 && bool_res2.value() == true);
+ BOOST_ASSERT( bool_res3 && bool_res3.value() == true);
+ BOOST_ASSERT( bool_res4 && bool_res4.value() == true);
+ BOOST_ASSERT( bool_res5 && bool_res5.value() == true);
+ BOOST_ASSERT( bool_res6 && bool_res6.value() == true);
+ BOOST_ASSERT(!bool_res7 && bool_res7.value() == true);
+
+ string bool_str1 = convert<string>::from(true, "failed");
+ string bool_str2 = convert<string>::from(false, "failed");
+ string bool_str3 = convert<string>::from(1, "failed");
+ string bool_str4 = convert<string>::from(0, "failed");
+
+ BOOST_ASSERT(bool_str1 == "1");
+ BOOST_ASSERT(bool_str2 == "0");
+ BOOST_ASSERT(bool_str3 == "1");
+ BOOST_ASSERT(bool_str4 == "0");
+*/
Added: sandbox/coerce/libs/coerce/test/char.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/test/char.cpp 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
@@ -0,0 +1,56 @@
+// Copyright Jeroen Habraken 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)
+
+#define BOOST_TEST_MODULE char
+
+#include <boost/coerce.hpp>
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE(source) {
+ using namespace boost;
+
+ BOOST_CHECK_EQUAL(coerce::as<std::string>('\0'), std::string("\0", 1));
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(' '), " ");
+ BOOST_CHECK_EQUAL(coerce::as<std::string>('\x23'), "\x23");
+ BOOST_CHECK_EQUAL(coerce::as<std::string>('A'), "A");
+}
+
+BOOST_AUTO_TEST_CASE(target) {
+ using namespace boost;
+
+ BOOST_CHECK_THROW(coerce::as<char>(""), coerce::bad_cast);
+
+ BOOST_CHECK_EQUAL(coerce::as<char>("\0"), '\0');
+ BOOST_CHECK_EQUAL(coerce::as<char>(" "), ' ');
+ BOOST_CHECK_EQUAL(coerce::as<char>("\x17"), '\x17');
+ BOOST_CHECK_EQUAL(coerce::as<char>("A"), 'A');
+
+ BOOST_CHECK_THROW(coerce::as<char>(L"\u2345"), coerce::bad_cast);
+
+ BOOST_CHECK_THROW(coerce::as<char>("XXX"), coerce::bad_cast);
+}
+
+/* lexical_cast
+
+ BOOST_CHECK_EQUAL('A', lexical_cast<char>('A'));
+ BOOST_CHECK_EQUAL(' ', lexical_cast<char>(' '));
+ BOOST_CHECK_EQUAL('1', lexical_cast<char>(1));
+ BOOST_CHECK_EQUAL('0', lexical_cast<char>(0));
+ BOOST_CHECK_THROW(lexical_cast<char>(123), bad_lexical_cast);
+ BOOST_CHECK_EQUAL('1', lexical_cast<char>(1.0));
+ BOOST_CHECK_EQUAL('1', lexical_cast<char>(true));
+ BOOST_CHECK_EQUAL('0', lexical_cast<char>(false));
+ BOOST_CHECK_EQUAL('A', lexical_cast<char>("A"));
+ BOOST_CHECK_EQUAL(' ', lexical_cast<char>(" "));
+ BOOST_CHECK_THROW(lexical_cast<char>(""), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<char>("Test"), bad_lexical_cast);
+ BOOST_CHECK_EQUAL('A', lexical_cast<char>(std::string("A")));
+ BOOST_CHECK_EQUAL(' ', lexical_cast<char>(std::string(" ")));
+ BOOST_CHECK_THROW(
+ lexical_cast<char>(std::string("")), bad_lexical_cast);
+ BOOST_CHECK_THROW(
+ lexical_cast<char>(std::string("Test")), bad_lexical_cast);
+*/
Added: sandbox/coerce/libs/coerce/test/default.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/test/default.cpp 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
@@ -0,0 +1,17 @@
+// Copyright Jeroen Habraken 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)
+
+#define BOOST_TEST_MODULE default
+
+#include <boost/coerce.hpp>
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE(default_) {
+ using namespace boost;
+
+ BOOST_CHECK_EQUAL(coerce::as_default<int>("XXX"), 0);
+ BOOST_CHECK_EQUAL(coerce::as_default<int>("XXX", 23), 23);
+}
Modified: sandbox/coerce/libs/coerce/test/integral.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/integral.cpp (original)
+++ sandbox/coerce/libs/coerce/test/integral.cpp 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
@@ -69,6 +69,11 @@
BOOST_CHECK_EQUAL(coerce::as<T>("-23"), static_cast<T>(-23));
}
+ BOOST_CHECK_THROW(coerce::as<T>("++23"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("+-23"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("-+23"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("--23"), coerce::bad_cast);
+
BOOST_CHECK_EQUAL(coerce::as<T>("00023"), static_cast<T>(23));
if (std::numeric_limits<T>::is_signed) {
BOOST_CHECK_EQUAL(coerce::as<T>("+00023"), static_cast<T>(23));
@@ -79,6 +84,10 @@
BOOST_CHECK_THROW(coerce::as<T>("23 "), coerce::bad_cast);
BOOST_CHECK_THROW(coerce::as<T>(" 23 "), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("23.0"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("+23.0"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("-23.0"), coerce::bad_cast);
+
BOOST_CHECK_THROW(
coerce::as<T>("18446744073709551616"), coerce::bad_cast);
BOOST_CHECK_THROW(
@@ -107,3 +116,67 @@
boost::mpl::for_each<integral_types>(test);
}
+
+/* lexical_cast
+
+ BOOST_CHECK_EQUAL(1, lexical_cast<int>('1'));
+ BOOST_CHECK_EQUAL(0, lexical_cast<int>('0'));
+ BOOST_CHECK_THROW(lexical_cast<int>('A'), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(1, lexical_cast<int>(1));
+ BOOST_CHECK_EQUAL(1, lexical_cast<int>(1.0));
+
+ BOOST_CHECK_EQUAL(
+ (std::numeric_limits<int>::max)(),
+ lexical_cast<int>((std::numeric_limits<int>::max)()));
+
+ BOOST_CHECK_EQUAL(
+ (std::numeric_limits<int>::min)(),
+ lexical_cast<int>((std::numeric_limits<int>::min)()));
+
+ BOOST_CHECK_THROW(lexical_cast<int>(1.23), bad_lexical_cast);
+
+ BOOST_CHECK_THROW(lexical_cast<int>(1e20), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(1, lexical_cast<int>(true));
+ BOOST_CHECK_EQUAL(0, lexical_cast<int>(false));
+ BOOST_CHECK_EQUAL(123, lexical_cast<int>("123"));
+ BOOST_CHECK_THROW(
+ lexical_cast<int>(" 123"), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<int>(""), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<int>("Test"), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(123, lexical_cast<int>("123"));
+ BOOST_CHECK_EQUAL(123, lexical_cast<int>(std::string("123")));
+ BOOST_CHECK_THROW(
+ lexical_cast<int>(std::string(" 123")), bad_lexical_cast);
+ BOOST_CHECK_THROW(
+ lexical_cast<int>(std::string("")), bad_lexical_cast);
+ BOOST_CHECK_THROW(
+ lexical_cast<int>(std::string("Test")), bad_lexical_cast);
+
+ BOOST_CHECK(lexical_cast<T>("-1") == static_cast<T>(-1));
+ BOOST_CHECK(lexical_cast<T>("-9") == static_cast<T>(-9));
+ BOOST_CHECK(lexical_cast<T>(-1) == static_cast<T>(-1));
+ BOOST_CHECK(lexical_cast<T>(-9) == static_cast<T>(-9));
+
+ BOOST_CHECK_THROW(lexical_cast<T>("-1.0"), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>("-9.0"), bad_lexical_cast);
+ BOOST_CHECK(lexical_cast<T>(-1.0) == static_cast<T>(-1));
+ BOOST_CHECK(lexical_cast<T>(-9.0) == static_cast<T>(-9));
+
+ BOOST_CHECK(lexical_cast<T>(static_cast<T>(1)) == static_cast<T>(1));
+ BOOST_CHECK(lexical_cast<T>(static_cast<T>(9)) == static_cast<T>(9));
+ BOOST_CHECK_THROW(lexical_cast<T>(1.1f), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>(1.1), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>(1.1L), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>(1.0001f), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>(1.0001), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>(1.0001L), bad_lexical_cast);
+
+ BOOST_CHECK(lexical_cast<T>("+1") == static_cast<T>(1) );
+ BOOST_CHECK(lexical_cast<T>("+9") == static_cast<T>(9) );
+ BOOST_CHECK(lexical_cast<T>("+10") == static_cast<T>(10) );
+ BOOST_CHECK(lexical_cast<T>("+90") == static_cast<T>(90) );
+ BOOST_CHECK_THROW(lexical_cast<T>("++1"), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>("-+9"), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>("--1"), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<T>("+-9"), bad_lexical_cast);
+*/
Added: sandbox/coerce/libs/coerce/test/wchar_t.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/test/wchar_t.cpp 2011-07-07 05:43:42 EDT (Thu, 07 Jul 2011)
@@ -0,0 +1,62 @@
+// Copyright Jeroen Habraken 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)
+
+#define BOOST_TEST_MODULE wchar_t
+
+#include <boost/coerce.hpp>
+#include <boost/config.hpp>
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE(source) {
+ using namespace boost;
+
+#ifndef BOOST_NO_INTRINSIC_WCHAR_T
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(L'\0'), std::string("\0", 1));
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(L' '), " ");
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(L'\x23'), "\x23");
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(L'A'), "A");
+#endif
+}
+
+BOOST_AUTO_TEST_CASE(target) {
+ using namespace boost;
+
+#ifndef BOOST_NO_INTRINSIC_WCHAR_T
+ BOOST_CHECK_THROW(coerce::as<wchar_t>(""), coerce::bad_cast);
+
+ BOOST_CHECK_EQUAL(coerce::as<wchar_t>("\0"), L'\0');
+ BOOST_CHECK_EQUAL(coerce::as<wchar_t>(" "), L' ');
+ BOOST_CHECK_EQUAL(coerce::as<wchar_t>("\x23"), L'\x23');
+ BOOST_CHECK_EQUAL(coerce::as<wchar_t>("A"), L'A');
+
+ BOOST_CHECK_THROW(coerce::as<wchar_t>("XXX"), coerce::bad_cast);
+#endif
+}
+
+/* lexical_cast
+
+ BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(1));
+ BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(0));
+ BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>('1'));
+ BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>('0'));
+ BOOST_CHECK_THROW(lexical_cast<wchar_t>(123), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(1.0));
+ BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(0.0));
+ BOOST_CHECK_EQUAL(L'1', lexical_cast<wchar_t>(true));
+ BOOST_CHECK_EQUAL(L'0', lexical_cast<wchar_t>(false));
+ BOOST_CHECK_EQUAL(L'A', lexical_cast<wchar_t>(L'A'));
+ BOOST_CHECK_EQUAL(L' ', lexical_cast<wchar_t>(L' '));
+ BOOST_CHECK_EQUAL(L'A', lexical_cast<wchar_t>(L"A"));
+ BOOST_CHECK_EQUAL(L' ', lexical_cast<wchar_t>(L" "));
+ BOOST_CHECK_THROW(lexical_cast<wchar_t>(L""), bad_lexical_cast);
+ BOOST_CHECK_THROW(lexical_cast<wchar_t>(L"Test"), bad_lexical_cast);
+ BOOST_CHECK_EQUAL(L'A', lexical_cast<wchar_t>(std::wstring(L"A")));
+ BOOST_CHECK_EQUAL(L' ', lexical_cast<wchar_t>(std::wstring(L" ")));
+ BOOST_CHECK_THROW(
+ lexical_cast<wchar_t>(std::wstring(L"")), bad_lexical_cast);
+ BOOST_CHECK_THROW(
+ lexical_cast<wchar_t>(std::wstring(L"Test")), bad_lexical_cast);
+*/
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