Debian Codegraph @

ext/safestringlib/unittests/test_strfirstdiff_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strfirstdiff_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_strfirstdiff_s()
16 {
17 errno_t rc;
18 rsize_t ind;
19
20 char str1[LEN];
21 char str2[LEN];
22
23 /*--------------------------------------------------*/
24
25 rc = strfirstdiff_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 = strfirstdiff_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 = strfirstdiff_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 = strfirstdiff_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 = strfirstdiff_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 = strfirstdiff_s(str1, LEN, str2, &ind);
89 if (rc != ESNODIFF) {
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 = strfirstdiff_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 = strfirstdiff_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 = strfirstdiff_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 != 2) {
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
151 rc = strfirstdiff_s(str1, LEN, str1, &ind);
152 if (rc != ESNODIFF) {
153 printf("%s %u Error rc=%d \n",
154 __FUNCTION__, __LINE__, rc);
155 }
156
157 if (ind != 0) {
158 printf("%s %u Error ind=%zu rc=%d \n",
159 __FUNCTION__, __LINE__, ind, rc);
160 }
161
162 /*--------------------------------------------------*/
163
164 strcpy (str1, "keep it simple");
165 strcpy (str2, "keep it simple");
166
167 rc = strfirstdiff_s(str1, 1, str2, &ind);
168 if (rc != ESNODIFF) {
169 printf("%s %u Error rc=%d \n",
170 __FUNCTION__, __LINE__, rc);
171 }
172
173 if (ind != 0) {
174 printf("%s %u Error ind=%zu rc=%d \n",
175 __FUNCTION__, __LINE__, ind, rc);
176 }
177
178 /*--------------------------------------------------*/
179
180 strcpy (str1, "keep it simplE");
181 strcpy (str2, "keep it simple");
182
183 rc = strfirstdiff_s(str1, 13, str2, &ind);
184 if (rc != ESNODIFF) {
185 printf("%s %u Error rc=%d \n",
186 __FUNCTION__, __LINE__, rc);
187 }
188
189 if (ind != 0) {
190 printf("%s %u Error ind=%zu rc=%d \n",
191 __FUNCTION__, __LINE__, ind, rc);
192 }
193
194 /*--------------------------------------------------*/
195
196 strcpy (str1, "keep it simplE");
197 strcpy (str2, "keep it simple");
198
199 rc = strfirstdiff_s(str1, 14, str2, &ind);
200 if (rc != EOK) {
201 printf("%s %u Error rc=%d \n",
202 __FUNCTION__, __LINE__, rc);
203 }
204
205 if (ind != 13) {
206 printf("%s %u Error ind=%zu rc=%d \n",
207 __FUNCTION__, __LINE__, ind, rc);
208 }
209
210 /*--------------------------------------------------*/
211
212 strcpy (str1, "keep it simplE");
213 strcpy (str2, "keep it simple");
214
215 rc = strfirstdiff_s(str1, 55, str2, &ind);
216 if (rc != EOK) {
217 printf("%s %u Error rc=%d \n",
218 __FUNCTION__, __LINE__, rc);
219 }
220
221 if (ind != 13) {
222 printf("%s %u Error ind=%zu rc=%d \n",
223 __FUNCTION__, __LINE__, ind, rc);
224 }
225
226 /*--------------------------------------------------*/
227
228 return (0);
229 }