From 1d1575e971e8fca514fc421834e2bd3e60b9f069 Mon Sep 17 00:00:00 2001 From: roker Date: Tue, 6 Jul 2021 16:51:01 +0200 Subject: [PATCH] copy unittest_nfc.cc to unittest_nfc16.cc --- test/unittest_nfc16.cc | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test/unittest_nfc16.cc diff --git a/test/unittest_nfc16.cc b/test/unittest_nfc16.cc new file mode 100644 index 0000000..7c6a46f --- /dev/null +++ b/test/unittest_nfc16.cc @@ -0,0 +1,77 @@ +#include + +#include "../src/nfc.hh" // for illegal_utf8 exception +#include + +using namespace pEp; + +namespace { + +struct TestEntry +{ + u16string_view input; + bool is_nfc; + IsNFC quick; + u16string_view nfc; +}; + +typedef TestEntry TE; + + +std::ostream& operator<<(std::ostream& o, const TestEntry& tt) +{ + return o << "input=«" << tt.input << "», isNfc=" << tt.is_nfc << ", quick=" << tt.quick << ". "; +} + + +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 + + { "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) + + { "\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 + +// 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) + + { 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 + + { "EOF", true, IsNFC::Yes, "EOF" } + }; + +} // end of anonymous namespace + + +class Nfc16Test : public ::testing::TestWithParam +{ + // intentionally left blank for now. +}; + +INSTANTIATE_TEST_SUITE_P(Nfc16TestInstance, Nfc16Test, testing::ValuesIn(testValues) ); + +TEST_P( Nfc16Test, Meh ) +{ + const auto& v = GetParam(); + EXPECT_EQ( v.quick, isNFC_quick_check(v.input) ); + + EXPECT_EQ( v.is_nfc, isNFC(v.input) ); + EXPECT_EQ( v.nfc , toNFC(v.input) ); + + if(v.is_nfc) + { + EXPECT_EQ( v.input, toNFC(v.input) ); + } +}