From 5ffd66f1697a89b73a6f2cf5969de2f6d26f8b22 Mon Sep 17 00:00:00 2001 From: roker Date: Mon, 12 Jul 2021 13:29:58 +0200 Subject: [PATCH] fix the unittests for UTF-16 NFC tests --- src/nfc.cc | 6 ++++++ test/unittest_nfc16.cc | 39 ++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/nfc.cc b/src/nfc.cc index 8d0318c..294d90c 100644 --- a/src/nfc.cc +++ b/src/nfc.cc @@ -222,6 +222,12 @@ namespace namespace pEp { +std::string escape_utf16(u16string_view s) +{ + return escape(s); +} + + std::ostream& operator<<(std::ostream& o, IsNFC is_nfc) { switch(is_nfc) diff --git a/test/unittest_nfc16.cc b/test/unittest_nfc16.cc index 7c6a46f..b428f44 100644 --- a/test/unittest_nfc16.cc +++ b/test/unittest_nfc16.cc @@ -5,6 +5,11 @@ using namespace pEp; +namespace pEp +{ + std::string escape_utf16(u16string_view s); +} + namespace { struct TestEntry @@ -20,7 +25,7 @@ typedef TestEntry TE; std::ostream& operator<<(std::ostream& o, const TestEntry& tt) { - return o << "input=«" << tt.input << "», isNfc=" << tt.is_nfc << ", quick=" << tt.quick << ". "; + return o << "input=«" << pEp::escape_utf16(tt.input) << "», isNfc=" << tt.is_nfc << ", quick=" << tt.quick << ". "; } @@ -28,28 +33,28 @@ const char16_t nullo[4] = {0,0,0,0}; const std::vector testValues = { - { "" , true, IsNFC::Yes, "" }, // always start with the simple case ;-) - { "123" , true, IsNFC::Yes, "123" }, // some ASCII digits. Still easy. - { "\n\\\b" , true, IsNFC::Yes, "\n\\\b" }, // backslash escapes for ASCII and control chars - { "ä" , true, IsNFC::Yes, "ä" }, // small a with diaeresis - { "\xc4\x85" , true, IsNFC::Yes, "\xc4\x85" }, // small a with ogonek + { u"" , true, IsNFC::Yes, u"" }, // always start with the simple case ;-) + { u"123" , true, IsNFC::Yes, u"123" }, // some ASCII digits. Still easy. + { u"\n\\\b" , true, IsNFC::Yes, u"\n\\\b" }, // backslash escapes for ASCII and control chars + { u"ä" , true, IsNFC::Yes, u"ä" }, // small a with diaeresis + { u"\u0105" , true, IsNFC::Yes, u"\u0105" }, // small a with ogonek - { "a\xcc\x88", false, IsNFC::Maybe, "ä" }, // a + combining diaresis - { "a\xcc\xa8", false, IsNFC::Maybe, "\xc4\x85" }, // a + combining ogonek - { "a\xcc\xa8\xcc\x88", false, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // a + + (ogonek + diaeresis) - { "a\xcc\x88\xcc\xa8", false, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // a + + (diaeresis + ogonek) + { u"a\u0308" , false, IsNFC::Maybe, u"ä" }, // a + combining diaresis + { u"a\u0328" , false, IsNFC::Maybe, u"\u0105" }, // a + combining ogonek + { u"a\u0328\u0308", false, IsNFC::Maybe, u"\u0105\u0308" }, // a + + (ogonek + diaeresis) + { u"a\u0308\u0328", false, IsNFC::Maybe, u"\u0105\u0308" }, // a + + (diaeresis + ogonek) - { "\xc4\x85\xcc\x88" , true, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // small a with ogonek + combining diaeresis - { "ä\xcc\xa8" , false, IsNFC::Maybe, "\xc4\x85\xcc\x88" }, // a diaeresis + combining ogonek + { u"\u0105\u0308" , true, IsNFC::Maybe, u"\u0105\u0308" }, // small a with ogonek + combining diaeresis + { u"ä\u0328" , false, IsNFC::Maybe, u"\u0105\u0308" }, // a diaeresis + combining ogonek // Already implemented, because and have neither "No" nor "Maybe" NFC class: - { "a\xcc\x85\xcc\xbc", false, IsNFC::No , "a\xcc\xbc\xcc\x85"}, // a + + (overline + seagull_below) - { "a\xcc\xbc\xcc\x85", true, IsNFC::Yes , "a\xcc\xbc\xcc\x85"}, // a + + (seagull_below + overline) + { u"a\u0305\u033c", false, IsNFC::No , u"a\u033c\u0305"}, // a + + (overline + seagull_below) + { u"a\u033c\u0305", true, IsNFC::Yes , u"a\u033c\u0305"}, // a + + (seagull_below + overline) - { string_view(nullo, 1), true, IsNFC::Yes, string_view(nullo, 1) }, // Yeah, 1 NUL byte - { string_view(nullo, 4), true, IsNFC::Yes, string_view(nullo, 4) }, // Yeah, 4 NUL bytes + { u16string_view(nullo, 1), true, IsNFC::Yes, u16string_view(nullo, 1) }, // Yeah, 1 NUL byte + { u16string_view(nullo, 4), true, IsNFC::Yes, u16string_view(nullo, 4) }, // Yeah, 4 NUL bytes - { "EOF", true, IsNFC::Yes, "EOF" } + { u"EOF", true, IsNFC::Yes, u"EOF" } }; } // end of anonymous namespace