Debian Codegraph @

ext/safestringlib/unittests/test_strcmpfld_s.c

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