Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58768 - trunk/libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2010-01-06 10:59:37


Author: hkaiser
Date: 2010-01-06 10:59:37 EST (Wed, 06 Jan 2010)
New Revision: 58768
URL: http://svn.boost.org/trac/boost/changeset/58768

Log:
Spirit: fixing Karma binary tests
Text files modified:
   trunk/libs/spirit/test/karma/binary.cpp | 5 ++---
   trunk/libs/spirit/test/karma/test.hpp | 27 +++++++++++++++++++++++++++
   2 files changed, 29 insertions(+), 3 deletions(-)

Modified: trunk/libs/spirit/test/karma/binary.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/binary.cpp (original)
+++ trunk/libs/spirit/test/karma/binary.cpp 2010-01-06 10:59:37 EST (Wed, 06 Jan 2010)
@@ -193,7 +193,7 @@
 
 #ifdef BOOST_LITTLE_ENDIAN
         BOOST_TEST(binary_test("\x01", 1, byte_, phoenix::val(0x01)));
- BOOST_TEST(binary_test("\x01\0x02", 2, byte_, phoenix::val(0x0201)));
+ BOOST_TEST(binary_test("\x01\x02", 2, word, phoenix::val(0x0201)));
         BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword,
             phoenix::val(0x04030201)));
 
@@ -223,8 +223,7 @@
 #else // BOOST_LITTLE_ENDIAN
 
         BOOST_TEST(binary_test("\x01", 1, byte_, phoenix::val(0x01)));
- BOOST_TEST(binary_test("\x01\x02", 2, byte_,
- phoenix::val(boost::uint16_t(0x0102))));
+ BOOST_TEST(binary_test("\x01\x02", 2, word, phoenix::val(0x0102)));
         BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword,
             phoenix::val(0x01020304)));
 

Modified: trunk/libs/spirit/test/karma/test.hpp
==============================================================================
--- trunk/libs/spirit/test/karma/test.hpp (original)
+++ trunk/libs/spirit/test/karma/test.hpp 2010-01-06 10:59:37 EST (Wed, 06 Jan 2010)
@@ -10,8 +10,10 @@
 #include <string>
 #include <iterator>
 #include <iostream>
+#include <iomanip>
 #include <typeinfo>
 
+#include <boost/foreach.hpp>
 #include <boost/spirit/include/karma_generate.hpp>
 #include <boost/spirit/include/karma_what.hpp>
 
@@ -57,6 +59,23 @@
     }
 
     ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename T>
+ void print_binary_if_failed(char const* func, bool result
+ , std::basic_string<Char> const& generated, T const& expected)
+ {
+ if (!result)
+ std::cerr << "in " << func << ": result is false" << std::endl;
+ else if (generated.size() != expected.size() ||
+ std::memcmp(generated.c_str(), expected.c_str(), generated.size()))
+ {
+ std::cerr << "in " << func << ": generated \"";
+ BOOST_FOREACH(int c, generated)
+ std::cerr << "\\x" << std::hex << std::setfill('0') << std::setw(2) << c;
+ std::cerr << "\"" << std::endl;
+ }
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
     template <typename Char, typename Generator>
     inline bool test(Char const *expected, Generator const& g)
     {
@@ -229,6 +248,8 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g);
 
+ print_binary_if_failed("binary_test", result, generated
+ , std::string(expected, size));
         return result && !std::memcmp(generated.c_str(), expected, size);
     }
 
@@ -249,6 +270,8 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate(outit, g, attrib);
 
+ print_binary_if_failed("binary_test", result, generated
+ , std::string(expected, size));
         return result && !std::memcmp(generated.c_str(), expected, size);
     }
 
@@ -269,6 +292,8 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d);
 
+ print_binary_if_failed("binary_test_delimited", result, generated
+ , std::string(expected, size));
         return result && !std::memcmp(generated.c_str(), expected, size);
     }
 
@@ -289,6 +314,8 @@
         std::back_insert_iterator<string_type> outit(generated);
         bool result = karma::generate_delimited(outit, g, d, attrib);
 
+ print_binary_if_failed("binary_test_delimited", result, generated
+ , std::string(expected, size));
         return result && !std::memcmp(generated.c_str(), expected, size);
     }
 


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