22 #include "goby/util/binary.h" 30 using goby::util::hex_decode;
31 using goby::util::hex_encode;
34 std::cout <<
"testing lowercase even" << std::endl;
37 for (
int i = 0; i <= 255; ++i) ss << std::setfill(
'0') << std::setw(2) << std::hex << i;
39 std::string hex1 = ss.str();
43 hex_decode(hex1, &bytes);
44 hex_encode(bytes, &hex2);
46 std::cout <<
"hex1: " << hex1 << std::endl;
47 std::cout <<
"hex2: " << hex2 << std::endl;
48 assert(hex1 == hex2.substr(hex2.size() - hex1.size()));
51 std::cout <<
"testing uppercase even" << std::endl;
54 for (
int i = 0; i <= 255; ++i)
55 ss << std::uppercase << std::setfill(
'0') << std::setw(2) << std::hex << i;
57 std::string hex1 = ss.str();
61 hex_decode(hex1, &bytes);
62 hex_encode(bytes, &hex2,
true);
64 std::cout <<
"hex1: " << hex1 << std::endl;
65 std::cout <<
"hex2: " << hex2 << std::endl;
66 assert(hex1 == hex2.substr(hex2.size() - hex1.size()));
70 std::cout <<
"testing lowercase odd" << std::endl;
73 for (
int i = 0; i <= 255; ++i) ss << std::setfill(
'0') << std::setw(2) << std::hex << i;
77 std::string hex1 = ss.str();
81 hex_decode(hex1, &bytes);
82 hex_encode(bytes, &hex2);
84 std::cout <<
"hex1: " << hex1 << std::endl;
85 std::cout <<
"hex2: " << hex2 << std::endl;
86 assert(hex1 == hex2.substr(hex2.size() - hex1.size()));
89 std::cout <<
"testing uppercase odd" << std::endl;
92 for (
int i = 0; i <= 255; ++i)
93 ss << std::uppercase << std::setfill(
'0') << std::setw(2) << std::hex << i;
96 std::string hex1 = ss.str();
100 hex_decode(hex1, &bytes);
101 hex_encode(bytes, &hex2,
true);
103 std::cout <<
"hex1: " << hex1 << std::endl;
104 std::cout <<
"hex2: " << hex2 << std::endl;
105 assert(hex1 == hex2.substr(hex2.size() - hex1.size()));
108 std::cout <<
"all tests passed" << std::endl;