From bb9988933edb7dc2ab75931888abbf7817cc74bb Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 8 Dec 2023 14:21:52 +0100 Subject: [PATCH] unicode: add unit test for normalize Signed-off-by: Simon Rozman --- UnitTests/unicode.cpp | 12 ++++++++++++ include/stdex/unicode.hpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/UnitTests/unicode.cpp b/UnitTests/unicode.cpp index 140c650a5..84b708b37 100644 --- a/UnitTests/unicode.cpp +++ b/UnitTests/unicode.cpp @@ -87,6 +87,18 @@ namespace UnitTests "", win1250_to_utf8.convert(nullptr, 0).c_str()); } + + TEST_METHOD(normalize) + { +#ifdef _WIN32 + Assert::AreEqual( + L"tést", + stdex::normalize(L"tést").c_str()); + Assert::AreEqual( + L"", + stdex::normalize(nullptr, 0).c_str()); +#endif + } }; } diff --git a/include/stdex/unicode.hpp b/include/stdex/unicode.hpp index da048081f..b9069fb73 100644 --- a/include/stdex/unicode.hpp +++ b/include/stdex/unicode.hpp @@ -818,10 +818,12 @@ namespace stdex size_t count_dst = dst.size(); dst.resize(count_dst + count_src); _Assume_(count_src + 1 < INT_MAX); +#pragma warning(suppress: 6387) // Testing indicates src may be NULL when count_src is also 0. Is SAL of the lpSrcString parameter wrong? int r = NormalizeString(NormalizationC, src, static_cast(count_src), dst.data() + count_dst, static_cast(count_src + 1)); if (r >= 0) dst.resize(count_dst + r); else +#pragma warning(suppress: 6387) // Testing indicates src may be NULL when count_src is also 0. Is SAL of the _Src parameter wrong? memcpy(dst.data() + count_dst, src, count_src * sizeof(wchar_t)); return dst.size(); }