diff options
author | Elliott Hughes <enh@google.com> | 2014-06-05 20:10:09 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-06-05 23:19:15 -0700 |
commit | 69f05d291d848de654c72e5278de8ca06fbf5d2f (patch) | |
tree | f43847693b03d7978e7234577f2d6d843f3ec356 /tests/wchar_test.cpp | |
parent | 8aabecf35c71a8255db259cba01005eea10485cf (diff) | |
download | android_bionic-69f05d291d848de654c72e5278de8ca06fbf5d2f.tar.gz android_bionic-69f05d291d848de654c72e5278de8ca06fbf5d2f.tar.bz2 android_bionic-69f05d291d848de654c72e5278de8ca06fbf5d2f.zip |
Fix the printf family for non-ASCII.
The bug here turned out to be that we hadn't increased the constant
corresponding to the maximum number of bytes in a character to match
our new implementation, so any character requiring more than a byte
in UTF-8 would break our printf family.
Bug: 15439554
Change-Id: I693e5e6eb11c640b5886e848502908ec5fff53b1
Diffstat (limited to 'tests/wchar_test.cpp')
-rw-r--r-- | tests/wchar_test.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp index e76026f26..a5f5f63a2 100644 --- a/tests/wchar_test.cpp +++ b/tests/wchar_test.cpp @@ -449,3 +449,32 @@ TEST(wchar, wmemmove) { wmemmove(wstr+5, wstr, sizeof(const_wstr)/sizeof(wchar_t) - 6); EXPECT_STREQ(L"This This is a test of something or other", wstr); } + +TEST(wchar, mbrtowc_15439554) { + // http://b/15439554 + ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); + uselocale(LC_GLOBAL_LOCALE); + + ASSERT_GE(static_cast<size_t>(MB_LEN_MAX), MB_CUR_MAX); + ASSERT_GE(MB_CUR_MAX, 4U); + + wchar_t wc; + size_t n; + + // 1-byte character. + n = mbrtowc(&wc, "x", MB_CUR_MAX, NULL); + EXPECT_EQ(1U, n); + EXPECT_EQ(L'x', wc); + // 2-byte character. + n = mbrtowc(&wc, "\xc2\xa2", MB_CUR_MAX, NULL); + EXPECT_EQ(2U, n); + EXPECT_EQ(L'¢', wc); + // 3-byte character. + n = mbrtowc(&wc, "\xe2\x82\xac", MB_CUR_MAX, NULL); + EXPECT_EQ(3U, n); + EXPECT_EQ(L'€', wc); + // 4-byte character. + n = mbrtowc(&wc, "\xf0\xa4\xad\xa2", MB_CUR_MAX, NULL); + EXPECT_EQ(4U, n); + EXPECT_EQ(L'𤭢', wc); +} |