Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72014 - in sandbox/coerce: boost/coerce/detail libs/coerce/test
From: vexocide_at_[hidden]
Date: 2011-05-17 04:52:59


Author: vexocide
Date: 2011-05-17 04:52:57 EDT (Tue, 17 May 2011)
New Revision: 72014
URL: http://svn.boost.org/trac/boost/changeset/72014

Log:
Added a test for integral types
Added:
   sandbox/coerce/libs/coerce/test/integral.cpp (contents, props changed)
Text files modified:
   sandbox/coerce/boost/coerce/detail/qi.hpp | 2 +-
   sandbox/coerce/libs/coerce/test/Jamfile.v2 | 4 ++--
   2 files changed, 3 insertions(+), 3 deletions(-)

Modified: sandbox/coerce/boost/coerce/detail/qi.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/qi.hpp (original)
+++ sandbox/coerce/boost/coerce/detail/qi.hpp 2011-05-17 04:52:57 EDT (Tue, 17 May 2011)
@@ -11,7 +11,7 @@
 #pragma once
 #endif
 
-#include <boost/coerce/detail/reserve.hpp>
+#include <boost/coerce/reserve.hpp>
 
 #include <boost/range/begin.hpp>
 #include <boost/range/const_iterator.hpp>

Modified: sandbox/coerce/libs/coerce/test/Jamfile.v2
==============================================================================
--- sandbox/coerce/libs/coerce/test/Jamfile.v2 (original)
+++ sandbox/coerce/libs/coerce/test/Jamfile.v2 2011-05-17 04:52:57 EDT (Tue, 17 May 2011)
@@ -10,5 +10,5 @@
         <source>/boost//unit_test_framework
     ;
 
-unit-test reserve :
- reserve.cpp ;
+unit-test integral :
+ integral.cpp ;

Added: sandbox/coerce/libs/coerce/test/integral.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/test/integral.cpp 2011-05-17 04:52:57 EDT (Tue, 17 May 2011)
@@ -0,0 +1,110 @@
+// Copyright Jeroen Habraken 2010.
+//
+// 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 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>
+#include <boost/mpl/vector.hpp>
+#include <boost/test/unit_test.hpp>
+
+struct source_test {
+ template <typename T>
+ void
+ operator()(T) {
+ CHECK_EQUAL(std::string, static_cast<T>(0), "0");
+
+ CHECK_EQUAL(std::string, static_cast<T>(23), "23");
+ if (std::numeric_limits<T>::is_signed) {
+ CHECK_EQUAL(std::string, static_cast<T>(-23), "-23");
+ }
+ }
+};
+
+BOOST_AUTO_TEST_CASE(source) {
+ source_test test;
+
+ typedef boost::mpl::vector<
+#ifdef BOOST_HAS_LONG_LONG
+ boost::long_long_type,
+ boost::ulong_long_type,
+#endif
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ unsigned long
+ > integral_types;
+
+ boost::mpl::for_each<integral_types>(test);
+}
+
+struct target_test {
+ template <typename T>
+ void
+ operator()(T) {
+ CHECK_EQUAL(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));
+ }
+
+ CHECK_THROW(T, "");
+ CHECK_THROW(T, "+");
+ CHECK_THROW(T, "-");
+
+ CHECK_EQUAL(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));
+ }
+
+ CHECK_EQUAL(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));
+ }
+
+ 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_EQUAL(T, "23\0X", static_cast<T>(23));
+
+ CHECK_THROW(T, "XXX");
+ }
+};
+
+BOOST_AUTO_TEST_CASE(target) {
+ target_test test;
+
+ typedef boost::mpl::vector<
+#ifdef BOOST_HAS_LONG_LONG
+ boost::long_long_type,
+ boost::ulong_long_type,
+#endif
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ unsigned long
+ > integral_types;
+
+ boost::mpl::for_each<integral_types>(test);
+}


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