Debian Codegraph @

ext/safestringlib/unittests/test_strspn_s.c

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