Support compiling without -loldnames on native Windows.
[gnulib.git] / tests / unistr / test-u8-next.c
blob610357d72ac4ecae4a4e1fedbf711e77e66e274f
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. */
19 #include <config.h>
21 #include "unistr.h"
23 #include "macros.h"
25 int
26 main ()
28 ucs4_t uc;
29 const uint8_t *ret;
31 /* Test NUL unit input. */
33 static const uint8_t input[] = "";
34 uc = 0xBADFACE;
35 ret = u8_next (&uc, input);
36 ASSERT (ret == NULL);
37 ASSERT (uc == 0);
40 /* Test ISO 646 unit input. */
42 ucs4_t c;
43 uint8_t buf[2];
45 for (c = 1; c < 0x80; c++)
47 buf[0] = c;
48 buf[1] = 0;
49 uc = 0xBADFACE;
50 ret = u8_next (&uc, buf);
51 ASSERT (ret == buf + 1);
52 ASSERT (uc == c);
56 /* Test 2-byte character input. */
58 static const uint8_t input[] = { 0xC3, 0x97, 0 };
59 uc = 0xBADFACE;
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 };
68 uc = 0xBADFACE;
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 };
77 uc = 0xBADFACE;
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 };
86 uc = 0xBADFACE;
87 ret = u8_next (&uc, input);
88 ASSERT (ret == NULL);
89 ASSERT (uc == 0xFFFD);
92 static const uint8_t input[] = { 0xC3, 0 };
93 uc = 0xBADFACE;
94 ret = u8_next (&uc, input);
95 ASSERT (ret == NULL);
96 ASSERT (uc == 0xFFFD);
99 static const uint8_t input[] = { 0xE2, 0 };
100 uc = 0xBADFACE;
101 ret = u8_next (&uc, input);
102 ASSERT (ret == NULL);
103 ASSERT (uc == 0xFFFD);
106 static const uint8_t input[] = { 0xF4, 0 };
107 uc = 0xBADFACE;
108 ret = u8_next (&uc, input);
109 ASSERT (ret == NULL);
110 ASSERT (uc == 0xFFFD);
113 static const uint8_t input[] = { 0xFE, 0 };
114 uc = 0xBADFACE;
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 };
123 uc = 0xBADFACE;
124 ret = u8_next (&uc, input);
125 ASSERT (ret == NULL);
126 ASSERT (uc == 0xFFFD);
129 static const uint8_t input[] = { 0xE2, 0x82, 0 };
130 uc = 0xBADFACE;
131 ret = u8_next (&uc, input);
132 ASSERT (ret == NULL);
133 ASSERT (uc == 0xFFFD);
136 static const uint8_t input[] = { 0xE2, 0xD0, 0 };
137 uc = 0xBADFACE;
138 ret = u8_next (&uc, input);
139 ASSERT (ret == NULL);
140 ASSERT (uc == 0xFFFD);
143 static const uint8_t input[] = { 0xF0, 0x8F, 0 };
144 uc = 0xBADFACE;
145 ret = u8_next (&uc, input);
146 ASSERT (ret == NULL);
147 ASSERT (uc == 0xFFFD);
150 static const uint8_t input[] = { 0xF3, 0x8F, 0 };
151 uc = 0xBADFACE;
152 ret = u8_next (&uc, input);
153 ASSERT (ret == NULL);
154 ASSERT (uc == 0xFFFD);
157 static const uint8_t input[] = { 0xF3, 0xD0, 0 };
158 uc = 0xBADFACE;
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 };
167 uc = 0xBADFACE;
168 ret = u8_next (&uc, input);
169 ASSERT (ret == NULL);
170 ASSERT (uc == 0xFFFD);
173 static const uint8_t input[] = { 0xF3, 0xD0, 0xBF, 0 };
174 uc = 0xBADFACE;
175 ret = u8_next (&uc, input);
176 ASSERT (ret == NULL);
177 ASSERT (uc == 0xFFFD);
180 static const uint8_t input[] = { 0xF3, 0x8F, 0xD0, 0 };
181 uc = 0xBADFACE;
182 ret = u8_next (&uc, input);
183 ASSERT (ret == NULL);
184 ASSERT (uc == 0xFFFD);
187 return 0;