X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=libiberty%2Ftestsuite%2Ftest-expandargv.c;h=234de9ae6bdc0eaf57807ac9a56648ca76380518;hb=5ca0b868fa7f767788555b3c32d8931017c0d756;hp=9d1af01454598941576e67123e15c16cc5c2f465;hpb=01f0fe5e0450edf168c1f612feb93cf588e4e7ea;p=external%2Fbinutils.git diff --git a/libiberty/testsuite/test-expandargv.c b/libiberty/testsuite/test-expandargv.c index 9d1af01..234de9a 100644 --- a/libiberty/testsuite/test-expandargv.c +++ b/libiberty/testsuite/test-expandargv.c @@ -1,5 +1,5 @@ /* expandargv test program, - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006-2019 Free Software Foundation, Inc. Written by Carlos O'Donell This file is part of the libiberty library, which is part of GCC. @@ -40,6 +40,9 @@ #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 @@ -107,6 +110,38 @@ const char *test_data[] = { ARGV0, 0, + /* Test 4 - Check for options beginning with an empty line. */ + "\na\nb", /* Test 4 data */ + ARGV0, + "@test-expandargv-4.lst", + 0, + ARGV0, + "a", + "b", + 0, + + /* Test 5 - Check for options containing an empty argument. */ + "a\n''\nb", /* Test 5 data */ + ARGV0, + "@test-expandargv-5.lst", + 0, + ARGV0, + "a", + "", + "b", + 0, + + /* Test 6 - Check for options containing a quoted newline. */ + "a\n'a\n\nb'\nb", /* Test 6 data */ + ARGV0, + "@test-expandargv-6.lst", + 0, + ARGV0, + "a", + "a\n\nb", + "b", + 0, + 0 /* Test done marker, don't remove. */ }; @@ -157,7 +192,7 @@ writeout_test (int test, const char * test_data) { char filename[256]; FILE *fd; - size_t len; + size_t len, sys_fwrite; char * parse; /* Unique filename per test */ @@ -172,11 +207,14 @@ writeout_test (int test, const char * test_data) if (parse == NULL) fatal_error (__LINE__, "Failed to malloc parse.", errno); - memcpy (parse, test_data, sizeof (char) * len); + memcpy (parse, test_data, sizeof (char) * (len + 1)); /* Run all possible replaces */ run_replaces (parse); - fwrite (parse, len, sizeof (char), fd); + sys_fwrite = fwrite (parse, sizeof (char), len, fd); + if (sys_fwrite != len) + fatal_error (__LINE__, "Failed to write to test file.", errno); + free (parse); fclose (fd); } @@ -246,7 +284,7 @@ run_tests (const char **test_data) /* Compare each of the argv's ... */ else for (k = 0; k < argc_after; k++) - if (strncmp (argv_before[k], argv_after[k], strlen(argv_after[k])) != 0) + if (strcmp (argv_before[k], argv_after[k]) != 0) { printf ("FAIL: test-expandargv-%d. Arguments don't match.\n", i); failed++;