1 /* Test of u8_mbtouc() and u8_mbtouc_unsafe() functions.
2 Copyright (C) 2010-2017 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
20 test_function (int (*my_u8_mbtouc
) (ucs4_t
*, const uint8_t *, size_t))
25 /* Test NUL unit input. */
27 static const uint8_t input
[] = "";
29 ret
= my_u8_mbtouc (&uc
, input
, 1);
34 /* Test ISO 646 unit input. */
39 for (c
= 0; c
< 0x80; c
++)
43 ret
= my_u8_mbtouc (&uc
, buf
, 1);
49 /* Test 2-byte character input. */
51 static const uint8_t input
[] = { 0xC3, 0x97 };
53 ret
= my_u8_mbtouc (&uc
, input
, 2);
55 ASSERT (uc
== 0x00D7);
58 /* Test 3-byte character input. */
60 static const uint8_t input
[] = { 0xE2, 0x82, 0xAC };
62 ret
= my_u8_mbtouc (&uc
, input
, 3);
64 ASSERT (uc
== 0x20AC);
67 /* Test 4-byte character input. */
69 static const uint8_t input
[] = { 0xF4, 0x8F, 0xBF, 0xBD };
71 ret
= my_u8_mbtouc (&uc
, input
, 4);
73 ASSERT (uc
== 0x10FFFD);
76 /* Test incomplete/invalid 1-byte input. */
78 static const uint8_t input
[] = { 0xC1 };
80 ret
= my_u8_mbtouc (&uc
, input
, 1);
82 ASSERT (uc
== 0xFFFD);
85 static const uint8_t input
[] = { 0xC3 };
87 ret
= my_u8_mbtouc (&uc
, input
, 1);
89 ASSERT (uc
== 0xFFFD);
92 static const uint8_t input
[] = { 0xE2 };
94 ret
= my_u8_mbtouc (&uc
, input
, 1);
96 ASSERT (uc
== 0xFFFD);
99 static const uint8_t input
[] = { 0xF4 };
101 ret
= my_u8_mbtouc (&uc
, input
, 1);
103 ASSERT (uc
== 0xFFFD);
106 static const uint8_t input
[] = { 0xFE };
108 ret
= my_u8_mbtouc (&uc
, input
, 1);
110 ASSERT (uc
== 0xFFFD);
113 /* Test incomplete/invalid 2-byte input. */
115 static const uint8_t input
[] = { 0xE0, 0x9F };
117 ret
= my_u8_mbtouc (&uc
, input
, 2);
118 ASSERT (ret
== 1 || ret
== 2);
119 ASSERT (uc
== 0xFFFD);
122 static const uint8_t input
[] = { 0xE2, 0x82 };
124 ret
= my_u8_mbtouc (&uc
, input
, 2);
126 ASSERT (uc
== 0xFFFD);
129 static const uint8_t input
[] = { 0xE2, 0xD0 };
131 ret
= my_u8_mbtouc (&uc
, input
, 2);
132 ASSERT (ret
== 1 || ret
== 2);
133 ASSERT (uc
== 0xFFFD);
136 static const uint8_t input
[] = { 0xF0, 0x8F };
138 ret
= my_u8_mbtouc (&uc
, input
, 2);
139 ASSERT (ret
== 1 || ret
== 2);
140 ASSERT (uc
== 0xFFFD);
143 static const uint8_t input
[] = { 0xF3, 0x8F };
145 ret
= my_u8_mbtouc (&uc
, input
, 2);
147 ASSERT (uc
== 0xFFFD);
150 static const uint8_t input
[] = { 0xF3, 0xD0 };
152 ret
= my_u8_mbtouc (&uc
, input
, 2);
153 ASSERT (ret
== 1 || ret
== 2);
154 ASSERT (uc
== 0xFFFD);
157 /* Test incomplete/invalid 3-byte input. */
159 static const uint8_t input
[] = { 0xF3, 0x8F, 0xBF };
161 ret
= my_u8_mbtouc (&uc
, input
, 3);
163 ASSERT (uc
== 0xFFFD);
166 static const uint8_t input
[] = { 0xF3, 0xD0, 0xBF };
168 ret
= my_u8_mbtouc (&uc
, input
, 3);
170 ASSERT (uc
== 0xFFFD);
173 static const uint8_t input
[] = { 0xF3, 0x8F, 0xD0 };
175 ret
= my_u8_mbtouc (&uc
, input
, 3);
177 ASSERT (uc
== 0xFFFD);