This source file includes following definitions.
- test_u_strtok
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 static void
18 test_u_strtok (void)
19 {
20 {
21 UNIT input[] = { 'f', 'o', 'o', 0 };
22 const UNIT delim[] = { 0 };
23 UNIT *state;
24 const UNIT *result = U_STRTOK (input, delim, &state);
25 ASSERT (result == input);
26 }
27
28 {
29 UNIT 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
32 };
33 const UNIT delim[] = { ' ', '\t', 0 };
34 UNIT *state;
35 const UNIT *result;
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);
44 }
45
46
47 {
48 ucs4_t u_input[] =
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
51 };
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);
57 UNIT *state;
58 const UNIT *result;
59 UNIT *ptr, *first_ptr, *second_ptr;
60 size_t i;
61 for (i = 0, ptr = input; i < SIZEOF (u_input) && u_input[i] != 0; i++)
62 {
63 int ret = U_UCTOMB (ptr, u_input[i], input_len - (ptr - input));
64 if (i == 4)
65 first_ptr = ptr;
66 if (i == 12)
67 second_ptr = ptr;
68 ptr += ret;
69 }
70 *ptr = 0;
71 for (i = 0, ptr = delim; i < SIZEOF (u_delim) && u_delim[i] != 0; i++)
72 {
73 int ret = U_UCTOMB (ptr, u_delim[i], delim_len - (ptr - delim));
74 ptr += ret;
75 }
76 *ptr = 0;
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);
85 free (input);
86 free (delim);
87 }
88 }