C++11 library providing functionality common to all adapters.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. #include "../src/std_utils.hh"
  2. #include "../src/pEpLog.hh"
  3. #include <iostream>
  4. #include <cassert>
  5. #include <pEp/pitytest11/PityTest.hh>
  6. using namespace pEp;
  7. int main()
  8. {
  9. pEp::Adapter::pEpLog::set_enabled(true);
  10. {
  11. // Valid hex string
  12. std::string str_in{ "FFABCD00EF123200" };
  13. std::vector<unsigned char> bin = Utils::hex2bin(str_in);
  14. PITYASSERT(str_in.length() == bin.size() * 2, "Size error");
  15. std::string str_out = pEp::Utils::bin2hex(bin);
  16. pEpLog("Hex_IN : '" + Utils::to_lower(str_in) + "'");
  17. pEpLog("Hex_OUT : '" + Utils::to_lower(str_out) + "'");
  18. PITYASSERT(Utils::to_lower(str_in) == Utils::to_lower(str_out), "roundtrip failed");
  19. }
  20. {
  21. // Uneven string throws
  22. std::string str_in{ "FFA" };
  23. PITYASSERT_THROWS(Utils::hex2bin(str_in), "Uneven string should throw");
  24. }
  25. {
  26. // Non-hex chars
  27. std::string str_in{ "pEp!" };
  28. PITYASSERT_THROWS(Utils::hex2bin(str_in), "Invalid hex chars should throw");
  29. }
  30. pEpLog("All tests passsed");
  31. }