Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73408 - sandbox/coerce/libs/coerce/test
From: vexocide_at_[hidden]
Date: 2011-07-28 07:01:09


Author: vexocide
Date: 2011-07-28 07:01:07 EDT (Thu, 28 Jul 2011)
New Revision: 73408
URL: http://svn.boost.org/trac/boost/changeset/73408

Log:
Added tests for tags and added missing includes
Added:
   sandbox/coerce/libs/coerce/test/tag.cpp (contents, props changed)
Text files modified:
   sandbox/coerce/libs/coerce/test/Jamfile.v2 | 3 +++
   sandbox/coerce/libs/coerce/test/bool.cpp | 2 ++
   sandbox/coerce/libs/coerce/test/char.cpp | 2 ++
   sandbox/coerce/libs/coerce/test/floating_point.cpp | 2 ++
   sandbox/coerce/libs/coerce/test/integral.cpp | 2 ++
   sandbox/coerce/libs/coerce/test/wchar_t.cpp | 2 ++
   6 files changed, 13 insertions(+), 0 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-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -33,6 +33,9 @@
 unit-test reserve :
     reserve.cpp ;
 
+unit-test tag :
+ tag.cpp ;
+
 unit-test qi :
     qi.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-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -11,6 +11,8 @@
 #include <boost/coerce.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <string>
+
 BOOST_AUTO_TEST_CASE(source) {
     using namespace boost;
 

Modified: sandbox/coerce/libs/coerce/test/char.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/char.cpp (original)
+++ sandbox/coerce/libs/coerce/test/char.cpp 2011-07-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -11,6 +11,8 @@
 #include <boost/coerce.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <string>
+
 BOOST_AUTO_TEST_CASE(source) {
     using namespace boost;
 

Modified: sandbox/coerce/libs/coerce/test/floating_point.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/floating_point.cpp (original)
+++ sandbox/coerce/libs/coerce/test/floating_point.cpp 2011-07-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -16,6 +16,8 @@
 #include <boost/test/floating_point_comparison.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <string>
+
 struct source_test {
     template <typename T>
     void

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-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -14,6 +14,8 @@
 #include <boost/mpl/vector.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <string>
+
 struct source_test {
     template <typename T>
     void

Added: sandbox/coerce/libs/coerce/test/tag.cpp
==============================================================================
--- (empty file)
+++ sandbox/coerce/libs/coerce/test/tag.cpp 2011-07-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,106 @@
+// 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 tag
+
+#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
+
+#include <boost/coerce.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include <string>
+
+struct source_test {
+ template <typename T>
+ void
+ operator()(T) {
+ using namespace boost;
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<std::string>(
+ static_cast<T>(23), coerce::tag::base<10>()),
+ "23");
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<std::string>(static_cast<T>(23), coerce::tag::bin()),
+ "10111");
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<std::string>(static_cast<T>(23), coerce::tag::oct()),
+ "27");
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<std::string>(static_cast<T>(23), coerce::tag::hex()),
+ "17");
+ }
+};
+
+BOOST_AUTO_TEST_CASE(source) {
+ source_test test;
+
+ typedef boost::mpl::vector<
+ short
+ , unsigned short
+ , int
+ , unsigned int
+ , long
+ , unsigned long
+#ifdef BOOST_HAS_LONG_LONG
+ , boost::long_long_type
+ , boost::ulong_long_type
+#endif
+ > integral_types;
+
+ boost::mpl::for_each<integral_types>(test);
+}
+
+struct target_test {
+ template <typename T>
+ void
+ operator()(T) {
+ using namespace boost;
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<T>("23", coerce::tag::base<10>()), static_cast<T>(23));
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<T>("10111", coerce::tag::bin()), static_cast<T>(23));
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<T>("27", coerce::tag::oct()), static_cast<T>(23));
+
+ BOOST_CHECK_EQUAL(
+ coerce::as<T>("17", coerce::tag::hex()), static_cast<T>(23));
+ BOOST_CHECK_EQUAL(
+ coerce::as<T>("0x17", coerce::tag::hex()), static_cast<T>(23));
+
+ BOOST_CHECK_THROW(
+ coerce::as<T>("23X", coerce::tag::base<10>()), coerce::bad_cast);
+ BOOST_CHECK_THROW(
+ coerce::as<T>("XXX", coerce::tag::base<10>()), coerce::bad_cast);
+ }
+};
+
+BOOST_AUTO_TEST_CASE(target) {
+ target_test test;
+
+ typedef boost::mpl::vector<
+ short
+ , unsigned short
+ , int
+ , unsigned int
+ , long
+ , unsigned long
+#ifdef BOOST_HAS_LONG_LONG
+ , boost::long_long_type
+ , boost::ulong_long_type
+#endif
+ > integral_types;
+
+ boost::mpl::for_each<integral_types>(test);
+}

Modified: sandbox/coerce/libs/coerce/test/wchar_t.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/wchar_t.cpp (original)
+++ sandbox/coerce/libs/coerce/test/wchar_t.cpp 2011-07-28 07:01:07 EDT (Thu, 28 Jul 2011)
@@ -12,6 +12,8 @@
 #include <boost/config.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <string>
+
 BOOST_AUTO_TEST_CASE(source) {
     using namespace boost;
 


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