unicode: add unit test for normalize

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-12-08 14:21:52 +01:00
parent 6d1d9bd1b8
commit bb9988933e
2 changed files with 14 additions and 0 deletions

View File

@ -87,6 +87,18 @@ namespace UnitTests
"", "",
win1250_to_utf8.convert(nullptr, 0).c_str()); 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
}
}; };
} }

View File

@ -818,10 +818,12 @@ namespace stdex
size_t count_dst = dst.size(); size_t count_dst = dst.size();
dst.resize(count_dst + count_src); dst.resize(count_dst + count_src);
_Assume_(count_src + 1 < INT_MAX); _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<int>(count_src), dst.data() + count_dst, static_cast<int>(count_src + 1)); int r = NormalizeString(NormalizationC, src, static_cast<int>(count_src), dst.data() + count_dst, static_cast<int>(count_src + 1));
if (r >= 0) if (r >= 0)
dst.resize(count_dst + r); dst.resize(count_dst + r);
else 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)); memcpy(dst.data() + count_dst, src, count_src * sizeof(wchar_t));
return dst.size(); return dst.size();
} }