summaryrefslogtreecommitdiff
path: root/Tests/LibC/TestWchar.cpp
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2021-10-22 01:38:29 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-10-21 23:57:32 -0700
commit89afd4d063b79ef2eba81d1bfc7857c388679c5e (patch)
treedd77ab520a316c376f3cd933c8f4b8b7c1eef08f /Tests/LibC/TestWchar.cpp
parent552ae77f0ddc45b65d88af78f4fa080f4301a65b (diff)
downloadserenity-89afd4d063b79ef2eba81d1bfc7857c388679c5e.zip
LibC: Implement mbsnrtowcs
Diffstat (limited to 'Tests/LibC/TestWchar.cpp')
-rw-r--r--Tests/LibC/TestWchar.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/Tests/LibC/TestWchar.cpp b/Tests/LibC/TestWchar.cpp
index 4ac7282504..c8b6f71f30 100644
--- a/Tests/LibC/TestWchar.cpp
+++ b/Tests/LibC/TestWchar.cpp
@@ -441,6 +441,45 @@ TEST_CASE(mbsrtowcs)
EXPECT_EQ(src, nullptr);
}
+TEST_CASE(mbsnrtowcs)
+{
+ mbstate_t state = {};
+ const char good_chars[] = "\xf0\x9f\x90\x9e\xf0\x9f\x90\x9e";
+ const char* src;
+ size_t ret = 0;
+
+ // Convert nothing.
+ src = good_chars;
+ ret = mbsnrtowcs(nullptr, &src, 0, 0, &state);
+ EXPECT_EQ(ret, 0ul);
+ EXPECT_EQ(src, good_chars);
+
+ // Convert one full wide character.
+ src = good_chars;
+ ret = mbsnrtowcs(nullptr, &src, 4, 0, &state);
+ EXPECT_EQ(ret, 1ul);
+ EXPECT_EQ(src, good_chars + 4);
+
+ // Encounter a null character.
+ src = good_chars;
+ ret = mbsnrtowcs(nullptr, &src, 10, 0, &state);
+ EXPECT_EQ(ret, 2ul);
+ EXPECT_EQ(src, nullptr);
+
+ // Convert an incomplete character.
+ // Make sure that we point past the last processed byte.
+ src = good_chars;
+ ret = mbsnrtowcs(nullptr, &src, 6, 0, &state);
+ EXPECT_EQ(ret, 1ul);
+ EXPECT_EQ(src, good_chars + 6);
+ EXPECT_EQ(mbsinit(&state), 0);
+
+ // Finish converting the incomplete character.
+ ret = mbsnrtowcs(nullptr, &src, 2, 0, &state);
+ EXPECT_EQ(ret, 1ul);
+ EXPECT_EQ(src, good_chars + 8);
+}
+
TEST_CASE(wcslcpy)
{
auto buf = static_cast<wchar_t*>(malloc(8 * sizeof(wchar_t)));