1 /* Test of u16_prev() 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. */
26 check (const uint16_t *input, size_t input_length, ucs4_t *puc)
30 /* Test recognition when at the beginning of the string. */
31 if (u16_prev (&uc, input + input_length, input) != input)
34 /* Test recognition when preceded by a 1-unit character. */
43 for (i = 0; i < input_length; i++)
46 if (u16_prev (&uc1, ptr + input_length, buf) != ptr)
52 /* Test recognition when preceded by a 2-unit character. */
62 for (i = 0; i < input_length; i++)
65 if (u16_prev (&uc1, ptr + input_length, buf) != ptr)
76 check_invalid (const uint16_t *input, size_t input_length)
80 /* Test recognition when at the beginning of the string. */
82 if (u16_prev (&uc, input + input_length, input) != NULL)
87 #if CONFIG_UNICODE_SAFETY
88 /* Test recognition when preceded by a 1-unit character. */
96 for (i = 0; i < input_length; i++)
100 if (u16_prev (&uc, ptr + input_length, buf) != NULL)
106 /* Test recognition when preceded by a 2-unit character. */
115 for (i = 0; i < input_length; i++)
119 if (u16_prev (&uc, ptr + input_length, buf) != NULL)
134 /* Test ISO 646 unit input. */
139 for (c = 0; c < 0x80; c++)
143 ASSERT (check (buf, 1, &uc) == 0);
148 /* Test BMP unit input. */
150 static const uint16_t input[] = { 0x20AC };
152 ASSERT (check (input, SIZEOF (input), &uc) == 0);
153 ASSERT (uc == 0x20AC);
156 /* Test 2-units character input. */
158 static const uint16_t input[] = { 0xD835, 0xDD1F };
160 ASSERT (check (input, SIZEOF (input), &uc) == 0);
161 ASSERT (uc == 0x1D51F);
164 /* Test incomplete/invalid 1-unit input. */
166 static const uint16_t input[] = { 0xD835 };
167 ASSERT (check_invalid (input, SIZEOF (input)) == 0);
170 static const uint16_t input[] = { 0xDD1F };
171 ASSERT (check_invalid (input, SIZEOF (input)) == 0);