diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-10-21 23:45:10 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-21 23:47:20 -0700 |
commit | e61860243329c57811aec28ed2eb0ff8c8af760f (patch) | |
tree | c33195ebc4597c218098444f85e9cab76b9b870d /Tests | |
parent | 259ef765043caff5bbc1234c7b97270526bbb452 (diff) | |
download | serenity-e61860243329c57811aec28ed2eb0ff8c8af760f.zip |
LibC: Implement mbrlen
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibC/TestWchar.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Tests/LibC/TestWchar.cpp b/Tests/LibC/TestWchar.cpp index dc173eccb4..2e42de4057 100644 --- a/Tests/LibC/TestWchar.cpp +++ b/Tests/LibC/TestWchar.cpp @@ -439,3 +439,38 @@ TEST_CASE(wcslcpy) ret = wcslcpy(nullptr, L"abc", 0); EXPECT_EQ(ret, 3ul); } + +TEST_CASE(mbrlen) +{ + size_t ret = 0; + mbstate_t state = {}; + + // Ensure that we can parse normal ASCII characters. + ret = mbrlen("Hello", 5, &state); + EXPECT_EQ(ret, 1ul); + + // Try two three-byte codepoints (™™), only one of which should be consumed. + ret = mbrlen("\xe2\x84\xa2\xe2\x84\xa2", 6, &state); + EXPECT_EQ(ret, 3ul); + + // Try a null character, which should return 0 and reset the state to the initial state. + ret = mbrlen("\x00\x00", 2, &state); + EXPECT_EQ(ret, 0ul); + EXPECT_NE(mbsinit(&state), 0); + + // Try an incomplete multibyte character. + ret = mbrlen("\xe2\x84", 2, &state); + EXPECT_EQ(ret, -2ul); + EXPECT_EQ(mbsinit(&state), 0); + + // Finish the previous multibyte character. + ret = mbrlen("\xa2", 1, &state); + EXPECT_EQ(ret, 1ul); + + // Try an invalid multibyte sequence. + // Reset the state afterwards because the effects are undefined. + ret = mbrlen("\xff", 1, &state); + EXPECT_EQ(ret, -1ul); + EXPECT_EQ(errno, EILSEQ); + state = {}; +} |