aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index 7fc5960d..e6416ac1 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -247,6 +247,44 @@ void read_lines_from_file_test()
}
}
+void assert_hex_encode(std::string const& input, std::string const& expected)
+{
+ std::string actual = QUtil::hex_encode(input);
+ if (expected != actual)
+ {
+ std::cout << "hex encode " << input
+ << ": expected = " << expected
+ << "; actual = " << actual
+ << std::endl;
+ }
+}
+
+void assert_hex_decode(std::string const& input, std::string const& expected)
+{
+ std::string actual = QUtil::hex_decode(input);
+ if (expected != actual)
+ {
+ std::cout << "hex encode " << input
+ << ": expected = " << expected
+ << "; actual = " << actual
+ << std::endl;
+ }
+}
+
+void hex_encode_decode_test()
+{
+ std::cout << "begin hex encode/decode\n";
+ assert_hex_encode("", "");
+ assert_hex_encode("Potato", "506f7461746f");
+ std::string with_null("a\367" "00w");
+ with_null[3] = '\0';
+ assert_hex_encode(with_null, "61f7300077");
+ assert_hex_decode("", "");
+ assert_hex_decode("61F7-3000-77", with_null);
+ assert_hex_decode("41455", "AEP");
+ std::cout << "end hex encode/decode\n";
+}
+
int main(int argc, char* argv[])
{
try
@@ -266,6 +304,8 @@ int main(int argc, char* argv[])
same_file_test();
std::cout << "----" << std::endl;
read_lines_from_file_test();
+ std::cout << "----" << std::endl;
+ hex_encode_decode_test();
}
catch (std::exception& e)
{