Support compiling without -loldnames on native Windows.
[gnulib.git] / tests / unistr / test-u8-mbtouc.h
blob7f3a8f9750716c7fc6afb11f356b2442ea8a33fd
1 /* Test of u8_mbtouc() and u8_mbtouc_unsafe() functions.
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 static void
20 test_function (int (*my_u8_mbtouc) (ucs4_t *, const uint8_t *, size_t))
22 ucs4_t uc;
23 int ret;
25 /* Test NUL unit input. */
27 static const uint8_t input[] = "";
28 uc = 0xBADFACE;
29 ret = my_u8_mbtouc (&uc, input, 1);
30 ASSERT (ret == 1);
31 ASSERT (uc == 0);
34 /* Test ISO 646 unit input. */
36 ucs4_t c;
37 uint8_t buf[1];
39 for (c = 0; c < 0x80; c++)
41 buf[0] = c;
42 uc = 0xBADFACE;
43 ret = my_u8_mbtouc (&uc, buf, 1);
44 ASSERT (ret == 1);
45 ASSERT (uc == c);
49 /* Test 2-byte character input. */
51 static const uint8_t input[] = { 0xC3, 0x97 };
52 uc = 0xBADFACE;
53 ret = my_u8_mbtouc (&uc, input, 2);
54 ASSERT (ret == 2);
55 ASSERT (uc == 0x00D7);
58 /* Test 3-byte character input. */
60 static const uint8_t input[] = { 0xE2, 0x82, 0xAC };
61 uc = 0xBADFACE;
62 ret = my_u8_mbtouc (&uc, input, 3);
63 ASSERT (ret == 3);
64 ASSERT (uc == 0x20AC);
67 /* Test 4-byte character input. */
69 static const uint8_t input[] = { 0xF4, 0x8F, 0xBF, 0xBD };
70 uc = 0xBADFACE;
71 ret = my_u8_mbtouc (&uc, input, 4);
72 ASSERT (ret == 4);
73 ASSERT (uc == 0x10FFFD);
76 /* Test incomplete/invalid 1-byte input. */
78 static const uint8_t input[] = { 0xC1 };
79 uc = 0xBADFACE;
80 ret = my_u8_mbtouc (&uc, input, 1);
81 ASSERT (ret == 1);
82 ASSERT (uc == 0xFFFD);
85 static const uint8_t input[] = { 0xC3 };
86 uc = 0xBADFACE;
87 ret = my_u8_mbtouc (&uc, input, 1);
88 ASSERT (ret == 1);
89 ASSERT (uc == 0xFFFD);
92 static const uint8_t input[] = { 0xE2 };
93 uc = 0xBADFACE;
94 ret = my_u8_mbtouc (&uc, input, 1);
95 ASSERT (ret == 1);
96 ASSERT (uc == 0xFFFD);
99 static const uint8_t input[] = { 0xF4 };
100 uc = 0xBADFACE;
101 ret = my_u8_mbtouc (&uc, input, 1);
102 ASSERT (ret == 1);
103 ASSERT (uc == 0xFFFD);
106 static const uint8_t input[] = { 0xFE };
107 uc = 0xBADFACE;
108 ret = my_u8_mbtouc (&uc, input, 1);
109 ASSERT (ret == 1);
110 ASSERT (uc == 0xFFFD);
113 /* Test incomplete/invalid 2-byte input. */
115 static const uint8_t input[] = { 0xE0, 0x9F };
116 uc = 0xBADFACE;
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 };
123 uc = 0xBADFACE;
124 ret = my_u8_mbtouc (&uc, input, 2);
125 ASSERT (ret == 2);
126 ASSERT (uc == 0xFFFD);
129 static const uint8_t input[] = { 0xE2, 0xD0 };
130 uc = 0xBADFACE;
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 };
137 uc = 0xBADFACE;
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 };
144 uc = 0xBADFACE;
145 ret = my_u8_mbtouc (&uc, input, 2);
146 ASSERT (ret == 2);
147 ASSERT (uc == 0xFFFD);
150 static const uint8_t input[] = { 0xF3, 0xD0 };
151 uc = 0xBADFACE;
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 };
160 uc = 0xBADFACE;
161 ret = my_u8_mbtouc (&uc, input, 3);
162 ASSERT (ret == 3);
163 ASSERT (uc == 0xFFFD);
166 static const uint8_t input[] = { 0xF3, 0xD0, 0xBF };
167 uc = 0xBADFACE;
168 ret = my_u8_mbtouc (&uc, input, 3);
169 ASSERT (ret == 1);
170 ASSERT (uc == 0xFFFD);
173 static const uint8_t input[] = { 0xF3, 0x8F, 0xD0 };
174 uc = 0xBADFACE;
175 ret = my_u8_mbtouc (&uc, input, 3);
176 ASSERT (ret == 2);
177 ASSERT (uc == 0xFFFD);