2 Copyright (c) Marshall Clow 2011-2012.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 For more information, see http://www.boost.org
12 #include <boost/config.hpp>
13 #include <boost/algorithm/hex.hpp>
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp>
21 namespace ba = boost::algorithm;
23 void test_short_input1 () {
26 try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
27 catch ( const std::exception &ex ) { return; }
28 BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_short_input1" );
29 BOOST_CHECK ( false );
32 void test_short_input2 () {
35 try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
36 catch ( const ba::hex_decode_error &ex ) { return; }
37 BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_short_input2" );
38 BOOST_CHECK ( false );
41 void test_short_input3 () {
44 try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
45 catch ( const ba::not_enough_input &ex ) { return; }
46 BOOST_TEST_MESSAGE ( "Failed to catch ba::not_enough_input in test_short_input3" );
47 BOOST_CHECK ( false );
50 // Make sure that the right thing is thrown
51 void test_short_input4 () {
54 try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
55 catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
56 catch ( const ba::not_enough_input &ex ) { return; }
57 catch ( ... ) { BOOST_CHECK ( false ); }
58 BOOST_CHECK ( false );
61 // Make sure that the right thing is thrown
62 void test_short_input5 () {
65 try { ba::unhex ( "A", std::back_inserter(s)); }
66 catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
67 catch ( const ba::not_enough_input &ex ) { return; }
68 catch ( ... ) { BOOST_CHECK ( false ); }
69 BOOST_CHECK ( false );
73 void test_short_input () {
74 // BOOST_TEST_MESSAGE ( "Short input tests for boost::algorithm::unhex" );
83 void test_nonhex_input1 () {
86 try { ba::unhex ( "01234FG1234", std::back_inserter(s)); }
87 catch ( const std::exception &ex ) {
88 BOOST_CHECK ( 'G' == *boost::get_error_info<ba::bad_char>(ex));
92 BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_nonhex_input1" );
93 BOOST_CHECK ( false );
96 void test_nonhex_input2 () {
99 try { ba::unhex ( "012Z4FA1234", std::back_inserter(s)); }
100 catch ( const ba::hex_decode_error &ex ) {
101 BOOST_CHECK ( 'Z' == *boost::get_error_info<ba::bad_char>(ex));
105 BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_nonhex_input2" );
106 BOOST_CHECK ( false );
109 void test_nonhex_input3 () {
112 try { ba::unhex ( "01234FA12Q4", std::back_inserter(s)); }
113 catch ( const ba::non_hex_input &ex ) {
114 BOOST_CHECK ( 'Q' == *boost::get_error_info<ba::bad_char>(ex));
118 BOOST_TEST_MESSAGE ( "Failed to catch ba::non_hex_input in test_nonhex_input3" );
119 BOOST_CHECK ( false );
122 // Make sure that the right thing is thrown
123 void test_nonhex_input4 () {
126 try { ba::unhex ( "P1234FA1234", std::back_inserter(s)); }
127 catch ( const ba::not_enough_input &ex ) { BOOST_CHECK ( false ); }
128 catch ( const ba::non_hex_input &ex ) { return; }
129 catch ( ... ) { BOOST_CHECK ( false ); }
130 BOOST_CHECK ( false );
133 void test_nonhex_input () {
134 // BOOST_TEST_MESSAGE ( "Non hex input tests for boost::algorithm::unhex" );
135 test_nonhex_input1 ();
136 test_nonhex_input2 ();
137 test_nonhex_input3 ();
138 test_nonhex_input4 ();
141 BOOST_AUTO_TEST_CASE( test_main )
144 test_nonhex_input ();