p≡p MIME library
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.

54 lines
1.4 KiB

  1. #include <gtest/gtest.h>
  2. #include "to_utf8.hh"
  3. #include <vector>
  4. namespace {
  5. const char nullo[4] = {0,0,0,0};
  6. const std::vector<std::string> testValuesIdentical =
  7. {
  8. { "" },
  9. { std::string(nullo, nullo+1) }, // Yeah, 1 NUL byte
  10. { std::string(nullo, nullo+4) }, // Yeah, 4 NUL bytes
  11. { "\taeiouAEIU~+-&\\ =?:\n\f</>\r" },
  12. };
  13. }
  14. class ToUtf8Test : public ::testing::TestWithParam<std::string>
  15. {
  16. // intentionally left blank for now.
  17. };
  18. INSTANTIATE_TEST_CASE_P(ToUtf8TestInstance, ToUtf8Test, testing::ValuesIn(testValuesIdentical) );
  19. TEST_P( ToUtf8Test, Meh )
  20. {
  21. const auto& v = GetParam();
  22. EXPECT_EQ( v, to_utf8("UTF-8", v) );
  23. EXPECT_EQ( v, to_utf8("utf-8", v) );
  24. EXPECT_EQ( v, to_utf8("ISO-8859-1", v) );
  25. EXPECT_EQ( v, to_utf8("iso-8859-1", v) );
  26. }
  27. TEST( ToUtf8, Latin1 )
  28. {
  29. EXPECT_EQ( to_utf8("ISO-8859-1", "\x84\xdc" "bergr\xf6\xdf" "en\xe4" "nderung\x93: 10\x80!"), "„Übergrößenänderung“: 10€!" );
  30. EXPECT_EQ( to_utf8("UTF-8", "„Übergrößenänderung“: 10€!"), "„Übergrößenänderung“: 10€!" );
  31. }
  32. TEST( ToUtf8, Latin9 )
  33. {
  34. EXPECT_EQ( to_utf8("ISO-8859-15", "\xdc" "bergr\xf6\xdf" "en\xe4nderung: 10\xa4!"), "Übergrößenänderung: 10\xe2\x82\xac!" );
  35. std::string latin9, utf8;
  36. for(unsigned u=0; u<277; ++u)
  37. {
  38. latin9 += "\xb0\xa4\xbe"; // degree, euro, capital Y with diaeresis: °€Ÿ
  39. utf8 += "\xc2\xb0" "\xe2\x82\xac" "\xc5\xb8";
  40. EXPECT_EQ( to_utf8("ISO-8859-15", latin9), utf8 );
  41. }
  42. }