/test/util/unit/percent_encoding_test.cpp

https://github.com/hioa-cs/IncludeOS · C++ · 22 lines · 18 code · 4 blank · 0 comment · 2 complexity · d20394bfcca9642ca00f8946c3c9a1db MD5 · raw file

  1. #include <common.cxx>
  2. #include <uri>
  3. #include <strings.h> // strcasecmp
  4. CASE("uri::encode() encodes a string")
  5. {
  6. std::string encoded {uri::encode("The C++ Programming Language (4th Edition)")};
  7. static const char* expected = "The%20C%2B%2B%20Programming%20Language%20%284th%20Edition%29";
  8. EXPECT(strcasecmp(encoded.c_str(), expected) == 0);
  9. }
  10. CASE("uri::decode() decodes an URI-encoded string")
  11. {
  12. std::string decoded {uri::decode("The%20C%2B%2B%20Programming%20Language%20%284th%20Edition%29")};
  13. EXPECT(decoded == "The C++ Programming Language (4th Edition)");
  14. }
  15. CASE("uri::decode() throws on invalid input when URI_THROW_ON_ERROR is defined")
  16. {
  17. EXPECT_THROWS_AS(std::string s = uri::decode("%2x%zz"), std::runtime_error);
  18. }