diff options
author | Jay Berkenbilt <ejb@ql.org> | 2018-01-14 15:04:13 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2018-01-14 15:04:13 +0100 |
commit | 3e306ae64cc3d160034f27d72ad27bee03a65aa5 (patch) | |
tree | d60ce6f228328e1560e51cf494bc93b7ff2bd03e /libtests/qutil.cc | |
parent | 68572df2bf0c6d1d7756ff05a96e01d7e2f69c09 (diff) | |
download | qpdf-3e306ae64cc3d160034f27d72ad27bee03a65aa5.tar.zst |
Add QUtil::hex_decode
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r-- | libtests/qutil.cc | 40 |
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) { |