Debian Codegraph @

ext/safestringlib/unittests/test_strfirstsame_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strfirstsame_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
15 int test_strfirstsame_s()
16 {
17 errno_t rc;
18 rsize_t ind;
19
20 char str1[LEN];
21 char str2[LEN];
22
23 /*--------------------------------------------------*/
24
25 rc = strfirstsame_s(NULL, LEN, str2, &ind);
26 if (rc != ESNULLP) {
27 printf("%s %u Error rc=%d \n",
28 __FUNCTION__, __LINE__, rc);
29 }
30
31 if (ind != 0) {
32 printf("%s %u Error ind=%zu rc=%d \n",
33 __FUNCTION__, __LINE__, ind, rc);
34 }
35
36 /*--------------------------------------------------*/
37
38 rc = strfirstsame_s(str1, LEN, NULL, &ind);
39 if (rc != ESNULLP) {
40 printf("%s %u Error rc=%d \n",
41 __FUNCTION__, __LINE__, rc);
42 }
43
44 if (ind != 0) {
45 printf("%s %u Error ind=%zu rc=%d \n",
46 __FUNCTION__, __LINE__, ind, rc);
47 }
48
49 /*--------------------------------------------------*/
50
51 rc = strfirstsame_s(str1, LEN, str2, NULL);
52 if (rc != ESNULLP) {
53 printf("%s %u Error rc=%d \n",
54 __FUNCTION__, __LINE__, rc);
55 }
56
57 /*--------------------------------------------------*/
58
59 rc = strfirstsame_s(str1, 0, str2, &ind);
60 if (rc != ESZEROL) {
61 printf("%s %u Error rc=%d \n",
62 __FUNCTION__, __LINE__, rc);
63 }
64
65 if (ind != 0) {
66 printf("%s %u Error ind=%zu rc=%d \n",
67 __FUNCTION__, __LINE__, ind, rc);
68 }
69
70 /*--------------------------------------------------*/
71
72 rc = strfirstsame_s(str1, RSIZE_MAX_STR+1, str2, &ind);
73 if (rc != ESLEMAX) {
74 printf("%s %u Error rc=%d \n",
75 __FUNCTION__, __LINE__, rc);
76 }
77
78 if (ind != 0) {
79 printf("%s %u Error ind=%zu rc=%d \n",
80 __FUNCTION__, __LINE__, ind, rc);
81 }
82
83 /*--------------------------------------------------*/
84
85 str1[0] = '\0';
86 str2[0] = '\0';
87
88 rc = strfirstsame_s(str1, LEN, str2, &ind);
89 if (rc != ESNOTFND) {
90 printf("%s %u Error rc=%d \n",
91 __FUNCTION__, __LINE__, rc);
92 }
93
94 if (ind != 0) {
95 printf("%s %u Error ind=%zu rc=%d \n",
96 __FUNCTION__, __LINE__, ind, rc);
97 }
98
99 /*--------------------------------------------------*/
100
101 strcpy (str1, "kEEP it simple");
102 strcpy (str2, "keep it simple");
103
104 rc = strfirstsame_s(str1, LEN, str2, &ind);
105 if (rc != EOK) {
106 printf("%s %u Error rc=%d \n",
107 __FUNCTION__, __LINE__, rc);
108 }
109
110 if (ind != 0) {
111 printf("%s %u Error ind=%zu rc=%d \n",
112 __FUNCTION__, __LINE__, ind, rc);
113 }
114
115 /*--------------------------------------------------*/
116
117 strcpy (str1, "Keep it simple");
118 strcpy (str2, "keep it simple");
119
120 rc = strfirstsame_s(str1, LEN, str2, &ind);
121 if (rc != EOK) {
122 printf("%s %u Error rc=%d \n",
123 __FUNCTION__, __LINE__, rc);
124 }
125
126 if (ind != 1) {
127 printf("%s %u Error ind=%zu rc=%d \n",
128 __FUNCTION__, __LINE__, ind, rc);
129 }
130
131 /*--------------------------------------------------*/
132
133 strcpy (str1, "KEEP it simple");
134 strcpy (str2, "keep it simple");
135
136 rc = strfirstsame_s(str1, LEN, str2, &ind);
137 if (rc != EOK) {
138 printf("%s %u Error rc=%d \n",
139 __FUNCTION__, __LINE__, rc);
140 }
141
142 if (ind != 4) {
143 printf("%s %u Error ind=%zu rc=%d \n",
144 __FUNCTION__, __LINE__, ind, rc);
145 }
146
147 /*--------------------------------------------------*/
148
149 strcpy (str1, "keep it simple");
150 strcpy (str2, "KEEP_IT_SIMPLe");
151
152 rc = strfirstsame_s(str1, 13, str2, &ind);
153 if (rc != ESNOTFND) {
154 printf("%s %u Error rc=%d \n",
155 __FUNCTION__, __LINE__, rc);
156 }
157
158 if (ind != 0) {
159 printf("%s %u Error ind=%zu rc=%d \n",
160 __FUNCTION__, __LINE__, ind, rc);
161 }
162
163 /*--------------------------------------------------*/
164
165 strcpy (str1, "keep it simple");
166 strcpy (str2, "KEEP_IT_SIMPLe");
167
168 rc = strfirstsame_s(str1, 14, str2, &ind);
169 if (rc != EOK) {
170 printf("%s %u Error rc=%d \n",
171 __FUNCTION__, __LINE__, rc);
172 }
173
174 if (ind != 13) {
175 printf("%s %u Error ind=%zu rc=%d \n",
176 __FUNCTION__, __LINE__, ind, rc);
177 }
178
179 /*--------------------------------------------------*/
180
181 strcpy (str1, "keep it simple");
182
183 /* same string for src and dest */
184 rc = strfirstsame_s(str1, LEN, str1, &ind);
185 if (rc != EOK) {
186 printf("%s %u Error ind=%zu rc=%d \n",
187 __FUNCTION__, __LINE__, ind, rc);
188 }
189
190 if (ind != 0) {
191 printf("%s %u Error ind=%zu rc=%d \n",
192 __FUNCTION__, __LINE__, ind, rc);
193 }
194
195 /*--------------------------------------------------*/
196
197 strcpy (str1, "KEEP it simple");
198 strcpy (str2, "keep it simple");
199
200 rc = strfirstsame_s(str1, 1, str2, &ind);
201 if (rc != ESNOTFND) {
202 printf("%s %u Error ind=%zu rc=%d \n",
203 __FUNCTION__, __LINE__, ind, rc);
204 }
205
206 if (ind != 0) {
207 printf("%s %u Error ind=%zu rc=%d \n",
208 __FUNCTION__, __LINE__, ind, rc);
209 }
210
211 /*--------------------------------------------------*/
212
213 strcpy (str1, "keep it simple");
214 strcpy (str2, "KEEP_IT_SIMPLE");
215
216 rc = strfirstsame_s(str1, 5, str2, &ind);
217 if (rc != ESNOTFND) {
218 printf("%s %u Error ind=%zu rc=%d \n",
219 __FUNCTION__, __LINE__, ind, rc);
220 }
221
222 if (ind != 0) {
223 printf("%s %u Error ind=%zu rc=%d \n",
224 __FUNCTION__, __LINE__, ind, rc);
225 }
226
227 /*--------------------------------------------------*/
228
229 strcpy (str1, "keep it simple");
230 strcpy (str2, "KEEP_IT_SIMPLE");
231
232 rc = strfirstsame_s(str1, LEN, str2, &ind);
233 if (rc != ESNOTFND) {
234 printf("%s %u Error ind=%zu rc=%d \n",
235 __FUNCTION__, __LINE__, ind, rc);
236 }
237
238 if (ind != 0) {
239 printf("%s %u Error ind=%zu rc=%d \n",
240 __FUNCTION__, __LINE__, ind, rc);
241 }
242
243 /*--------------------------------------------------*/
244
245 return (0);
246 }