X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-getline.c;h=134e320a8a270a7809b5326723ac2830be349ee6;hb=5191b3546cfb6c163228c23f214e325ddf60d46f;hp=6b66d71dbec4c8aae224563f42188aeb3104edf5;hpb=d68417c03e69fde605af699ba9a9671c663d8baf;p=gnulib.git
diff --git a/tests/test-getline.c b/tests/test-getline.c
index 6b66d71db..134e320a8 100644
--- a/tests/test-getline.c
+++ b/tests/test-getline.c
@@ -1,5 +1,5 @@
/* Test of getline() function.
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007-2013 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
@@ -12,60 +12,65 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program; if not, see . */
/* Written by Eric Blake , 2007. */
#include
#include
+
+#include "signature.h"
+SIGNATURE_CHECK (getline, ssize_t, (char **, size_t *, 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-getline.txt", "wb");
- if (!f || fwrite ("a\nbc\nd\0f", 1, 8, f) != 8 || fclose (f) != 0)
+ if (!f || fwrite ("a\nA\nbc\nd\0f", 1, 10, f) != 10 || fclose (f) != 0)
{
fputs ("Failed to create sample file.\n", stderr);
- unlink ("test-getline.txt");
+ remove ("test-getline.txt");
return 1;
}
f = fopen ("test-getline.txt", "rb");
if (!f)
{
fputs ("Failed to reopen sample file.\n", stderr);
- unlink ("test-getline.txt");
+ remove ("test-getline.txt");
return 1;
}
/* Test initial allocation, which must include trailing NUL. */
+ line = NULL;
+ len = 0;
result = getline (&line, &len, f);
ASSERT (result == 2);
ASSERT (strcmp (line, "a\n") == 0);
ASSERT (2 < len);
+ free (line);
- /* Test growth of buffer, must not leak. */
+ /* Test initial allocation again, with line = NULL and len != 0. */
+ line = NULL;
+ len = (size_t)(~0) / 4;
+ result = getline (&line, &len, f);
+ ASSERT (result == 2);
+ ASSERT (strcmp (line, "A\n") == 0);
+ ASSERT (2 < len);
free (line);
+
+ /* Test growth of buffer, must not leak. */
line = malloc (1);
len = 0;
result = getline (&line, &len, f);
@@ -84,6 +89,6 @@ main (int argc, char **argv)
free (line);
fclose (f);
- unlink ("test-getline.txt");
+ remove ("test-getline.txt");
return 0;
}