Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72918 - sandbox/coerce/libs/coerce/test
From: vexocide_at_[hidden]
Date: 2011-07-05 08:27:51


Author: vexocide
Date: 2011-07-05 08:27:49 EDT (Tue, 05 Jul 2011)
New Revision: 72918
URL: http://svn.boost.org/trac/boost/changeset/72918

Log:
Added more tests and refactored the integral tests
Added:
   sandbox/coerce/libs/coerce/test/bool.cpp (contents, props changed)
Text files modified:
   sandbox/coerce/libs/coerce/test/Jamfile.v2 | 3 +
   sandbox/coerce/libs/coerce/test/integral.cpp | 61 +++++++++++++++++++--------------------
   sandbox/coerce/libs/coerce/test/qi.cpp | 7 ++++
   3 files changed, 40 insertions(+), 31 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-05 08:27:49 EDT (Tue, 05 Jul 2011)
@@ -10,6 +10,9 @@
         <source>/boost//unit_test_framework
     ;
 
+unit-test bool :
+ bool.cpp ;
+
 unit-test integral :
     integral.cpp ;
 

Added: sandbox/coerce/libs/coerce/test/bool.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/test/bool.cpp 2011-07-05 08:27:49 EDT (Tue, 05 Jul 2011)
@@ -0,0 +1,29 @@
+// 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 bool_
+
+#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>(true), "true");
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(false), "false");
+}
+
+BOOST_AUTO_TEST_CASE(target) {
+ using namespace boost;
+
+ 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);
+}

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-05 08:27:49 EDT (Tue, 05 Jul 2011)
@@ -6,12 +6,6 @@
 
 #define BOOST_TEST_MODULE integral
 
-#define CHECK_EQUAL(type, source, target) \
- BOOST_CHECK_EQUAL(boost::coerce::as<type>(source), target)
-
-#define CHECK_THROW(type, source) \
- BOOST_CHECK_THROW(boost::coerce::as<type>(source), boost::coerce::bad_cast)
-
 #include <boost/coerce.hpp>
 #include <boost/limits.hpp>
 #include <boost/mpl/for_each.hpp>
@@ -22,11 +16,14 @@
     template <typename T>
     void
     operator()(T) {
- CHECK_EQUAL(std::string, static_cast<T>(0), "0");
+ using namespace boost;
+
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(static_cast<T>(0)), "0");
 
- CHECK_EQUAL(std::string, static_cast<T>(23), "23");
+ BOOST_CHECK_EQUAL(coerce::as<std::string>(static_cast<T>(23)), "23");
         if (std::numeric_limits<T>::is_signed) {
- CHECK_EQUAL(std::string, static_cast<T>(-23), "-23");
+ BOOST_CHECK_EQUAL(
+ coerce::as<std::string>(static_cast<T>(-23)), "-23");
         }
     }
 };
@@ -54,39 +51,41 @@
     template <typename T>
     void
     operator()(T) {
- CHECK_EQUAL(T, "0", static_cast<T>(0));
+ using namespace boost;
+
+ BOOST_CHECK_EQUAL(coerce::as<T>("0"), static_cast<T>(0));
         if (std::numeric_limits<T>::is_signed) {
- CHECK_EQUAL(T, "+0", static_cast<T>(0));
- CHECK_EQUAL(T, "-0", static_cast<T>(0));
+ BOOST_CHECK_EQUAL(coerce::as<T>("+0"), static_cast<T>(0));
+ BOOST_CHECK_EQUAL(coerce::as<T>("-0"), static_cast<T>(0));
         }
 
- CHECK_THROW(T, "");
- CHECK_THROW(T, "+");
- CHECK_THROW(T, "-");
+ BOOST_CHECK_THROW(coerce::as<T>(""), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("+"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("-"), coerce::bad_cast);
 
- CHECK_EQUAL(T, "23", static_cast<T>(23));
+ BOOST_CHECK_EQUAL(coerce::as<T>("23"), static_cast<T>(23));
         if (std::numeric_limits<T>::is_signed) {
- CHECK_EQUAL(T, "+23", static_cast<T>(23));
- CHECK_EQUAL(T, "-23", static_cast<T>(-23));
+ BOOST_CHECK_EQUAL(coerce::as<T>("23"), static_cast<T>(23));
+ BOOST_CHECK_EQUAL(coerce::as<T>("-23"), static_cast<T>(-23));
         }
 
- CHECK_EQUAL(T, "00023", static_cast<T>(23));
+ BOOST_CHECK_EQUAL(coerce::as<T>("00023"), static_cast<T>(23));
         if (std::numeric_limits<T>::is_signed) {
- CHECK_EQUAL(T, "+00023", static_cast<T>(23));
- CHECK_EQUAL(T, "-00023", static_cast<T>(-23));
+ BOOST_CHECK_EQUAL(coerce::as<T>("+00023"), static_cast<T>(23));
+ BOOST_CHECK_EQUAL(coerce::as<T>("-00023"), static_cast<T>(-23));
         }
 
- CHECK_THROW(T, " 23");
- CHECK_THROW(T, "23 ");
- CHECK_THROW(T, " 23 ");
-
- CHECK_THROW(T, "18446744073709551616");
- CHECK_THROW(T, "-9223372036854775809");
-
- CHECK_THROW(T, "23X");
- CHECK_THROW(T, "23\0X");
+ 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>("18446744073709551616"), coerce::bad_cast);
+ BOOST_CHECK_THROW(
+ coerce::as<T>("-9223372036854775809"), coerce::bad_cast);
 
- CHECK_THROW(T, "XXX");
+ BOOST_CHECK_THROW(coerce::as<T>("23X"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<T>("XXX"), coerce::bad_cast);
     }
 };
 

Modified: sandbox/coerce/libs/coerce/test/qi.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/qi.cpp (original)
+++ sandbox/coerce/libs/coerce/test/qi.cpp 2011-07-05 08:27:49 EDT (Tue, 05 Jul 2011)
@@ -55,3 +55,10 @@
     BOOST_CHECK_EQUAL(coerce::as<int>(std::string("1")), 1);
     BOOST_CHECK_EQUAL(coerce::as<int>(std::wstring(L"1")), 1);
 }
+
+BOOST_AUTO_TEST_CASE(throw_) {
+ using namespace boost;
+
+ BOOST_CHECK_THROW(coerce::as<int>("1\0"), coerce::bad_cast);
+ BOOST_CHECK_THROW(coerce::as<int>("1\0" "1"), coerce::bad_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