Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62116 - trunk/libs/spirit/test/qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-05-20 13:25:10


Author: hkaiser
Date: 2010-05-20 13:25:08 EDT (Thu, 20 May 2010)
New Revision: 62116
URL: http://svn.boost.org/trac/boost/changeset/62116

Log:
Spirit: Added tests to ensure numeric overflow leads to failing parse
Text files modified:
   trunk/libs/spirit/test/qi/int.cpp | 12 ++++++++++++
   trunk/libs/spirit/test/qi/rule.cpp | 10 ++++++++++
   trunk/libs/spirit/test/qi/uint.cpp | 6 ++++--
   3 files changed, 26 insertions(+), 2 deletions(-)

Modified: trunk/libs/spirit/test/qi/int.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/int.cpp (original)
+++ trunk/libs/spirit/test/qi/int.cpp 2010-05-20 13:25:08 EDT (Thu, 20 May 2010)
@@ -174,6 +174,18 @@
     }
 
     ///////////////////////////////////////////////////////////////////////////
+ // Check overflow is parse error
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ boost::spirit::qi::int_parser<boost::int8_t> int8_;
+ boost::spirit::qi::int_parser<boost::int16_t> int16_;
+ char c;
+
+ BOOST_TEST(!test_attr("999", int8_, c));
+ BOOST_TEST(!test_attr("999", int16_, c));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
     // int_parser<unused_type> tests
     ///////////////////////////////////////////////////////////////////////////
     {

Modified: trunk/libs/spirit/test/qi/rule.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/rule.cpp (original)
+++ trunk/libs/spirit/test/qi/rule.cpp 2010-05-20 13:25:08 EDT (Thu, 20 May 2010)
@@ -39,6 +39,7 @@
     using boost::spirit::qi::locals;
     using boost::spirit::qi::rule;
     using boost::spirit::qi::int_;
+ using boost::spirit::qi::uint_;
     using boost::spirit::qi::fail;
     using boost::spirit::qi::on_error;
     using boost::spirit::qi::debug;
@@ -474,6 +475,15 @@
         BOOST_TEST(test_attr("1", r, v) && at_c<0>(v) == 1);
     }
 
+ {
+ using boost::fusion::vector;
+ using boost::fusion::at_c;
+ rule<const char*, vector<unsigned int>()> r = uint_;
+
+ vector<unsigned int> v = 0;
+ BOOST_TEST(test_attr("1", r, v) && at_c<0>(v) == 1);
+ }
+
     return boost::report_errors();
 }
 

Modified: trunk/libs/spirit/test/qi/uint.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/uint.cpp (original)
+++ trunk/libs/spirit/test/qi/uint.cpp 2010-05-20 13:25:08 EDT (Thu, 20 May 2010)
@@ -202,10 +202,12 @@
     // Check overflow is parse error
     ///////////////////////////////////////////////////////////////////////////
     {
- boost::spirit::qi::uint_parser<boost::uint8_t> uint_;
+ boost::spirit::qi::uint_parser<boost::uint8_t> uint8_;
+ boost::spirit::qi::uint_parser<boost::uint16_t> uint16_;
         boost::uint8_t u;
 
- BOOST_TEST(!test_attr("999", uint_, u));
+ BOOST_TEST(!test_attr("999", uint8_, u));
+ BOOST_TEST(!test_attr("999", uint16_, u));
     }
 
     ///////////////////////////////////////////////////////////////////////////


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