hex_ut.cpp 739 B

1234567891011121314151617181920212223242526272829
  1. #include "hex.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include "str.h"
  4. Y_UNIT_TEST_SUITE(THexCodingTest) {
  5. void TestImpl(const TString& data) {
  6. TString encoded;
  7. TStringOutput encodedOut(encoded);
  8. HexEncode(data.data(), data.size(), encodedOut);
  9. UNIT_ASSERT_EQUAL(encoded.size(), data.size() * 2);
  10. TString decoded;
  11. TStringOutput decodedOut(decoded);
  12. HexDecode(encoded.data(), encoded.size(), decodedOut);
  13. UNIT_ASSERT_EQUAL(decoded, data);
  14. }
  15. Y_UNIT_TEST(TestEncodeDecodeToStream) {
  16. TString data = "100ABAcaba500,$%0987123456 \n\t\x01\x02\x03.";
  17. TestImpl(data);
  18. }
  19. Y_UNIT_TEST(TestEmpty) {
  20. TestImpl("");
  21. }
  22. }