Debian Codegraph @

ext/safestringlib/unittests/test_strlastdiff_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strlastdiff_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_strlastdiff_s()
16 {
17 errno_t rc;
18 rsize_t ind;
19
20 char str1[LEN];
21 char str2[LEN];
22
23
24 /*--------------------------------------------------*/
25
26 rc = strlastdiff_s(NULL, LEN, str2, &ind);
27 if (rc != ESNULLP) {
28 printf("%s %u Error rc=%d \n",
29 __FUNCTION__, __LINE__, rc);
30 }
31
32 if (ind != 0) {
33 printf("%s %u Error ind=%zu rc=%d \n",
34 __FUNCTION__, __LINE__, ind, rc);
35 }
36
37 /*--------------------------------------------------*/
38
39 rc = strlastdiff_s(str1, LEN, NULL, &ind);
40 if (rc != ESNULLP) {
41 printf("%s %u Error rc=%d \n",
42 __FUNCTION__, __LINE__, rc);
43 }
44
45 if (ind != 0) {
46 printf("%s %u Error ind=%zu rc=%d \n",
47 __FUNCTION__, __LINE__, ind, rc);
48 }
49
50 /*--------------------------------------------------*/
51
52 rc = strlastdiff_s(str1, LEN, str2, NULL);
53 if (rc != ESNULLP) {
54 printf("%s %u Error rc=%d \n",
55 __FUNCTION__, __LINE__, rc);
56 }
57
58 /*--------------------------------------------------*/
59
60 rc = strlastdiff_s(str1, 0, str2, &ind);
61 if (rc != ESZEROL) {
62 printf("%s %u Error rc=%d \n",
63 __FUNCTION__, __LINE__, rc);
64 }
65
66 if (ind != 0) {
67 printf("%s %u Error ind=%zu rc=%d \n",
68 __FUNCTION__, __LINE__, ind, rc);
69 }
70
71 /*--------------------------------------------------*/
72
73 rc = strlastdiff_s(str1, RSIZE_MAX_STR+1, str2, &ind);
74 if (rc != ESLEMAX) {
75 printf("%s %u Error rc=%d \n",
76 __FUNCTION__, __LINE__, rc);
77 }
78
79 if (ind != 0) {
80 printf("%s %u Error ind=%zu rc=%d \n",
81 __FUNCTION__, __LINE__, ind, rc);
82 }
83
84 /*--------------------------------------------------*/
85
86 str1[0] = '\0';
87 str2[0] = '\0';
88
89 rc = strlastdiff_s(str1, LEN, str2, &ind);
90 if (rc != ESNODIFF) {
91 printf("%s %u Error rc=%d \n",
92 __FUNCTION__, __LINE__, rc);
93 }
94
95 if (ind != 0) {
96 printf("%s %u Error ind=%zu rc=%d \n",
97 __FUNCTION__, __LINE__, ind, rc);
98 }
99
100 /*--------------------------------------------------*/
101
102 strcpy (str1, "Keep iT simple");
103 strcpy (str2, "keep it simple");
104
105 rc = strlastdiff_s(str1, LEN, str2, &ind);
106 if (rc != EOK) {
107 printf("%s %u Error rc=%d \n",
108 __FUNCTION__, __LINE__, rc);
109 }
110
111 if (ind != 6) {
112 printf("%s %u Error ind=%zu rc=%d \n",
113 __FUNCTION__, __LINE__, ind, rc);
114 }
115
116 /*--------------------------------------------------*/
117
118 strcpy (str1, "kEep it simple");
119 strcpy (str2, "keep it simple");
120
121 rc = strlastdiff_s(str1, LEN, str2, &ind);
122 if (rc != EOK) {
123 printf("%s %u Error rc=%d \n",
124 __FUNCTION__, __LINE__, rc);
125 }
126
127 if (ind != 1) {
128 printf("%s %u Error ind=%zu rc=%d \n",
129 __FUNCTION__, __LINE__, ind, rc);
130 }
131
132 /*--------------------------------------------------*/
133
134 strcpy (str1, "keep it siMple");
135 strcpy (str2, "keEp it Simple");
136
137 rc = strlastdiff_s(str1, LEN, str2, &ind);
138 if (rc != EOK) {
139 printf("%s %u Error rc=%d \n",
140 __FUNCTION__, __LINE__, rc);
141 }
142
143 if (ind != 10) {
144 printf("%s %u Error ind=%zu rc=%d \n",
145 __FUNCTION__, __LINE__, ind, rc);
146 }
147
148 /*--------------------------------------------------*/
149
150 strcpy (str1, "keep it simple");
151
152 rc = strlastdiff_s(str1, LEN, str1, &ind);
153 if (rc != ESNODIFF) {
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 = strlastdiff_s(str1, 1, str2, &ind);
169 if (rc != ESNODIFF) {
170 printf("%s %u Error rc=%d \n",
171 __FUNCTION__, __LINE__, rc);
172 }
173
174 if (ind != 0) {
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 strcpy (str2, "keep it simplE");
183
184 rc = strlastdiff_s(str1, 25, str2, &ind);
185 if (rc != EOK) {
186 printf("%s %u Error rc=%d \n",
187 __FUNCTION__, __LINE__, rc);
188 }
189
190 if (ind != 13) {
191 printf("%s %u Error ind=%zu rc=%d \n",
192 __FUNCTION__, __LINE__, ind, rc);
193 }
194
195 /*--------------------------------------------------*/
196
197 return (0);
198 }