Debian Codegraph @

ext/safestringlib/unittests/test_strljustify_s.c

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