1 /* Test of u8_next() function.
2 Copyright (C) 2010-2020 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 <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
31 /* Test NUL unit input. */
33 static const uint8_t input
[] = "";
35 ret
= u8_next (&uc
, input
);
40 /* Test ISO 646 unit input. */
45 for (c
= 1; c
< 0x80; c
++)
50 ret
= u8_next (&uc
, buf
);
51 ASSERT (ret
== buf
+ 1);
56 /* Test 2-byte character input. */
58 static const uint8_t input
[] = { 0xC3, 0x97, 0 };
60 ret
= u8_next (&uc
, input
);
61 ASSERT (ret
== input
+ 2);
62 ASSERT (uc
== 0x00D7);
65 /* Test 3-byte character input. */
67 static const uint8_t input
[] = { 0xE2, 0x82, 0xAC, 0 };
69 ret
= u8_next (&uc
, input
);
70 ASSERT (ret
== input
+ 3);
71 ASSERT (uc
== 0x20AC);
74 /* Test 4-byte character input. */
76 static const uint8_t input
[] = { 0xF4, 0x8F, 0xBF, 0xBD, 0 };
78 ret
= u8_next (&uc
, input
);
79 ASSERT (ret
== input
+ 4);
80 ASSERT (uc
== 0x10FFFD);
83 /* Test incomplete/invalid 1-byte input. */
85 static const uint8_t input
[] = { 0xC1, 0 };
87 ret
= u8_next (&uc
, input
);
89 ASSERT (uc
== 0xFFFD);
92 static const uint8_t input
[] = { 0xC3, 0 };
94 ret
= u8_next (&uc
, input
);
96 ASSERT (uc
== 0xFFFD);
99 static const uint8_t input
[] = { 0xE2, 0 };
101 ret
= u8_next (&uc
, input
);
102 ASSERT (ret
== NULL
);
103 ASSERT (uc
== 0xFFFD);
106 static const uint8_t input
[] = { 0xF4, 0 };
108 ret
= u8_next (&uc
, input
);
109 ASSERT (ret
== NULL
);
110 ASSERT (uc
== 0xFFFD);
113 static const uint8_t input
[] = { 0xFE, 0 };
115 ret
= u8_next (&uc
, input
);
116 ASSERT (ret
== NULL
);
117 ASSERT (uc
== 0xFFFD);
120 /* Test incomplete/invalid 2-byte input. */
122 static const uint8_t input
[] = { 0xE0, 0x9F, 0 };
124 ret
= u8_next (&uc
, input
);
125 ASSERT (ret
== NULL
);
126 ASSERT (uc
== 0xFFFD);
129 static const uint8_t input
[] = { 0xE2, 0x82, 0 };
131 ret
= u8_next (&uc
, input
);
132 ASSERT (ret
== NULL
);
133 ASSERT (uc
== 0xFFFD);
136 static const uint8_t input
[] = { 0xE2, 0xD0, 0 };
138 ret
= u8_next (&uc
, input
);
139 ASSERT (ret
== NULL
);
140 ASSERT (uc
== 0xFFFD);
143 static const uint8_t input
[] = { 0xF0, 0x8F, 0 };
145 ret
= u8_next (&uc
, input
);
146 ASSERT (ret
== NULL
);
147 ASSERT (uc
== 0xFFFD);
150 static const uint8_t input
[] = { 0xF3, 0x8F, 0 };
152 ret
= u8_next (&uc
, input
);
153 ASSERT (ret
== NULL
);
154 ASSERT (uc
== 0xFFFD);
157 static const uint8_t input
[] = { 0xF3, 0xD0, 0 };
159 ret
= u8_next (&uc
, input
);
160 ASSERT (ret
== NULL
);
161 ASSERT (uc
== 0xFFFD);
164 /* Test incomplete/invalid 3-byte input. */
166 static const uint8_t input
[] = { 0xF3, 0x8F, 0xBF, 0 };
168 ret
= u8_next (&uc
, input
);
169 ASSERT (ret
== NULL
);
170 ASSERT (uc
== 0xFFFD);
173 static const uint8_t input
[] = { 0xF3, 0xD0, 0xBF, 0 };
175 ret
= u8_next (&uc
, input
);
176 ASSERT (ret
== NULL
);
177 ASSERT (uc
== 0xFFFD);
180 static const uint8_t input
[] = { 0xF3, 0x8F, 0xD0, 0 };
182 ret
= u8_next (&uc
, input
);
183 ASSERT (ret
== NULL
);
184 ASSERT (uc
== 0xFFFD);