robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 20 | /* 01/02/2003 Port to LTP avenkat@us.ibm.com */ |
| 21 | /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ |
| 22 | |
| 23 | /* |
| 24 | * NAME |
| 25 | * string01.c - check string functions. |
| 26 | * |
| 27 | * CALLS |
| 28 | * strchr, strrchr, strcat, strcmp, strcpy, strlen, |
| 29 | * strncat, strncmp, strncpy |
| 30 | * |
| 31 | * ALGORITHM |
| 32 | * Test functionality of the string functions: |
| 33 | * (strchr, strrchr, strcat, strcmp, strcpy, strlen, |
| 34 | * strncat, strncmp, strncpy ) |
| 35 | * |
| 36 | */ |
| 37 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 38 | #include <stdio.h> |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 39 | #include <sys/types.h> |
| 40 | #include <string.h> |
| 41 | |
| 42 | /***** LTP Port *****/ |
| 43 | #include <errno.h> |
| 44 | #include <stdlib.h> |
| 45 | #include "test.h" |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 46 | |
| 47 | #define FAILED 0 |
| 48 | #define PASSED 1 |
| 49 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 50 | char *TCID = "string01"; |
| 51 | |
| 52 | int local_flag = PASSED; |
| 53 | int block_number; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 54 | FILE *temp; |
| 55 | int TST_TOTAL = 1; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 56 | /***** ** ** *****/ |
| 57 | |
| 58 | #define LONGSTR (96*1024-1) |
| 59 | /* #define LONGSTR (1024-1) */ |
| 60 | |
| 61 | /* |
| 62 | * Miscellaneous data strings for testing. |
| 63 | */ |
| 64 | |
| 65 | char tiat[] = "This is a test of the string functions. "; |
| 66 | char yat[] = "This is yet another test."; |
| 67 | char tiatyat[] = |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 68 | "This is a test of the string functions. This is yet another test."; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 69 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 70 | char longstr[LONGSTR + 1]; /* a very long string */ |
| 71 | char dst0[LONGSTR + 1]; /* place holders for various tests */ |
| 72 | char dst1[LONGSTR + 1]; |
| 73 | char dst2[LONGSTR + 1]; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Data structures for testing. |
| 77 | */ |
| 78 | |
| 79 | /* Strlen (strlen( s ) == e_res) */ |
| 80 | struct t_strlen { |
| 81 | char *s; |
| 82 | int e_res; |
| 83 | } t_len[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 84 | { |
| 85 | "", 0}, { |
| 86 | "12345", 5}, { |
| 87 | tiat, 41}, { |
| 88 | longstr, LONGSTR}, { |
| 89 | NULL, 0} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* Index (index( s, c ) == e_res) */ |
| 93 | struct t_index { |
| 94 | char *s; |
| 95 | char c; |
| 96 | char *e_res; |
| 97 | } t_index[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | { |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 99 | "", 'z', NULL}, { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | tiat, 'a', tiat + 8}, { |
| 101 | tiat, 's', tiat + 3}, { |
| 102 | tiat, 'o', tiat + 15}, { |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 103 | tiat, 'z', NULL}, { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | NULL, 0, NULL} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* Rindex (rindex( s, c ) == e_res) */ |
| 108 | struct t_rindex { |
| 109 | char *s; |
| 110 | char c; |
| 111 | char *e_res; |
| 112 | } t_rindex[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | { |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 114 | "", 'z', NULL}, { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | tiat, 'a', tiat + 8}, { |
| 116 | tiat, 's', tiat + 37}, { |
| 117 | tiat, 'o', tiat + 35}, { |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 118 | tiat, 'z', NULL}, { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | NULL, 0, NULL} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 122 | /* Strcmp (strcmp( s1, s2 ) == e_res) */ |
| 123 | struct t_strcmp { |
| 124 | char *s1; |
| 125 | char *s2; |
| 126 | int e_res; |
| 127 | } t_cmp[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 128 | { |
| 129 | "", "", 0}, { |
| 130 | "", tiat, -((int)'T')}, { |
| 131 | tiat, "", 'T'}, { |
| 132 | tiat, tiat, 0}, { |
| 133 | yat, tiat, 'y' - 'a'}, { |
| 134 | NULL, NULL, 0} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 137 | /* Strcat (strcmp( strcat(s1, s2), s1s2 ) == e_res) */ |
| 138 | /* ASSUMES strcmp is working -- it is tested prior to strcat */ |
| 139 | struct t_strcat { |
| 140 | char *s1; |
| 141 | char *s2; |
| 142 | char *s1s2; |
| 143 | int e_res; |
| 144 | } t_cat[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | { |
| 146 | dst0, "", "", 0}, { |
| 147 | dst0, tiat, tiat, 0}, { |
| 148 | dst0, "", tiat, 0}, { |
| 149 | dst0, yat, tiatyat, 0}, { |
| 150 | dst1, longstr, longstr, 0}, { |
| 151 | NULL, NULL, NULL, 0} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | /* Strcpy (strcmp( strcpy(s1, s2), s1s2 ) == e_res) */ |
| 155 | /* ASSUMES strcmp is working -- it is tested prior to strcpy */ |
| 156 | /* No overlapping copies are tested */ |
| 157 | struct t_strcpy { |
| 158 | char *s1; |
| 159 | char *s2; |
| 160 | int e_res; |
| 161 | } t_cpy[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 162 | { |
| 163 | dst0, "", 0}, { |
| 164 | dst0, tiat, 0}, { |
| 165 | dst0, longstr, 0}, { |
| 166 | NULL, NULL, 0} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | /* Strncmp (strncmp( s1, s2 ) == e_res) */ |
| 170 | struct t_strncmp { |
| 171 | char *s1; |
| 172 | char *s2; |
| 173 | int n; |
| 174 | int e_res; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | int a_res; /* Allowable results, some platforms only return 1 or -1 */ |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 176 | } t_ncmp[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | { |
| 178 | "", "", 0, 0, 0}, { |
| 179 | "", "", 80, 0, 0}, { |
| 180 | tiat, "", 0, 0, 0}, { |
| 181 | "", tiat, 80, -((int)'T'), -1}, { |
| 182 | tiat, "", 80, 'T', 1}, { |
| 183 | tiat, tiat, 80, 0, 0}, { |
| 184 | yat, tiat, 80, 'y' - 'a', 1}, { |
| 185 | yat, tiat, 8, 0, 1}, { |
| 186 | yat, tiat, 9, 'y' - 'a', 1}, { |
| 187 | NULL, NULL, 0, 0, 0} |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 188 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | /* Strncat (strcmp( strncat(s1, s2, n), s1ns2 ) == e_res) */ |
| 192 | /* ASSUMES strcmp is working -- it is tested prior to strncat */ |
| 193 | /* dest is guaranteed to be all '\0' s at start of test */ |
| 194 | struct t_strncat { |
| 195 | char *s1; |
| 196 | char *s2; |
| 197 | int n; |
| 198 | char *s1ns2; |
| 199 | int e_res; |
| 200 | } t_ncat[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 201 | /* Regular strcat stuff -- i.e., n is large enough */ |
| 202 | { |
| 203 | dst0, "", LONGSTR, "", 0}, { |
| 204 | dst0, tiat, LONGSTR, tiat, 0}, { |
| 205 | dst0, "", LONGSTR, tiat, 0}, { |
| 206 | dst0, yat, LONGSTR, tiatyat, 0}, { |
| 207 | dst1, longstr, LONGSTR, longstr, 0}, |
| 208 | /* Restricted strcat stuff */ |
| 209 | { |
| 210 | dst2, longstr, 0, "", 0}, { |
| 211 | dst2, longstr, 1, "t", 0}, { |
| 212 | dst2, longstr, LONGSTR - 1, longstr, 0}, { |
| 213 | NULL, NULL, 0, NULL, 0} |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 214 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 217 | /* Strncpy (strcmp( strncpy(s1, s2), s1n ) == e_res) */ |
| 218 | /* ASSUMES strcmp is working -- it is tested prior to strncpy */ |
| 219 | /* No overlapping copies are tested */ |
| 220 | struct t_strncpy { |
| 221 | char *s1; |
| 222 | char *s2; |
| 223 | int n; |
| 224 | char *s1n; |
| 225 | int e_res; |
| 226 | } t_ncpy[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 227 | /* Regular strcpy stuff -- i.e., n is large enough */ |
| 228 | { |
| 229 | dst0, "", LONGSTR, "", 0}, { |
| 230 | dst0, tiat, LONGSTR, tiat, 0}, { |
| 231 | dst0, longstr, LONGSTR, longstr, 0}, |
| 232 | /* Restricted strcpy stuff */ |
| 233 | { |
| 234 | dst1, tiat, 0, "", 0}, { |
| 235 | dst1, longstr, 5, "ttttt", 0}, { |
| 236 | NULL, NULL, 0, NULL, 0} |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 239 | /***** LTP Port *****/ |
| 240 | void setup(); |
| 241 | int blenter(); |
| 242 | int blexit(); |
| 243 | int anyfail(); |
| 244 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 245 | void setup(void) |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 246 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 247 | temp = stderr; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 250 | int blenter(void) |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 251 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 252 | local_flag = PASSED; |
| 253 | return 0; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 256 | int blexit(void) |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 257 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 258 | (local_flag == PASSED) ? tst_resm(TPASS, |
| 259 | "Test passed") : tst_resm(TFAIL, |
| 260 | "Test failed"); |
| 261 | return 0; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 264 | int anyfail(void) |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 265 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 266 | tst_exit(); |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /***** ** ** *****/ |
| 270 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 271 | /*--------------------------------------------------------------*/ |
| 272 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 273 | int main(int argc, char *argv[]) |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 274 | { |
| 275 | register int n, i; |
| 276 | char *s, *pr; |
| 277 | |
| 278 | /* |
| 279 | * Init longstr |
| 280 | */ |
| 281 | |
| 282 | s = longstr; |
| 283 | n = LONGSTR; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 284 | while (n--) |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 285 | *s++ = 't'; |
| 286 | *s = '\0'; |
| 287 | |
| 288 | setup(); |
| 289 | /*--------------------------------------------------------------*/ |
| 290 | |
| 291 | /* |
| 292 | * Index |
| 293 | */ |
| 294 | //fprintf(temp, "\tStrchr\n" ); |
| 295 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 296 | while (t_index[i].s) { |
| 297 | if ((pr = |
| 298 | strchr(t_index[i].s, t_index[i].c)) != t_index[i].e_res) { |
| 299 | fprintf(temp, "(Strchr) test %d", i); |
| 300 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 301 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 302 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 303 | } |
| 304 | /* |
| 305 | * Strrchr |
| 306 | */ |
| 307 | //fprintf(temp, "\tStrrchr\n" ); |
| 308 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 309 | while (t_rindex[i].s) { |
| 310 | if ((pr = strrchr(t_rindex[i].s, t_rindex[i].c)) |
| 311 | != t_rindex[i].e_res) { |
| 312 | fprintf(temp, "(Strrchr) test %d", i); |
| 313 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 314 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 315 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 316 | } |
| 317 | /* |
| 318 | * Strlen |
| 319 | */ |
| 320 | //fprintf(temp, "\tStrlen\n" ); |
| 321 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 322 | while (t_len[i].s) { |
| 323 | if ((n = strlen(t_len[i].s)) != t_len[i].e_res) { |
| 324 | fprintf(temp, "(Strlen) test %d: expected %d, got %d", |
| 325 | i, t_len[i].e_res, n); |
| 326 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 327 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 328 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* |
| 332 | * Strcmp |
| 333 | */ |
| 334 | //fprintf(temp, "\tStrcmp\n" ); |
| 335 | i = 0; |
| 336 | #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0)) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 337 | while (t_cmp[i].s1) { |
| 338 | n = strcmp(t_cmp[i].s1, t_cmp[i].s2); |
| 339 | if (sign(n) != sign(t_cmp[i].e_res)) { |
| 340 | fprintf(temp, "(Strcmp) test %d: expected %d, got %d", |
| 341 | i, sign(t_cmp[i].e_res), sign(n)); |
| 342 | local_flag = FAILED; |
| 343 | } |
| 344 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /* |
| 348 | * Strcat |
| 349 | */ |
| 350 | //fprintf(temp, "\tStrcat\n" ); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 351 | memset(dst0, 0, LONGSTR + 1); /* clean slate */ |
| 352 | memset(dst1, 0, LONGSTR + 1); /* clean slate */ |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 353 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 354 | while (t_cat[i].s1) { |
| 355 | if ((n = |
| 356 | strcmp(strcat(t_cat[i].s1, t_cat[i].s2), t_cat[i].s1s2)) |
| 357 | != t_cat[i].e_res) { |
| 358 | fprintf(temp, "(Strcat) test %d: expected %d, got %d", |
| 359 | i, t_cat[i].e_res, n); |
| 360 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 361 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 362 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Strcpy |
| 367 | */ |
| 368 | //fprintf(temp, "\tStrcpy\n" ); |
| 369 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 370 | while (t_cpy[i].s1) { |
| 371 | if ((n = strcmp(strcpy(t_cpy[i].s1, t_cpy[i].s2), t_cpy[i].s2)) |
| 372 | != t_cpy[i].e_res) { |
| 373 | fprintf(temp, "(Strcpy) test %d: expected %d, got %d", |
| 374 | i, t_cpy[i].e_res, n); |
| 375 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 376 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 377 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Strncat |
| 382 | */ |
| 383 | //fprintf(temp, "\tStrncat\n" ); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 384 | memset(dst0, 0, LONGSTR + 1); /* clean slate */ |
| 385 | memset(dst1, 0, LONGSTR + 1); /* clean slate */ |
| 386 | memset(dst2, 0, LONGSTR + 1); /* clean slate */ |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 387 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 388 | while (t_ncat[i].s1) { |
| 389 | if ((n = |
| 390 | strcmp(strncat(t_ncat[i].s1, t_ncat[i].s2, t_ncat[i].n), |
| 391 | t_ncat[i].s1ns2)) != t_ncat[i].e_res) { |
| 392 | fprintf(temp, "(Strncat) test %d: expected %d, got %d", |
| 393 | i, t_ncat[i].e_res, n); |
| 394 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 395 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 396 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 397 | } |
| 398 | |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 399 | /* |
| 400 | * Strncmp |
| 401 | */ |
| 402 | //fprintf(temp, "\tStrncmp\n" ); |
| 403 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 404 | while (t_ncmp[i].s1) { |
| 405 | if ((n = strncmp(t_ncmp[i].s1, t_ncmp[i].s2, t_ncmp[i].n)) |
| 406 | != t_ncmp[i].e_res) { |
| 407 | if ((t_ncmp[i].a_res < 0 && n > t_ncmp[i].a_res) |
| 408 | || (t_ncmp[i].a_res > 0 && n < t_ncmp[i].a_res)) { |
| 409 | fprintf(temp, |
| 410 | "(Strncmp) test %d: expected %d, got %d", |
| 411 | i, t_ncmp[i].e_res, n); |
| 412 | local_flag = FAILED; |
| 413 | } |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 414 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 415 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* |
| 419 | * Strncpy |
| 420 | */ |
| 421 | //fprintf(temp, "\tStrncpy\n" ); |
| 422 | i = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 423 | memset(dst0, 0, LONGSTR + 1); /* clean slate */ |
| 424 | memset(dst1, 0, LONGSTR + 1); /* clean slate */ |
| 425 | while (t_ncpy[i].s1) { |
| 426 | if ((n = |
| 427 | strcmp(strncpy(t_ncpy[i].s1, t_ncpy[i].s2, t_ncpy[i].n), |
| 428 | t_ncpy[i].s1n)) != t_ncpy[i].e_res) { |
| 429 | fprintf(temp, "(Strncpy) test %d: expected %d, got %d", |
| 430 | i, t_ncpy[i].e_res, n); |
| 431 | local_flag = FAILED; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 432 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 433 | i++; |
robbiew | c58f59a | 2002-12-31 22:43:14 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | blexit(); |
| 437 | anyfail(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 438 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 439 | } |