Debian Codegraph @

ext/safestringlib/unittests/test_strremovews_s.c

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