A C++ wrapper for the basic C datatypes defined by the pEpEngine.
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.

83 lines
2.7 KiB

  1. #include <gtest/gtest.h>
  2. #include "../src/nfc.hh" // for illegal_utf8 exception
  3. #include <vector>
  4. using namespace pEp;
  5. namespace pEp
  6. {
  7. std::string escape_utf16(u16string_view s);
  8. }
  9. namespace {
  10. struct TestEntry
  11. {
  12. u16string_view input;
  13. bool is_nfc;
  14. IsNFC quick;
  15. u16string_view nfc;
  16. };
  17. typedef TestEntry TE;
  18. std::ostream& operator<<(std::ostream& o, const TestEntry& tt)
  19. {
  20. return o << "input=«" << pEp::escape_utf16(tt.input) << "», isNfc=" << tt.is_nfc << ", quick=" << tt.quick << ". ";
  21. }
  22. const char16_t nullo[4] = {0,0,0,0};
  23. const std::vector<TestEntry> testValues =
  24. {
  25. { u"" , true, IsNFC::Yes, u"" }, // always start with the simple case ;-)
  26. { u"123" , true, IsNFC::Yes, u"123" }, // some ASCII digits. Still easy.
  27. { u"\n\\\b" , true, IsNFC::Yes, u"\n\\\b" }, // backslash escapes for ASCII and control chars
  28. { u"ä" , true, IsNFC::Yes, u"ä" }, // <U+00E4> small a with diaeresis
  29. { u"\u0105" , true, IsNFC::Yes, u"\u0105" }, // <U+0105> small a with ogonek
  30. { u"a\u0308" , false, IsNFC::Maybe, u"ä" }, // a + <U+0308> combining diaresis
  31. { u"a\u0328" , false, IsNFC::Maybe, u"\u0105" }, // a + <U+0328> combining ogonek
  32. { u"a\u0328\u0308", false, IsNFC::Maybe, u"\u0105\u0308" }, // a + <U+0328> + <U+0308> (ogonek + diaeresis)
  33. { u"a\u0308\u0328", false, IsNFC::Maybe, u"\u0105\u0308" }, // a + <U+0308> + <U+0328> (diaeresis + ogonek)
  34. { u"\u0105\u0308" , true, IsNFC::Maybe, u"\u0105\u0308" }, // <U+0105> small a with ogonek + combining diaeresis
  35. { u"ä\u0328" , false, IsNFC::Maybe, u"\u0105\u0308" }, // a diaeresis + <U+0328> combining ogonek
  36. // Already implemented, because <U+305> and <U+33C> have neither "No" nor "Maybe" NFC class:
  37. { u"a\u0305\u033c", false, IsNFC::No , u"a\u033c\u0305"}, // a + <U+0305> + <U+033C> (overline + seagull_below)
  38. { u"a\u033c\u0305", true, IsNFC::Yes , u"a\u033c\u0305"}, // a + <U+033C> + <U+0305> (seagull_below + overline)
  39. { u"\U0001D161", false, IsNFC::No, u"x" }, // MUSICAL SYMBOL SIXTEENTH NOTE
  40. { u16string_view(nullo, 1), true, IsNFC::Yes, u16string_view(nullo, 1) }, // Yeah, 1 NUL byte
  41. { u16string_view(nullo, 4), true, IsNFC::Yes, u16string_view(nullo, 4) }, // Yeah, 4 NUL bytes
  42. { u"EOF", true, IsNFC::Yes, u"EOF" }
  43. };
  44. } // end of anonymous namespace
  45. class Nfc16Test : public ::testing::TestWithParam<TestEntry>
  46. {
  47. // intentionally left blank for now.
  48. };
  49. INSTANTIATE_TEST_SUITE_P(Nfc16TestInstance, Nfc16Test, testing::ValuesIn(testValues) );
  50. TEST_P( Nfc16Test, Meh )
  51. {
  52. const auto& v = GetParam();
  53. EXPECT_EQ( v.quick, isNFC_quick_check(v.input) );
  54. EXPECT_EQ( v.is_nfc, isNFC(v.input) );
  55. EXPECT_EQ( v.nfc , toNFC(v.input) );
  56. if(v.is_nfc)
  57. {
  58. EXPECT_EQ( v.input, toNFC(v.input) );
  59. }
  60. }