Skip to content

Commit 3cedd05

Browse files
nigels-comNigel Stewart
authored and
Nigel Stewart
committed
Test coverage for algorithm::hex_lower, adapting existing coverage for algorithm::hex
1 parent b7d46e6 commit 3cedd05

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/hex_test1.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <boost/config.hpp>
1111
#include <boost/algorithm/hex.hpp>
12+
#include <boost/algorithm/string/case_conv.hpp>
1213

1314
#define BOOST_TEST_MAIN
1415
#include <boost/test/unit_test.hpp>
@@ -42,6 +43,31 @@ void test_to_hex ( const typename String::value_type ** tests ) {
4243
}
4344
}
4445

46+
template<typename String>
47+
void test_to_hex_lower ( const typename String::value_type ** tests ) {
48+
for ( const typename String::value_type **p = tests; *p; p++ ) {
49+
String arg, argh, one, two, three, four;
50+
arg.assign ( *p );
51+
boost::algorithm::hex_lower ( *p, std::back_inserter ( one ));
52+
boost::algorithm::hex_lower ( arg, std::back_inserter ( two ));
53+
boost::algorithm::hex_lower ( arg.begin (), arg.end (), std::back_inserter ( three ));
54+
four = boost::algorithm::hex_lower ( arg );
55+
BOOST_CHECK ( one == two );
56+
BOOST_CHECK ( one == three );
57+
BOOST_CHECK ( one == four );
58+
argh = one;
59+
one.clear (); two.clear (); three.clear (); four.clear ();
60+
boost::algorithm::unhex ( argh.c_str (), std::back_inserter ( one ));
61+
boost::algorithm::unhex ( argh, std::back_inserter ( two ));
62+
boost::algorithm::unhex ( argh.begin (), argh.end (), std::back_inserter ( three ));
63+
four = boost::algorithm::unhex ( argh );
64+
BOOST_CHECK ( one == two );
65+
BOOST_CHECK ( one == three );
66+
BOOST_CHECK ( one == four );
67+
BOOST_CHECK ( one == arg );
68+
}
69+
}
70+
4571

4672
template<typename String>
4773
void test_from_hex_success ( const typename String::value_type ** tests ) {
@@ -61,6 +87,11 @@ void test_from_hex_success ( const typename String::value_type ** tests ) {
6187
boost::algorithm::hex ( argh, std::back_inserter ( two ));
6288
boost::algorithm::hex ( argh.begin (), argh.end (), std::back_inserter ( three ));
6389
four = boost::algorithm::hex ( argh );
90+
boost::algorithm::to_lower( arg );
91+
boost::algorithm::to_lower( one );
92+
boost::algorithm::to_lower( two );
93+
boost::algorithm::to_lower( three );
94+
boost::algorithm::to_lower( four );
6495
BOOST_CHECK ( one == two );
6596
BOOST_CHECK ( one == three );
6697
BOOST_CHECK ( one == four );
@@ -113,13 +144,15 @@ const wchar_t *tohex_w [] = {
113144
const char *fromhex [] = {
114145
"20",
115146
"2122234556FF",
147+
"2122234556ff",
116148
NULL // End of the list
117149
};
118150

119151

120152
const wchar_t *fromhex_w [] = {
121153
L"00101020",
122154
L"2122234556FF3456",
155+
L"2122234556ff3456",
123156
NULL // End of the list
124157
};
125158

@@ -129,6 +162,8 @@ const char *fromhex_fail [] = {
129162
"H",
130163
"234",
131164
"21222G4556FF",
165+
"h",
166+
"21222g4556ff",
132167
NULL // End of the list
133168
};
134169

@@ -139,17 +174,21 @@ const wchar_t *fromhex_fail_w [] = {
139174
L"H",
140175
L"234",
141176
L"21222G4556FF",
177+
L"h",
178+
L"21222g4556ff",
142179
NULL // End of the list
143180
};
144181

145182

146183
BOOST_AUTO_TEST_CASE( test_main )
147184
{
148185
test_to_hex<std::string> ( tohex );
186+
test_to_hex_lower<std::string> ( tohex );
149187
test_from_hex_success<std::string> ( fromhex );
150188
test_from_hex_failure<std::string> ( fromhex_fail );
151189

152190
test_to_hex<std::wstring> ( tohex_w );
191+
test_to_hex_lower<std::wstring> ( tohex_w );
153192
test_from_hex_success<std::wstring> ( fromhex_w );
154193
test_from_hex_failure<std::wstring> ( fromhex_fail_w );
155194
}

0 commit comments

Comments
 (0)