From 552ae77f0ddc45b65d88af78f4fa080f4301a65b Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 22 Oct 2021 00:57:44 +0200 Subject: LibC: Implement wcsnrtombs --- Tests/LibC/TestWchar.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Tests/LibC') diff --git a/Tests/LibC/TestWchar.cpp b/Tests/LibC/TestWchar.cpp index 2e42de4057..4ac7282504 100644 --- a/Tests/LibC/TestWchar.cpp +++ b/Tests/LibC/TestWchar.cpp @@ -364,6 +364,32 @@ TEST_CASE(wcsrtombs) EXPECT_EQ(src, nullptr); } +TEST_CASE(wcsnrtombs) +{ + mbstate_t state = {}; + const wchar_t good_chars[] = { L'\U0001F41E', L'\U0001F41E', L'\0' }; + const wchar_t* src; + size_t ret = 0; + + // Convert nothing. + src = good_chars; + ret = wcsnrtombs(nullptr, &src, 0, 0, &state); + EXPECT_EQ(ret, 0ul); + EXPECT_EQ(src, good_chars); + + // Convert one wide char. + src = good_chars; + ret = wcsnrtombs(nullptr, &src, 1, 0, &state); + EXPECT_EQ(ret, 4ul); + EXPECT_EQ(src, good_chars + 1); + + // Encounter a null character. + src = good_chars; + ret = wcsnrtombs(nullptr, &src, 4, 0, &state); + EXPECT_EQ(ret, 8ul); + EXPECT_EQ(src, nullptr); +} + TEST_CASE(mbsrtowcs) { mbstate_t state = {}; -- cgit v1.2.3