This source file includes following definitions.
- test_strchr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 static void
21 test_strchr (void)
22 {
23 size_t size = 0x100000;
24 size_t length;
25 size_t i;
26 UNIT *input;
27 uint32_t *input32 = (uint32_t *) malloc ((size + 1) * sizeof (uint32_t));
28 ASSERT (input32);
29
30 input32[0] = 'a';
31 input32[1] = 'b';
32 u32_set (input32 + 2, 'c', 1024);
33 for (i = 1026; i < size - 2; i += 63)
34 {
35 size_t last = i + 63 < size - 2 ? i + 63 : size - 2;
36 ucs4_t uc = 'd' | (i - 1026);
37 if (uc >= 0xd800 && uc <= 0xdfff)
38 uc |= 0x100000;
39 u32_set (input32 + i, uc, last - i);
40 }
41 input32[size - 2] = 'e';
42 input32[size - 1] = 'a';
43 input32[size] = 0;
44
45 input = U32_TO_U (input32, size + 1, NULL, &length);
46 ASSERT (input);
47
48
49 ASSERT (U_STRCHR (input, 'a') == input);
50 ASSERT (U_STRCHR (input, 'b') == input + 1);
51 ASSERT (U_STRCHR (input, 'c') == input + 2);
52
53 {
54 UNIT *exp = input + 1026;
55 UNIT *prev = input + 2;
56
57 for (i = 1026; i < size - 2; i += 63)
58 {
59 UNIT c[6];
60 size_t n;
61 ucs4_t uc = 'd' | (i - 1026);
62 if (uc >= 0xd800 && uc <= 0xdfff)
63 uc |= 0x100000;
64 n = U_UCTOMB (c, uc, 6);
65 ASSERT (exp < input + length - 2);
66 ASSERT (U_STRCHR (prev, uc) == exp);
67 ASSERT (memcmp (exp, c, n * sizeof (UNIT)) == 0);
68 prev = exp;
69 exp += n * 63;
70 }
71 }
72
73 ASSERT (U_STRCHR (input + 1, 'a') == input + length - 2);
74 ASSERT (U_STRCHR (input + 1, 'e') == input + length - 3);
75
76 ASSERT (U_STRCHR (input, 'f') == NULL);
77 ASSERT (U_STRCHR (input, '\0') == input + length - 1);
78
79
80
81 {
82 size_t repeat = 10000;
83 for (; repeat > 0; repeat--)
84 {
85 ASSERT (U_STRCHR (input, 'c') == input + 2);
86 }
87 }
88
89
90 {
91 int i, j;
92 for (i = 0; i < 32; i++)
93 {
94 for (j = 0; j < 127; j++)
95 input[i + j] = j + 1;
96 input[i + 128] = 0;
97 for (j = 0; j < 127; j++)
98 {
99 ASSERT (U_STRCHR (input + i, j + 1) == input + i + j);
100 }
101 }
102 }
103
104
105 {
106 char *page_boundary = (char *) zerosize_ptr ();
107 size_t n;
108
109 if (page_boundary != NULL)
110 {
111 for (n = 2; n <= 500 / sizeof (UNIT); n++)
112 {
113 UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT));
114 U_SET (mem, 'X', n - 2);
115 mem[n - 2] = 0;
116 ASSERT (U_STRCHR (mem, 'U') == NULL);
117 mem[n - 2] = 'X';
118 mem[n - 1] = 0;
119 ASSERT (U_STRCHR (mem, 'U') == NULL);
120 }
121 }
122 }
123
124 #if 0
125
126
127
128
129
130
131
132 {
133 char *page_boundary = (char *) zerosize_ptr ();
134 size_t n;
135
136 if (page_boundary != NULL)
137 {
138 for (n = 2; n <= 500 / sizeof (UNIT); n++)
139 {
140 UNIT *mem = (UNIT *) (page_boundary - n * sizeof (UNIT));
141 U_SET (mem, 'X', n - 1);
142 mem[n - 1] = 0;
143 ASSERT (U_STRCHR (mem, 'U') == NULL);
144
145 {
146 size_t i;
147
148 for (i = 0; i < n; i++)
149 {
150 mem[i] = 'U';
151 ASSERT (U_STRCHR (mem, 'U') == mem + i);
152 mem[i] = 'X';
153 }
154 }
155 }
156 }
157 }
158 #endif
159
160 free (input);
161 if (sizeof (UNIT) != sizeof (uint32_t))
162 free (input32);
163 }