diff options
author | Elliott Hughes <enh@google.com> | 2016-04-28 14:54:52 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-04-28 16:41:29 -0700 |
commit | 6f6f9058fa7ba3cc9d53bd93e46c254ef8e8cd96 (patch) | |
tree | 572c806c787d2c3a1626a9d97b37de78072f3485 /tests/stdlib_test.cpp | |
parent | 671e6b20eabd0a1ab973f77dff272a00a4096ee7 (diff) |
Implement mblen(3).
Change-Id: I65948ea5b9ecd63f966ba767ad6db4a2effc4700
Diffstat (limited to 'tests/stdlib_test.cpp')
-rw-r--r-- | tests/stdlib_test.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 05438eb17..773230f2f 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -537,3 +537,26 @@ TEST(stdlib, getsubopt) { ASSERT_EQ(-1, getsubopt(&subopts, tokens, &value)); } + +TEST(stdlib, mblen) { + // "If s is a null pointer, mblen() shall return a non-zero or 0 value, if character encodings, + // respectively, do or do not have state-dependent encodings." We're always UTF-8. + EXPECT_EQ(0, mblen(nullptr, 1)); + + ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8")); + + // 1-byte UTF-8. + EXPECT_EQ(1, mblen("abcdef", 6)); + // 2-byte UTF-8. + EXPECT_EQ(2, mblen("\xc2\xa2" "cdef", 6)); + // 3-byte UTF-8. + EXPECT_EQ(3, mblen("\xe2\x82\xac" "def", 6)); + // 4-byte UTF-8. + EXPECT_EQ(4, mblen("\xf0\xa4\xad\xa2" "ef", 6)); + + // Illegal over-long sequence. + ASSERT_EQ(-1, mblen("\xf0\x82\x82\xac" "ef", 6)); + + // "mblen() shall ... return 0 (if s points to the null byte)". + EXPECT_EQ(0, mblen("", 1)); +} |