1 /* Test of u8_mbtoucr() function.
2 Copyright (C) 2010-2014 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. */
31 /* Test NUL unit input. */
33 static const uint8_t input[] = "";
35 ret = u8_mbtoucr (&uc, input, 1);
40 /* Test ISO 646 unit input. */
45 for (c = 0; c < 0x80; c++)
49 ret = u8_mbtoucr (&uc, buf, 1);
55 /* Test 2-byte character input. */
57 static const uint8_t input[] = { 0xC3, 0x97 };
59 ret = u8_mbtoucr (&uc, input, 2);
61 ASSERT (uc == 0x00D7);
64 /* Test 3-byte character input. */
66 static const uint8_t input[] = { 0xE2, 0x82, 0xAC };
68 ret = u8_mbtoucr (&uc, input, 3);
70 ASSERT (uc == 0x20AC);
73 /* Test 4-byte character input. */
75 static const uint8_t input[] = { 0xF4, 0x8F, 0xBF, 0xBD };
77 ret = u8_mbtoucr (&uc, input, 4);
79 ASSERT (uc == 0x10FFFD);
82 /* Test incomplete/invalid 1-byte input. */
84 static const uint8_t input[] = { 0xC1 };
86 ret = u8_mbtoucr (&uc, input, 1);
88 ASSERT (uc == 0xFFFD);
91 static const uint8_t input[] = { 0xC3 };
93 ret = u8_mbtoucr (&uc, input, 1);
95 ASSERT (uc == 0xFFFD);
98 static const uint8_t input[] = { 0xE2 };
100 ret = u8_mbtoucr (&uc, input, 1);
102 ASSERT (uc == 0xFFFD);
105 static const uint8_t input[] = { 0xF4 };
107 ret = u8_mbtoucr (&uc, input, 1);
109 ASSERT (uc == 0xFFFD);
112 static const uint8_t input[] = { 0xFE };
114 ret = u8_mbtoucr (&uc, input, 1);
116 ASSERT (uc == 0xFFFD);
119 /* Test incomplete/invalid 2-byte input. */
121 static const uint8_t input[] = { 0xE0, 0x9F };
123 ret = u8_mbtoucr (&uc, input, 2);
125 ASSERT (uc == 0xFFFD);
128 static const uint8_t input[] = { 0xE2, 0x82 };
130 ret = u8_mbtoucr (&uc, input, 2);
132 ASSERT (uc == 0xFFFD);
135 static const uint8_t input[] = { 0xE2, 0xD0 };
137 ret = u8_mbtoucr (&uc, input, 2);
139 ASSERT (uc == 0xFFFD);
142 static const uint8_t input[] = { 0xF0, 0x8F };
144 ret = u8_mbtoucr (&uc, input, 2);
146 ASSERT (uc == 0xFFFD);
149 static const uint8_t input[] = { 0xF3, 0x8F };
151 ret = u8_mbtoucr (&uc, input, 2);
153 ASSERT (uc == 0xFFFD);
156 static const uint8_t input[] = { 0xF3, 0xD0 };
158 ret = u8_mbtoucr (&uc, input, 2);
160 ASSERT (uc == 0xFFFD);
163 /* Test incomplete/invalid 3-byte input. */
165 static const uint8_t input[] = { 0xF3, 0x8F, 0xBF };
167 ret = u8_mbtoucr (&uc, input, 3);
169 ASSERT (uc == 0xFFFD);
172 static const uint8_t input[] = { 0xF3, 0xD0, 0xBF };
174 ret = u8_mbtoucr (&uc, input, 3);
176 ASSERT (uc == 0xFFFD);
179 static const uint8_t input[] = { 0xF3, 0x8F, 0xD0 };
181 ret = u8_mbtoucr (&uc, input, 3);
183 ASSERT (uc == 0xFFFD);