mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-12 20:16:37 +02:00
Test coverage for algorithm::hex_lower, adapting existing coverage for algorithm::hex
This commit is contained in:
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/algorithm/hex.hpp>
|
#include <boost/algorithm/hex.hpp>
|
||||||
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
|
|
||||||
#define BOOST_TEST_MAIN
|
#define BOOST_TEST_MAIN
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
@ -42,6 +43,31 @@ void test_to_hex ( const typename String::value_type ** tests ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename String>
|
||||||
|
void test_to_hex_lower ( const typename String::value_type ** tests ) {
|
||||||
|
for ( const typename String::value_type **p = tests; *p; p++ ) {
|
||||||
|
String arg, argh, one, two, three, four;
|
||||||
|
arg.assign ( *p );
|
||||||
|
boost::algorithm::hex_lower ( *p, std::back_inserter ( one ));
|
||||||
|
boost::algorithm::hex_lower ( arg, std::back_inserter ( two ));
|
||||||
|
boost::algorithm::hex_lower ( arg.begin (), arg.end (), std::back_inserter ( three ));
|
||||||
|
four = boost::algorithm::hex_lower ( arg );
|
||||||
|
BOOST_CHECK ( one == two );
|
||||||
|
BOOST_CHECK ( one == three );
|
||||||
|
BOOST_CHECK ( one == four );
|
||||||
|
argh = one;
|
||||||
|
one.clear (); two.clear (); three.clear (); four.clear ();
|
||||||
|
boost::algorithm::unhex ( argh.c_str (), std::back_inserter ( one ));
|
||||||
|
boost::algorithm::unhex ( argh, std::back_inserter ( two ));
|
||||||
|
boost::algorithm::unhex ( argh.begin (), argh.end (), std::back_inserter ( three ));
|
||||||
|
four = boost::algorithm::unhex ( argh );
|
||||||
|
BOOST_CHECK ( one == two );
|
||||||
|
BOOST_CHECK ( one == three );
|
||||||
|
BOOST_CHECK ( one == four );
|
||||||
|
BOOST_CHECK ( one == arg );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename String>
|
template<typename String>
|
||||||
void test_from_hex_success ( const typename String::value_type ** tests ) {
|
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 ) {
|
|||||||
boost::algorithm::hex ( argh, std::back_inserter ( two ));
|
boost::algorithm::hex ( argh, std::back_inserter ( two ));
|
||||||
boost::algorithm::hex ( argh.begin (), argh.end (), std::back_inserter ( three ));
|
boost::algorithm::hex ( argh.begin (), argh.end (), std::back_inserter ( three ));
|
||||||
four = boost::algorithm::hex ( argh );
|
four = boost::algorithm::hex ( argh );
|
||||||
|
boost::algorithm::to_lower( arg );
|
||||||
|
boost::algorithm::to_lower( one );
|
||||||
|
boost::algorithm::to_lower( two );
|
||||||
|
boost::algorithm::to_lower( three );
|
||||||
|
boost::algorithm::to_lower( four );
|
||||||
BOOST_CHECK ( one == two );
|
BOOST_CHECK ( one == two );
|
||||||
BOOST_CHECK ( one == three );
|
BOOST_CHECK ( one == three );
|
||||||
BOOST_CHECK ( one == four );
|
BOOST_CHECK ( one == four );
|
||||||
@ -113,6 +144,7 @@ const wchar_t *tohex_w [] = {
|
|||||||
const char *fromhex [] = {
|
const char *fromhex [] = {
|
||||||
"20",
|
"20",
|
||||||
"2122234556FF",
|
"2122234556FF",
|
||||||
|
"2122234556ff",
|
||||||
NULL // End of the list
|
NULL // End of the list
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,6 +152,7 @@ const char *fromhex [] = {
|
|||||||
const wchar_t *fromhex_w [] = {
|
const wchar_t *fromhex_w [] = {
|
||||||
L"00101020",
|
L"00101020",
|
||||||
L"2122234556FF3456",
|
L"2122234556FF3456",
|
||||||
|
L"2122234556ff3456",
|
||||||
NULL // End of the list
|
NULL // End of the list
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,6 +162,8 @@ const char *fromhex_fail [] = {
|
|||||||
"H",
|
"H",
|
||||||
"234",
|
"234",
|
||||||
"21222G4556FF",
|
"21222G4556FF",
|
||||||
|
"h",
|
||||||
|
"21222g4556ff",
|
||||||
NULL // End of the list
|
NULL // End of the list
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -139,6 +174,8 @@ const wchar_t *fromhex_fail_w [] = {
|
|||||||
L"H",
|
L"H",
|
||||||
L"234",
|
L"234",
|
||||||
L"21222G4556FF",
|
L"21222G4556FF",
|
||||||
|
L"h",
|
||||||
|
L"21222g4556ff",
|
||||||
NULL // End of the list
|
NULL // End of the list
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -146,10 +183,12 @@ const wchar_t *fromhex_fail_w [] = {
|
|||||||
BOOST_AUTO_TEST_CASE( test_main )
|
BOOST_AUTO_TEST_CASE( test_main )
|
||||||
{
|
{
|
||||||
test_to_hex<std::string> ( tohex );
|
test_to_hex<std::string> ( tohex );
|
||||||
|
test_to_hex_lower<std::string> ( tohex );
|
||||||
test_from_hex_success<std::string> ( fromhex );
|
test_from_hex_success<std::string> ( fromhex );
|
||||||
test_from_hex_failure<std::string> ( fromhex_fail );
|
test_from_hex_failure<std::string> ( fromhex_fail );
|
||||||
|
|
||||||
test_to_hex<std::wstring> ( tohex_w );
|
test_to_hex<std::wstring> ( tohex_w );
|
||||||
|
test_to_hex_lower<std::wstring> ( tohex_w );
|
||||||
test_from_hex_success<std::wstring> ( fromhex_w );
|
test_from_hex_success<std::wstring> ( fromhex_w );
|
||||||
test_from_hex_failure<std::wstring> ( fromhex_fail_w );
|
test_from_hex_failure<std::wstring> ( fromhex_fail_w );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user