1 /* Test of u8_mblen() function.
2 Copyright (C) 2010-2013 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. */
30 /* Test zero-length input. */
32 static const uint8_t input[] = "";
33 ret = u8_mblen (input, 0);
37 /* Test NUL unit input. */
39 static const uint8_t input[] = "";
40 ret = u8_mblen (input, 1);
44 /* Test ISO 646 unit input. */
49 for (c = 1; c < 0x80; c++)
52 ret = u8_mblen (buf, 1);
57 /* Test 2-byte character input. */
59 static const uint8_t input[] = { 0xC3, 0x97 };
60 ret = u8_mblen (input, 2);
64 /* Test 3-byte character input. */
66 static const uint8_t input[] = { 0xE2, 0x82, 0xAC };
67 ret = u8_mblen (input, 3);
71 /* Test 4-byte character input. */
73 static const uint8_t input[] = { 0xF4, 0x8F, 0xBF, 0xBD };
74 ret = u8_mblen (input, 4);
78 /* Test incomplete/invalid 1-byte input. */
80 static const uint8_t input[] = { 0xC1 };
81 ret = u8_mblen (input, 1);
85 static const uint8_t input[] = { 0xC3 };
86 ret = u8_mblen (input, 1);
90 static const uint8_t input[] = { 0xE2 };
91 ret = u8_mblen (input, 1);
95 static const uint8_t input[] = { 0xF4 };
96 ret = u8_mblen (input, 1);
100 static const uint8_t input[] = { 0xFE };
101 ret = u8_mblen (input, 1);
105 /* Test incomplete/invalid 2-byte input. */
107 static const uint8_t input[] = { 0xE0, 0x9F };
108 ret = u8_mblen (input, 2);
112 static const uint8_t input[] = { 0xE2, 0x82 };
113 ret = u8_mblen (input, 2);
117 static const uint8_t input[] = { 0xE2, 0xD0 };
118 ret = u8_mblen (input, 2);
122 static const uint8_t input[] = { 0xF0, 0x8F };
123 ret = u8_mblen (input, 2);
127 static const uint8_t input[] = { 0xF3, 0x8F };
128 ret = u8_mblen (input, 2);
132 static const uint8_t input[] = { 0xF3, 0xD0 };
133 ret = u8_mblen (input, 2);
137 /* Test incomplete/invalid 3-byte input. */
139 static const uint8_t input[] = { 0xF3, 0x8F, 0xBF };
140 ret = u8_mblen (input, 3);
144 static const uint8_t input[] = { 0xF3, 0xD0, 0xBF };
145 ret = u8_mblen (input, 3);
149 static const uint8_t input[] = { 0xF3, 0x8F, 0xD0 };
150 ret = u8_mblen (input, 3);