Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
Elliott Hughes | 18181e6 | 2019-01-30 13:52:36 -0800 | [diff] [blame] | 18 | #include <uchar.h> |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 19 | |
| 20 | #include <gtest/gtest.h> |
| 21 | |
| 22 | #include <errno.h> |
| 23 | #include <limits.h> |
| 24 | #include <locale.h> |
| 25 | #include <stdint.h> |
| 26 | |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 27 | // Modern versions of UTF-8 (https://datatracker.ietf.org/doc/html/rfc3629 and |
| 28 | // newer) explicitly disallow code points beyond U+10FFFF, which exclude all 5- |
| 29 | // and 6-byte sequences. Earlier versions of UTF-8 allowed the wider range: |
| 30 | // https://datatracker.ietf.org/doc/html/rfc2279. |
| 31 | // |
| 32 | // Bionic's unicode implementation was written after the high values were |
| 33 | // excluded, so it has never supported them. Other implementations (at least |
| 34 | // as of glibc 2.36), do support those sequences. |
| 35 | #if defined(__ANDROID__) || defined(ANDROID_HOST_MUSL) |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 36 | constexpr bool kLibcRejectsOverLongUtf8Sequences = true; |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 37 | #elif defined(__GLIBC__) |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 38 | constexpr bool kLibcRejectsOverLongUtf8Sequences = false; |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 39 | #else |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 40 | #error kLibcRejectsOverLongUtf8Sequences must be configured for this platform |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 41 | #endif |
| 42 | |
Dan Albert | 9a9bbe5 | 2023-07-18 23:12:47 +0000 | [diff] [blame] | 43 | // C23 7.30.1 (for each `mbrtoc*` function) says: |
| 44 | // |
| 45 | // Returns: |
| 46 | // |
| 47 | // 0 if the next n or fewer bytes complete the multibyte character that |
| 48 | // corresponds to the null wide character (which is the value stored). |
| 49 | // |
| 50 | // (size_t)(-2) if the next n bytes contribute to an incomplete (but |
| 51 | // potentially valid) multibyte character, and all n bytes have been |
| 52 | // processed (no value is stored). |
| 53 | // |
| 54 | // Bionic historically interpreted the behavior when n is 0 to be the next 0 |
| 55 | // bytes decoding to the null. That's a pretty bad interpretation, and both |
| 56 | // glibc and musl return -2 for that case. |
| 57 | // |
| 58 | // The tests currently checks the incorrect behavior for bionic because gtest |
| 59 | // doesn't support explicit xfail annotations. The behavior difference here |
| 60 | // should be fixed, but danalbert wants to add more tests before tackling the |
| 61 | // bugs. |
| 62 | #ifdef __ANDROID__ |
| 63 | constexpr size_t kExpectedResultForZeroLength = 0U; |
| 64 | #else |
| 65 | constexpr size_t kExpectedResultForZeroLength = static_cast<size_t>(-2); |
| 66 | #endif |
| 67 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 68 | TEST(uchar, sizeof_uchar_t) { |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 69 | EXPECT_EQ(2U, sizeof(char16_t)); |
| 70 | EXPECT_EQ(4U, sizeof(char32_t)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | TEST(uchar, start_state) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 74 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 75 | uselocale(LC_GLOBAL_LOCALE); |
| 76 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 77 | char out[MB_LEN_MAX]; |
| 78 | mbstate_t ps; |
| 79 | |
| 80 | // Any non-initial state is invalid when calling c32rtomb. |
| 81 | memset(&ps, 0, sizeof(ps)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 82 | EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps)); |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 83 | errno = 0; |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 84 | EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(out, 0x00a2, &ps)); |
| 85 | EXPECT_EQ(EILSEQ, errno); |
| 86 | |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 87 | // If the first argument to c32rtomb is nullptr or the second is L'\0' the shift |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 88 | // state should be reset. |
| 89 | memset(&ps, 0, sizeof(ps)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 90 | EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xc2", 1, &ps)); |
| 91 | EXPECT_EQ(1U, c32rtomb(nullptr, 0x00a2, &ps)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 92 | EXPECT_TRUE(mbsinit(&ps)); |
| 93 | |
| 94 | memset(&ps, 0, sizeof(ps)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 95 | EXPECT_EQ(static_cast<size_t>(-2), mbrtoc32(nullptr, "\xf0\xa4", 1, &ps)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 96 | EXPECT_EQ(1U, c32rtomb(out, L'\0', &ps)); |
| 97 | EXPECT_TRUE(mbsinit(&ps)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | TEST(uchar, c16rtomb_null_out) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 101 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 102 | uselocale(LC_GLOBAL_LOCALE); |
| 103 | |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 104 | EXPECT_EQ(1U, c16rtomb(nullptr, L'\0', nullptr)); |
| 105 | EXPECT_EQ(1U, c16rtomb(nullptr, L'h', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | TEST(uchar, c16rtomb_null_char) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 109 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 110 | uselocale(LC_GLOBAL_LOCALE); |
| 111 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 112 | char bytes[MB_LEN_MAX]; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 113 | EXPECT_EQ(1U, c16rtomb(bytes, L'\0', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | TEST(uchar, c16rtomb) { |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 117 | char bytes[MB_LEN_MAX]; |
| 118 | |
| 119 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 120 | EXPECT_EQ(1U, c16rtomb(bytes, L'h', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 121 | EXPECT_EQ('h', bytes[0]); |
| 122 | |
| 123 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 124 | uselocale(LC_GLOBAL_LOCALE); |
| 125 | |
| 126 | // 1-byte UTF-8. |
| 127 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 128 | EXPECT_EQ(1U, c16rtomb(bytes, L'h', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 129 | EXPECT_EQ('h', bytes[0]); |
| 130 | // 2-byte UTF-8. |
| 131 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 132 | EXPECT_EQ(2U, c16rtomb(bytes, 0x00a2, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 133 | EXPECT_EQ('\xc2', bytes[0]); |
| 134 | EXPECT_EQ('\xa2', bytes[1]); |
| 135 | // 3-byte UTF-8. |
| 136 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 137 | EXPECT_EQ(3U, c16rtomb(bytes, 0x20ac, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 138 | EXPECT_EQ('\xe2', bytes[0]); |
| 139 | EXPECT_EQ('\x82', bytes[1]); |
| 140 | EXPECT_EQ('\xac', bytes[2]); |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 141 | // 4-byte UTF-8 from a surrogate pair... |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 142 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 143 | EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, nullptr)); |
| 144 | EXPECT_EQ(4U, c16rtomb(bytes, 0xdfcd, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 145 | EXPECT_EQ('\xf4', bytes[0]); |
| 146 | EXPECT_EQ('\x8a', bytes[1]); |
| 147 | EXPECT_EQ('\xaf', bytes[2]); |
| 148 | EXPECT_EQ('\x8d', bytes[3]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | TEST(uchar, c16rtomb_invalid) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 152 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 153 | uselocale(LC_GLOBAL_LOCALE); |
| 154 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 155 | char bytes[MB_LEN_MAX]; |
| 156 | |
| 157 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 158 | EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdfcd, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 159 | |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 160 | EXPECT_EQ(0U, c16rtomb(bytes, 0xdbea, nullptr)); |
| 161 | EXPECT_EQ(static_cast<size_t>(-1), c16rtomb(bytes, 0xdbea, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | TEST(uchar, mbrtoc16_null) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 165 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 166 | uselocale(LC_GLOBAL_LOCALE); |
| 167 | |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 168 | ASSERT_EQ(0U, mbrtoc16(nullptr, nullptr, 0, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | TEST(uchar, mbrtoc16_zero_len) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 172 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 173 | uselocale(LC_GLOBAL_LOCALE); |
| 174 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 175 | char16_t out; |
| 176 | |
Alexander Ivchenko | 68b0166 | 2014-06-11 16:20:54 +0400 | [diff] [blame] | 177 | out = L'x'; |
Dan Albert | 9a9bbe5 | 2023-07-18 23:12:47 +0000 | [diff] [blame] | 178 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc16(&out, "hello", 0, nullptr)); |
| 179 | EXPECT_EQ(L'x', out); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 180 | |
Dan Albert | 9a9bbe5 | 2023-07-18 23:12:47 +0000 | [diff] [blame] | 181 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc16(&out, "hello", 0, nullptr)); |
| 182 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc16(&out, "", 0, nullptr)); |
| 183 | EXPECT_EQ(1U, mbrtoc16(&out, "hello", 1, nullptr)); |
| 184 | EXPECT_EQ(L'h', out); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | TEST(uchar, mbrtoc16) { |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 188 | char16_t out; |
| 189 | |
| 190 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 191 | uselocale(LC_GLOBAL_LOCALE); |
| 192 | |
| 193 | // 1-byte UTF-8. |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 194 | ASSERT_EQ(1U, mbrtoc16(&out, "abcdef", 6, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 195 | ASSERT_EQ(L'a', out); |
| 196 | // 2-byte UTF-8. |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 197 | ASSERT_EQ(2U, mbrtoc16(&out, "\xc2\xa2" "cdef", 6, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 198 | ASSERT_EQ(static_cast<char16_t>(0x00a2), out); |
| 199 | // 3-byte UTF-8. |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 200 | ASSERT_EQ(3U, mbrtoc16(&out, "\xe2\x82\xac" "def", 6, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 201 | ASSERT_EQ(static_cast<char16_t>(0x20ac), out); |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 202 | // 4-byte UTF-8 will be returned as a surrogate pair... |
Dan Albert | 1e8e0c1 | 2023-07-19 19:14:45 +0000 | [diff] [blame] | 203 | #ifdef __BIONIC__ |
| 204 | // https://issuetracker.google.com/289419882 |
| 205 | // |
| 206 | // We misread the spec when implementing this. The first call should return |
| 207 | // the length of the decoded character, and the second call should return -3 |
| 208 | // to indicate that the output is a continuation of the character decoded by |
| 209 | // the first call. |
| 210 | // |
| 211 | // C23 7.30.1.3.4: |
| 212 | // |
| 213 | // between 1 and n inclusive if the next n or fewer bytes complete a valid |
| 214 | // multibyte character (which is the value stored); the value returned is |
| 215 | // the number of bytes that complete the multibyte character. |
| 216 | // |
| 217 | // (size_t)(-3) if the next character resulting from a previous call has |
| 218 | // been stored (no bytes from the input have been consumed by this call). |
| 219 | // |
| 220 | // Leaving the test for the wrong outputs here while we clean up and improve |
| 221 | // the rest of the tests to get a better handle on the behavior differences |
| 222 | // before fixing the bug. |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 223 | ASSERT_EQ(static_cast<size_t>(-3), |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 224 | mbrtoc16(&out, "\xf4\x8a\xaf\x8d", 6, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 225 | ASSERT_EQ(static_cast<char16_t>(0xdbea), out); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 226 | ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d" "ef", 6, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 227 | ASSERT_EQ(static_cast<char16_t>(0xdfcd), out); |
Dan Albert | 1e8e0c1 | 2023-07-19 19:14:45 +0000 | [diff] [blame] | 228 | #else |
| 229 | ASSERT_EQ(4U, mbrtoc16(&out, "\xf4\x8a\xaf\x8d", 6, nullptr)); |
| 230 | ASSERT_EQ(static_cast<char16_t>(0xdbea), out); |
| 231 | ASSERT_EQ(static_cast<size_t>(-3), mbrtoc16(&out, |
| 232 | "\xf4\x8a\xaf\x8d" |
| 233 | "ef", |
| 234 | 6, nullptr)); |
| 235 | ASSERT_EQ(static_cast<char16_t>(0xdfcd), out); |
| 236 | #endif |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | TEST(uchar, mbrtoc16_long_sequences) { |
| 240 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 241 | uselocale(LC_GLOBAL_LOCALE); |
| 242 | |
| 243 | char16_t out = u'\0'; |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 244 | errno = 0; |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 245 | auto result = mbrtoc16(&out, "\xf8\xa1\xa2\xa3\xa4", 5, nullptr); |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 246 | if (kLibcRejectsOverLongUtf8Sequences) { |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 247 | EXPECT_EQ(static_cast<size_t>(-1), result); |
| 248 | EXPECT_EQ(EILSEQ, errno); |
| 249 | EXPECT_EQ(u'\0', out); |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 250 | } else { |
| 251 | EXPECT_EQ(5U, result); |
| 252 | EXPECT_EQ(0, errno); |
| 253 | EXPECT_EQ(u'\uf94a', out); |
Dan Albert | 1252ab0 | 2023-07-14 21:23:36 +0000 | [diff] [blame] | 254 | } |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | TEST(uchar, mbrtoc16_reserved_range) { |
Dan Albert | ef8e158 | 2023-07-19 19:34:12 +0000 | [diff] [blame] | 258 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 259 | uselocale(LC_GLOBAL_LOCALE); |
Dan Albert | ef8e158 | 2023-07-19 19:34:12 +0000 | [diff] [blame] | 260 | |
| 261 | errno = 0; |
| 262 | char16_t out = u'\0'; |
| 263 | EXPECT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\xf0\x80\xbf\xbf", 6, nullptr)); |
| 264 | EXPECT_EQ(u'\0', out); |
| 265 | EXPECT_EQ(EILSEQ, errno); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST(uchar, mbrtoc16_beyond_range) { |
Dan Albert | f5b8c7d | 2023-07-19 19:38:11 +0000 | [diff] [blame] | 269 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 270 | uselocale(LC_GLOBAL_LOCALE); |
Dan Albert | f5b8c7d | 2023-07-19 19:38:11 +0000 | [diff] [blame] | 271 | |
| 272 | errno = 0; |
| 273 | char16_t out = u'\0'; |
| 274 | auto result = mbrtoc16(&out, "\xf5\x80\x80\x80", 6, nullptr); |
| 275 | if (kLibcRejectsOverLongUtf8Sequences) { |
| 276 | EXPECT_EQ(static_cast<size_t>(-1), result); |
| 277 | EXPECT_EQ(u'\0', out); |
| 278 | EXPECT_EQ(EILSEQ, errno); |
| 279 | } else { |
| 280 | EXPECT_EQ(4U, result); |
| 281 | EXPECT_EQ(u'\xdcc0', out); |
| 282 | EXPECT_EQ(0, errno); |
| 283 | } |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 286 | void test_mbrtoc16_incomplete(mbstate_t* ps) { |
| 287 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 288 | uselocale(LC_GLOBAL_LOCALE); |
| 289 | |
| 290 | char16_t out; |
| 291 | // 2-byte UTF-8. |
| 292 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xc2", 1, ps)); |
| 293 | ASSERT_EQ(1U, mbrtoc16(&out, "\xa2" "cdef", 5, ps)); |
| 294 | ASSERT_EQ(static_cast<char16_t>(0x00a2), out); |
| 295 | ASSERT_TRUE(mbsinit(ps)); |
| 296 | // 3-byte UTF-8. |
| 297 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xe2", 1, ps)); |
| 298 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\x82", 1, ps)); |
| 299 | ASSERT_EQ(1U, mbrtoc16(&out, "\xac" "def", 4, ps)); |
| 300 | ASSERT_EQ(static_cast<char16_t>(0x20ac), out); |
| 301 | ASSERT_TRUE(mbsinit(ps)); |
| 302 | // 4-byte UTF-8. |
| 303 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xf4", 1, ps)); |
| 304 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\x8a\xaf", 2, ps)); |
Dan Albert | 1e8e0c1 | 2023-07-19 19:14:45 +0000 | [diff] [blame] | 305 | #ifdef __BIONIC__ |
| 306 | // https://issuetracker.google.com/289419882 |
| 307 | // See explanation in mbrtoc16 test for the same bug. |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 308 | ASSERT_EQ(static_cast<size_t>(-3), mbrtoc16(&out, "\x8d" "ef", 3, ps)); |
| 309 | ASSERT_EQ(static_cast<char16_t>(0xdbea), out); |
| 310 | ASSERT_EQ(1U, mbrtoc16(&out, "\x80" "ef", 3, ps)); |
| 311 | ASSERT_EQ(static_cast<char16_t>(0xdfcd), out); |
Dan Albert | 1e8e0c1 | 2023-07-19 19:14:45 +0000 | [diff] [blame] | 312 | #else |
| 313 | ASSERT_EQ(1U, mbrtoc16(&out, |
| 314 | "\x8d" |
| 315 | "ef", |
| 316 | 3, ps)); |
| 317 | ASSERT_EQ(static_cast<char16_t>(0xdbea), out); |
| 318 | ASSERT_EQ(static_cast<size_t>(-3), mbrtoc16(&out, |
| 319 | "\x80" |
| 320 | "ef", |
| 321 | 3, ps)); |
| 322 | ASSERT_EQ(static_cast<char16_t>(0xdfcd), out); |
| 323 | #endif |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 324 | ASSERT_TRUE(mbsinit(ps)); |
| 325 | |
| 326 | // Invalid 2-byte |
| 327 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc16(&out, "\xc2", 1, ps)); |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 328 | errno = 0; |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 329 | ASSERT_EQ(static_cast<size_t>(-1), mbrtoc16(&out, "\x20" "cdef", 5, ps)); |
| 330 | ASSERT_EQ(EILSEQ, errno); |
| 331 | } |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 332 | |
| 333 | TEST(uchar, mbrtoc16_incomplete) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 334 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 335 | uselocale(LC_GLOBAL_LOCALE); |
| 336 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 337 | mbstate_t ps; |
| 338 | memset(&ps, 0, sizeof(ps)); |
| 339 | |
| 340 | test_mbrtoc16_incomplete(&ps); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 341 | test_mbrtoc16_incomplete(nullptr); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | TEST(uchar, c32rtomb) { |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 345 | EXPECT_EQ(1U, c32rtomb(nullptr, L'\0', nullptr)); |
| 346 | EXPECT_EQ(1U, c32rtomb(nullptr, L'h', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 347 | |
| 348 | char bytes[MB_LEN_MAX]; |
| 349 | |
Elliott Hughes | 697f42a | 2017-07-14 17:00:05 -0700 | [diff] [blame] | 350 | memset(bytes, 1, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 351 | EXPECT_EQ(1U, c32rtomb(bytes, L'\0', nullptr)); |
Elliott Hughes | 697f42a | 2017-07-14 17:00:05 -0700 | [diff] [blame] | 352 | EXPECT_EQ('\0', bytes[0]); |
| 353 | EXPECT_EQ('\x01', bytes[1]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 354 | |
| 355 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 356 | EXPECT_EQ(1U, c32rtomb(bytes, L'h', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 357 | EXPECT_EQ('h', bytes[0]); |
| 358 | |
| 359 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 360 | uselocale(LC_GLOBAL_LOCALE); |
| 361 | |
| 362 | // 1-byte UTF-8. |
| 363 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 364 | EXPECT_EQ(1U, c32rtomb(bytes, L'h', nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 365 | EXPECT_EQ('h', bytes[0]); |
| 366 | // 2-byte UTF-8. |
| 367 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 368 | EXPECT_EQ(2U, c32rtomb(bytes, 0x00a2, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 369 | EXPECT_EQ('\xc2', bytes[0]); |
| 370 | EXPECT_EQ('\xa2', bytes[1]); |
| 371 | // 3-byte UTF-8. |
| 372 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 373 | EXPECT_EQ(3U, c32rtomb(bytes, 0x20ac, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 374 | EXPECT_EQ('\xe2', bytes[0]); |
| 375 | EXPECT_EQ('\x82', bytes[1]); |
| 376 | EXPECT_EQ('\xac', bytes[2]); |
| 377 | // 4-byte UTF-8. |
| 378 | memset(bytes, 0, sizeof(bytes)); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 379 | EXPECT_EQ(4U, c32rtomb(bytes, 0x24b62, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 380 | EXPECT_EQ('\xf0', bytes[0]); |
| 381 | EXPECT_EQ('\xa4', bytes[1]); |
| 382 | EXPECT_EQ('\xad', bytes[2]); |
| 383 | EXPECT_EQ('\xa2', bytes[3]); |
| 384 | // Invalid code point. |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 385 | errno = 0; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 386 | EXPECT_EQ(static_cast<size_t>(-1), c32rtomb(bytes, 0xffffffff, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 387 | EXPECT_EQ(EILSEQ, errno); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Elliott Hughes | 402c762 | 2018-07-06 17:18:05 -0700 | [diff] [blame] | 390 | TEST(uchar, mbrtoc32_valid_non_characters) { |
Elliott Hughes | 402c762 | 2018-07-06 17:18:05 -0700 | [diff] [blame] | 391 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 392 | uselocale(LC_GLOBAL_LOCALE); |
| 393 | |
| 394 | char32_t out[8] = {}; |
| 395 | ASSERT_EQ(3U, mbrtoc32(out, "\xef\xbf\xbe", 3, nullptr)); |
| 396 | ASSERT_EQ(0xfffeU, out[0]); |
| 397 | ASSERT_EQ(3U, mbrtoc32(out, "\xef\xbf\xbf", 3, nullptr)); |
| 398 | ASSERT_EQ(0xffffU, out[0]); |
Elliott Hughes | 402c762 | 2018-07-06 17:18:05 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | TEST(uchar, mbrtoc32_out_of_range) { |
Elliott Hughes | 402c762 | 2018-07-06 17:18:05 -0700 | [diff] [blame] | 402 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 403 | uselocale(LC_GLOBAL_LOCALE); |
| 404 | |
Dan Albert | 9fa76f1 | 2023-07-18 22:58:53 +0000 | [diff] [blame] | 405 | char32_t out = U'\0'; |
Elliott Hughes | 402c762 | 2018-07-06 17:18:05 -0700 | [diff] [blame] | 406 | errno = 0; |
Dan Albert | 9fa76f1 | 2023-07-18 22:58:53 +0000 | [diff] [blame] | 407 | auto result = mbrtoc32(&out, "\xf5\x80\x80\x80", 4, nullptr); |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 408 | if (kLibcRejectsOverLongUtf8Sequences) { |
Dan Albert | 9fa76f1 | 2023-07-18 22:58:53 +0000 | [diff] [blame] | 409 | EXPECT_EQ(static_cast<size_t>(-1), result); |
| 410 | EXPECT_EQ(EILSEQ, errno); |
| 411 | EXPECT_EQ(U'\0', out); |
Dan Albert | 78da292 | 2023-07-19 18:23:46 +0000 | [diff] [blame] | 412 | } else { |
| 413 | EXPECT_EQ(4U, result); |
| 414 | EXPECT_EQ(0, errno); |
| 415 | EXPECT_EQ(U'\x140000', out); |
Dan Albert | 9fa76f1 | 2023-07-18 22:58:53 +0000 | [diff] [blame] | 416 | } |
Elliott Hughes | 402c762 | 2018-07-06 17:18:05 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 419 | TEST(uchar, mbrtoc32) { |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 420 | char32_t out[8]; |
| 421 | |
Alexander Ivchenko | 68b0166 | 2014-06-11 16:20:54 +0400 | [diff] [blame] | 422 | out[0] = L'x'; |
Dan Albert | 9a9bbe5 | 2023-07-18 23:12:47 +0000 | [diff] [blame] | 423 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc32(out, "hello", 0, nullptr)); |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 424 | EXPECT_EQ(static_cast<char32_t>(L'x'), out[0]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 425 | |
Dan Albert | 9a9bbe5 | 2023-07-18 23:12:47 +0000 | [diff] [blame] | 426 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc32(out, "hello", 0, nullptr)); |
| 427 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc32(out, "", 0, nullptr)); |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 428 | EXPECT_EQ(1U, mbrtoc32(out, "hello", 1, nullptr)); |
| 429 | EXPECT_EQ(static_cast<char32_t>(L'h'), out[0]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 430 | |
Dan Albert | 9a9bbe5 | 2023-07-18 23:12:47 +0000 | [diff] [blame] | 431 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc32(nullptr, "hello", 0, nullptr)); |
| 432 | EXPECT_EQ(kExpectedResultForZeroLength, mbrtoc32(nullptr, "", 0, nullptr)); |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 433 | EXPECT_EQ(1U, mbrtoc32(nullptr, "hello", 1, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 434 | |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 435 | EXPECT_EQ(0U, mbrtoc32(nullptr, nullptr, 0, nullptr)); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 436 | |
| 437 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 438 | uselocale(LC_GLOBAL_LOCALE); |
| 439 | |
| 440 | // 1-byte UTF-8. |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 441 | EXPECT_EQ(1U, mbrtoc32(out, "abcdef", 6, nullptr)); |
| 442 | EXPECT_EQ(static_cast<char32_t>(L'a'), out[0]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 443 | // 2-byte UTF-8. |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 444 | EXPECT_EQ(2U, mbrtoc32(out, |
| 445 | "\xc2\xa2" |
| 446 | "cdef", |
| 447 | 6, nullptr)); |
| 448 | EXPECT_EQ(static_cast<char32_t>(0x00a2), out[0]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 449 | // 3-byte UTF-8. |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 450 | EXPECT_EQ(3U, mbrtoc32(out, |
| 451 | "\xe2\x82\xac" |
| 452 | "def", |
| 453 | 6, nullptr)); |
| 454 | EXPECT_EQ(static_cast<char32_t>(0x20ac), out[0]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 455 | // 4-byte UTF-8. |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 456 | EXPECT_EQ(4U, mbrtoc32(out, |
| 457 | "\xf0\xa4\xad\xa2" |
| 458 | "ef", |
| 459 | 6, nullptr)); |
| 460 | EXPECT_EQ(static_cast<char32_t>(0x24b62), out[0]); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 461 | #if defined(__BIONIC__) // glibc allows this. |
| 462 | // Illegal 5-byte UTF-8. |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 463 | errno = 0; |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 464 | EXPECT_EQ(static_cast<size_t>(-1), mbrtoc32(out, |
| 465 | "\xf8\xa1\xa2\xa3\xa4" |
| 466 | "f", |
| 467 | 6, nullptr)); |
| 468 | EXPECT_EQ(EILSEQ, errno); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 469 | #endif |
| 470 | // Illegal over-long sequence. |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 471 | errno = 0; |
Dan Albert | 0b8fbdf | 2023-07-18 22:21:36 +0000 | [diff] [blame] | 472 | EXPECT_EQ(static_cast<size_t>(-1), mbrtoc32(out, |
| 473 | "\xf0\x82\x82\xac" |
| 474 | "ef", |
| 475 | 6, nullptr)); |
| 476 | EXPECT_EQ(EILSEQ, errno); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 479 | void test_mbrtoc32_incomplete(mbstate_t* ps) { |
| 480 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 481 | uselocale(LC_GLOBAL_LOCALE); |
| 482 | |
| 483 | char32_t out; |
| 484 | // 2-byte UTF-8. |
| 485 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xc2", 1, ps)); |
| 486 | ASSERT_EQ(1U, mbrtoc32(&out, "\xa2" "cdef", 5, ps)); |
| 487 | ASSERT_EQ(static_cast<char32_t>(0x00a2), out); |
| 488 | ASSERT_TRUE(mbsinit(ps)); |
| 489 | // 3-byte UTF-8. |
| 490 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xe2", 1, ps)); |
| 491 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\x82", 1, ps)); |
| 492 | ASSERT_EQ(1U, mbrtoc32(&out, "\xac" "def", 4, ps)); |
| 493 | ASSERT_EQ(static_cast<char32_t>(0x20ac), out); |
| 494 | ASSERT_TRUE(mbsinit(ps)); |
| 495 | // 4-byte UTF-8. |
| 496 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xf0", 1, ps)); |
| 497 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xa4\xad", 2, ps)); |
| 498 | ASSERT_EQ(1U, mbrtoc32(&out, "\xa2" "ef", 3, ps)); |
| 499 | ASSERT_EQ(static_cast<char32_t>(0x24b62), out); |
| 500 | ASSERT_TRUE(mbsinit(ps)); |
| 501 | |
| 502 | // Invalid 2-byte |
| 503 | ASSERT_EQ(static_cast<size_t>(-2), mbrtoc32(&out, "\xc2", 1, ps)); |
Elliott Hughes | 3d8156d | 2021-11-05 17:47:07 -0700 | [diff] [blame] | 504 | errno = 0; |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 505 | ASSERT_EQ(static_cast<size_t>(-1), mbrtoc32(&out, "\x20" "cdef", 5, ps)); |
| 506 | ASSERT_EQ(EILSEQ, errno); |
| 507 | } |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 508 | |
| 509 | TEST(uchar, mbrtoc32_incomplete) { |
Dan Albert | a0d0e35 | 2023-07-19 22:12:59 +0000 | [diff] [blame^] | 510 | ASSERT_STREQ("C.UTF-8", setlocale(LC_CTYPE, "C.UTF-8")); |
| 511 | uselocale(LC_GLOBAL_LOCALE); |
| 512 | |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 513 | mbstate_t ps; |
| 514 | memset(&ps, 0, sizeof(ps)); |
| 515 | |
| 516 | test_mbrtoc32_incomplete(&ps); |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 517 | test_mbrtoc32_incomplete(nullptr); |
Dan Albert | 7a7f995 | 2014-06-02 11:33:04 -0700 | [diff] [blame] | 518 | } |