Debian Codegraph @

ext/safestringlib/unittests/test_strpbrk_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strpbrk_s
3 *
4 *
5 *------------------------------------------------------------------
6 */
7
8 #include "test_private.h"
9 #include "safe_str_lib.h"
10
11 #define LEN ( 128 )
12 #define SHORT_LEN ( 5 )
13
14 static char str1[LEN];
15 static char str2[LEN];
16
17 int test_strpbrk_s (void)
18 {
19 errno_t rc;
20 char *first;
21 char *std_first;
22
23 /*--------------------------------------------------*/
24
25 rc = strpbrk_s(str1, LEN, str2, LEN, NULL);
26 if (rc != ESNULLP) {
27 printf("%s %u Error rc=%d \n",
28 __FUNCTION__, __LINE__, rc);
29 }
30
31 /*--------------------------------------------------*/
32
33 rc = strpbrk_s(NULL, LEN, str2, LEN, &first);
34 if (rc != ESNULLP) {
35 printf("%s %u Error rc=%d \n",
36 __FUNCTION__, __LINE__, rc);
37 }
38
39 if (first) {
40 printf("%s %u Error first=%p rc=%d \n",
41 __FUNCTION__, __LINE__, first, rc);
42 }
43
44 /*--------------------------------------------------*/
45
46 rc = strpbrk_s(str1, LEN, NULL, LEN, &first);
47 if (rc != ESNULLP) {
48 printf("%s %u Error rc=%d \n",
49 __FUNCTION__, __LINE__, rc);
50 }
51
52 if (first) {
53 printf("%s %u Error first=%p rc=%d \n",
54 __FUNCTION__, __LINE__, first, rc);
55 }
56
57 /*--------------------------------------------------*/
58
59 rc = strpbrk_s(str1, LEN, str2, LEN, NULL);
60 if (rc != ESNULLP) {
61 printf("%s %u Error rc=%d \n",
62 __FUNCTION__, __LINE__, rc);
63 }
64
65 /*--------------------------------------------------*/
66
67 rc = strpbrk_s(str1, 0, str2, LEN, &first);
68 if (rc != ESZEROL) {
69 printf("%s %u Error rc=%d \n",
70 __FUNCTION__, __LINE__, rc);
71 }
72
73 if (first) {
74 printf("%s %u Error first=%p rc=%d \n",
75 __FUNCTION__, __LINE__, first, rc);
76 }
77
78 /*--------------------------------------------------*/
79
80 rc = strpbrk_s(str1, RSIZE_MAX_STR+1, str2, LEN, &first);
81 if (rc != ESLEMAX) {
82 printf("%s %u Error rc=%d \n",
83 __FUNCTION__, __LINE__, rc);
84 }
85
86 if (first) {
87 printf("%s %u Error first=%p rc=%d \n",
88 __FUNCTION__, __LINE__, first, rc);
89 }
90
91 /*--------------------------------------------------*/
92
93 rc = strpbrk_s(str1, RSIZE_MAX_STR, str2, RSIZE_MAX_STR+1, &first);
94 if (rc != ESLEMAX) {
95 printf("%s %u Error rc=%d \n",
96 __FUNCTION__, __LINE__, rc);
97 }
98
99 if (first) {
100 printf("%s %u Error first=%p rc=%d \n",
101 __FUNCTION__, __LINE__, first, rc);
102 }
103
104 /*--------------------------------------------------*/
105
106 str1[0] = '\0';
107 str2[0] = '\0';
108
109 /* not to be found */
110 rc = strpbrk_s(str1, LEN, str2, LEN, &first);
111 if (rc != ESNOTFND) {
112 printf("%s %u Error first=%p rc=%d \n",
113 __FUNCTION__, __LINE__, first, rc);
114 }
115
116 if (first) {
117 printf("%s %u Error first=%p rc=%d \n",
118 __FUNCTION__, __LINE__, first, rc);
119 }
120
121 std_first = strpbrk(str1, str2);
122 if (first != std_first) {
123 printf("%s %u first=%p std_first=%p rc=%d \n",
124 __FUNCTION__, __LINE__, first, std_first, rc);
125 }
126
127 /*--------------------------------------------------*/
128
129 strcpy (str1, "keep it simple");
130 strcpy (str2, "1234");
131
132 rc = strpbrk_s(str1, 2, str2, LEN, &first);
133 if (rc != ESNOTFND) {
134 printf("%s %u Error first=%p rc=%d \n",
135 __FUNCTION__, __LINE__, first, rc);
136 }
137
138 std_first = strpbrk(str1, str2);
139 if (first != std_first) {
140 printf("%s %u first=%p std_first=%p rc=%d \n",
141 __FUNCTION__, __LINE__, first, std_first, rc);
142 }
143
144 /*--------------------------------------------------*/
145
146 strcpy (str1, "keep it simple");
147 strcpy (str2, "ke");
148
149 rc = strpbrk_s(str1, 2, str2, LEN, &first);
150 if (rc != EOK) {
151 printf("%s %u Error first=%p rc=%d \n",
152 __FUNCTION__, __LINE__, first, rc);
153 }
154
155 std_first = strpbrk(str1, str2);
156 if (first != std_first) {
157 printf("%s %u first=%p std_first=%p rc=%d \n",
158 __FUNCTION__, __LINE__, first, std_first, rc);
159 }
160
161 /*--------------------------------------------------*/
162
163 strcpy (str1, "keep it simplez");
164 strcpy (str2, "z");
165
166 rc = strpbrk_s(str1, LEN, str2, LEN, &first);
167 if (rc != EOK) {
168 printf("%s %u Error first=%p rc=%d \n",
169 __FUNCTION__, __LINE__, first, rc);
170 }
171
172 std_first = strpbrk(str1, str2);
173 if (first != std_first) {
174 printf("%s %u first=%p std_first=%p rc=%d \n",
175 __FUNCTION__, __LINE__, first, std_first, rc);
176 }
177
178 /*--------------------------------------------------*/
179
180 strcpy (str1, "keep it simple");
181 strcpy (str2, "123456");
182
183 rc = strpbrk_s(str1, LEN, str2, 2, &first);
184 if (rc != ESNOTFND) {
185 printf("%s %u Error rc=%d \n",
186 __FUNCTION__, __LINE__, rc);
187 }
188
189 if (first != 0) {
190 printf("%s %u Error first=%p rc=%d \n",
191 __FUNCTION__, __LINE__, first, rc);
192 }
193
194 /*--------------------------------------------------*/
195
196 strcpy (str1, "keep it simple");
197 strcpy (str2, "");
198
199 rc = strpbrk_s(str1, LEN, str2, 1, &first);
200 if (rc != ESNOTFND) {
201 printf("%s %u Error rc=%d \n",
202 __FUNCTION__, __LINE__, rc);
203 }
204
205 if (first != 0) {
206 printf("%s %u Error first=%p rc=%d \n",
207 __FUNCTION__, __LINE__, first, rc);
208 }
209
210 /*--------------------------------------------------*/
211
212 strcpy (str1, "keep it simple");
213 strcpy (str2, "k");
214
215 rc = strpbrk_s(str1, LEN, str2, 1, &first);
216 if (rc != EOK) {
217 printf("%s %u Error rc=%d \n",
218 __FUNCTION__, __LINE__, rc);
219 }
220
221 std_first = strpbrk(str1, str2);
222 if (first != std_first) {
223 printf("%s %u first=%p std_first=%p rc=%d \n",
224 __FUNCTION__, __LINE__, first, std_first, rc);
225 }
226
227 /*--------------------------------------------------*/
228
229 strcpy (str1, "keep it simple");
230 strcpy (str2, "ke");
231
232 rc = strpbrk_s(str1, LEN, str2, 2, &first);
233 if (rc != EOK) {
234 printf("%s %u Error rc=%d \n",
235 __FUNCTION__, __LINE__, rc);
236 }
237
238 std_first = strpbrk(str1, str2);
239 if (first != std_first) {
240 printf("%s %u first=%p std_first=%p rc=%d \n",
241 __FUNCTION__, __LINE__, first, std_first, rc);
242 }
243
244 /*--------------------------------------------------*/
245
246 strcpy (str1, "keep it simple");
247 strcpy (str2, "hip");
248
249 rc = strpbrk_s(str1, LEN, str2, LEN, &first);
250 if (rc != EOK) {
251 printf("%s %u Error rc=%d \n",
252 __FUNCTION__, __LINE__, rc);
253 }
254
255 std_first = strpbrk(str1, str2);
256 if (first != std_first) {
257 printf("%s %u first=%p std_first=%p rc=%d \n",
258 __FUNCTION__, __LINE__, first, std_first, rc);
259 }
260
261 /*--------------------------------------------------*/
262
263 strcpy (str1, "keep it simply");
264 strcpy (str2, "123y");
265
266 rc = strpbrk_s(str1, LEN, str2, LEN, &first);
267 if (rc != EOK) {
268 printf("%s %u Error rc=%d \n",
269 __FUNCTION__, __LINE__, rc);
270 }
271
272 std_first = strpbrk(str1, str2);
273 if (first != std_first) {
274 printf("%s %u first=%p std_first=%p rc=%d \n",
275 __FUNCTION__, __LINE__, first, std_first, rc);
276 }
277
278 /*--------------------------------------------------*/
279
280 return (0);
281 }