mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
Tests: Add a test for mbsinit
This commit is contained in:
parent
212f9308d4
commit
e7f99edefa
1 changed files with 28 additions and 0 deletions
|
@ -198,3 +198,31 @@ TEST_CASE(wcscoll)
|
||||||
EXPECT(wcscoll(L"a", L"z") < 0);
|
EXPECT(wcscoll(L"a", L"z") < 0);
|
||||||
EXPECT(wcscoll(L"z", L"a") > 0);
|
EXPECT(wcscoll(L"z", L"a") > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(mbsinit)
|
||||||
|
{
|
||||||
|
// Ensure that nullptr is considered an initial state.
|
||||||
|
EXPECT(mbsinit(nullptr) != 0);
|
||||||
|
|
||||||
|
// Ensure that a zero-initialized state is recognized as initial state.
|
||||||
|
mbstate_t state = {};
|
||||||
|
EXPECT(mbsinit(&state) != 0);
|
||||||
|
|
||||||
|
// Read a partial multibyte sequence (0b11011111 / 0xdf).
|
||||||
|
size_t ret = mbrtowc(nullptr, "\xdf", 1, &state);
|
||||||
|
|
||||||
|
if (ret != -2ul)
|
||||||
|
FAIL(String::formatted("mbrtowc accepted partial multibyte sequence with return code {} (expected -2)", static_cast<ssize_t>(ret)));
|
||||||
|
|
||||||
|
// Ensure that we are not in an initial state.
|
||||||
|
EXPECT(mbsinit(&state) == 0);
|
||||||
|
|
||||||
|
// Read the remaining multibyte sequence (0b10111111 / 0xbf).
|
||||||
|
ret = mbrtowc(nullptr, "\xbf", 1, &state);
|
||||||
|
|
||||||
|
if (ret != 1ul)
|
||||||
|
FAIL(String::formatted("mbrtowc did not consume the expected number of bytes (1), returned {} instead", static_cast<ssize_t>(ret)));
|
||||||
|
|
||||||
|
// Ensure that we are in an initial state again.
|
||||||
|
EXPECT(mbsinit(&state) != 0);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue