Support compiling without -loldnames on native Windows.
[gnulib.git] / tests / unistr / test-u8-strmblen.c
blob1929301bc9d2783babc4c6abe21be2b4abecd917
1 /* Test of u8_strmblen() 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 int ret;
30 /* Test NUL unit input. */
32 static const uint8_t input[] = "";
33 ret = u8_strmblen (input);
34 ASSERT (ret == 0);
37 /* Test ISO 646 unit input. */
39 ucs4_t c;
40 uint8_t buf[2];
42 for (c = 1; c < 0x80; c++)
44 buf[0] = c;
45 buf[1] = 0;
46 ret = u8_strmblen (buf);
47 ASSERT (ret == 1);
51 /* Test 2-byte character input. */
53 static const uint8_t input[] = { 0xC3, 0x97, 0 };
54 ret = u8_strmblen (input);
55 ASSERT (ret == 2);
58 /* Test 3-byte character input. */
60 static const uint8_t input[] = { 0xE2, 0x82, 0xAC, 0 };
61 ret = u8_strmblen (input);
62 ASSERT (ret == 3);
65 /* Test 4-byte character input. */
67 static const uint8_t input[] = { 0xF4, 0x8F, 0xBF, 0xBD, 0 };
68 ret = u8_strmblen (input);
69 ASSERT (ret == 4);
72 /* Test incomplete/invalid 1-byte input. */
74 static const uint8_t input[] = { 0xC1, 0 };
75 ret = u8_strmblen (input);
76 ASSERT (ret == -1);
79 static const uint8_t input[] = { 0xC3, 0 };
80 ret = u8_strmblen (input);
81 ASSERT (ret == -1);
84 static const uint8_t input[] = { 0xE2, 0 };
85 ret = u8_strmblen (input);
86 ASSERT (ret == -1);
89 static const uint8_t input[] = { 0xF4, 0 };
90 ret = u8_strmblen (input);
91 ASSERT (ret == -1);
94 static const uint8_t input[] = { 0xFE, 0 };
95 ret = u8_strmblen (input);
96 ASSERT (ret == -1);
99 /* Test incomplete/invalid 2-byte input. */
101 static const uint8_t input[] = { 0xE0, 0x9F, 0 };
102 ret = u8_strmblen (input);
103 ASSERT (ret == -1);
106 static const uint8_t input[] = { 0xE2, 0x82, 0 };
107 ret = u8_strmblen (input);
108 ASSERT (ret == -1);
111 static const uint8_t input[] = { 0xE2, 0xD0, 0 };
112 ret = u8_strmblen (input);
113 ASSERT (ret == -1);
116 static const uint8_t input[] = { 0xF0, 0x8F, 0 };
117 ret = u8_strmblen (input);
118 ASSERT (ret == -1);
121 static const uint8_t input[] = { 0xF3, 0x8F, 0 };
122 ret = u8_strmblen (input);
123 ASSERT (ret == -1);
126 static const uint8_t input[] = { 0xF3, 0xD0, 0 };
127 ret = u8_strmblen (input);
128 ASSERT (ret == -1);
131 /* Test incomplete/invalid 3-byte input. */
133 static const uint8_t input[] = { 0xF3, 0x8F, 0xBF, 0 };
134 ret = u8_strmblen (input);
135 ASSERT (ret == -1);
138 static const uint8_t input[] = { 0xF3, 0xD0, 0xBF, 0 };
139 ret = u8_strmblen (input);
140 ASSERT (ret == -1);
143 static const uint8_t input[] = { 0xF3, 0x8F, 0xD0, 0 };
144 ret = u8_strmblen (input);
145 ASSERT (ret == -1);
148 return 0;