X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-getdelim.c;h=a5df49f1ddad15e0e6b9db16fdabd9eace0a0742;hb=26947b67c9e1e45a836d81613d0c4fa2fe6cf51a;hp=e33099b9cef484d07c537da33570369e816888c0;hpb=d68417c03e69fde605af699ba9a9671c663d8baf;p=gnulib.git diff --git a/tests/test-getdelim.c b/tests/test-getdelim.c index e33099b9c..a5df49f1d 100644 --- a/tests/test-getdelim.c +++ b/tests/test-getdelim.c @@ -1,5 +1,5 @@ /* Test of getdelim() function. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,52 +20,58 @@ #include #include + +#include "signature.h" +SIGNATURE_CHECK (getdelim, ssize_t, (char **, size_t *, int, FILE *)); + #include #include -#define ASSERT(expr) \ - do \ - { \ - if (!(expr)) \ - { \ - fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ - abort (); \ - } \ - } \ - while (0) +#include "macros.h" int -main (int argc, char **argv) +main (void) { FILE *f; - char *line = NULL; - size_t len = 0; + char *line; + size_t len; ssize_t result; /* Create test file. */ f = fopen ("test-getdelim.txt", "wb"); - if (!f || fwrite ("anbcnd\0f", 1, 8, f) != 8 || fclose (f) != 0) + if (!f || fwrite ("anAnbcnd\0f", 1, 10, f) != 10 || fclose (f) != 0) { fputs ("Failed to create sample file.\n", stderr); - unlink ("test-getdelim.txt"); + remove ("test-getdelim.txt"); return 1; } f = fopen ("test-getdelim.txt", "rb"); if (!f) { fputs ("Failed to reopen sample file.\n", stderr); - unlink ("test-getdelim.txt"); + remove ("test-getdelim.txt"); return 1; } /* Test initial allocation, which must include trailing NUL. */ + line = NULL; + len = 0; result = getdelim (&line, &len, 'n', f); ASSERT (result == 2); ASSERT (strcmp (line, "an") == 0); ASSERT (2 < len); + free (line); - /* Test growth of buffer. */ + /* Test initial allocation again, with line = NULL and len != 0. */ + line = NULL; + len = (size_t)(~0) / 4; + result = getdelim (&line, &len, 'n', f); + ASSERT (result == 2); + ASSERT (strcmp (line, "An") == 0); + ASSERT (2 < len); free (line); + + /* Test growth of buffer. */ line = malloc (1); len = 1; result = getdelim (&line, &len, 'n', f); @@ -84,6 +90,6 @@ main (int argc, char **argv) free (line); fclose (f); - unlink ("test-getdelim.txt"); + remove ("test-getdelim.txt"); return 0; }