1 /* Test of uN_strtok() functions.
2 Copyright (C) 2015-2016 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/>. */
21 UNIT input[] = { 'f', 'o', 'o', 0 };
22 const UNIT delim[] = { 0 };
24 const UNIT *result = U_STRTOK (input, delim, &state);
25 ASSERT (result == input);
30 { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', '\t',
31 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0
33 const UNIT delim[] = { ' ', '\t', 0 };
36 result = U_STRTOK (input, delim, &state);
37 ASSERT (result == input);
38 result = U_STRTOK (NULL, delim, &state);
39 ASSERT (result == input + 4);
40 result = U_STRTOK (NULL, delim, &state);
41 ASSERT (result == input + 12);
42 result = U_STRTOK (NULL, delim, &state);
43 ASSERT (result == NULL);
46 /* Check for multibyte delimiters. */
49 { 'A', 'B', 'C', 0x3000, 'A', 'B', 'C', 'D', 'A', 'B', 0x3000, 0x3001,
50 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0
52 ucs4_t u_delim[] = { 0x3000, 0x3001, 0 };
53 size_t input_len = 6 * SIZEOF (u_input);
54 UNIT *input = (UNIT *) malloc (input_len);
55 size_t delim_len = 6 * SIZEOF (u_delim);
56 UNIT *delim = (UNIT *) malloc (delim_len);
59 UNIT *ptr, *first_ptr, *second_ptr;
61 for (i = 0, ptr = input; i < SIZEOF (u_input) && u_input[i] != 0; i++)
63 int ret = U_UCTOMB (ptr, u_input[i], input_len - (ptr - input));
71 for (i = 0, ptr = delim; i < SIZEOF (u_delim) && u_delim[i] != 0; i++)
73 int ret = U_UCTOMB (ptr, u_delim[i], delim_len - (ptr - delim));
77 result = U_STRTOK (input, delim, &state);
78 ASSERT (result == input);
79 result = U_STRTOK (NULL, delim, &state);
80 ASSERT (result == first_ptr);
81 result = U_STRTOK (NULL, delim, &state);
82 ASSERT (result == second_ptr);
83 result = U_STRTOK (NULL, delim, &state);
84 ASSERT (result == NULL);