bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] open_memstream-tests: new module


From: Eric Blake
Subject: [PATCH 1/2] open_memstream-tests: new module
Date: Fri, 23 Apr 2010 16:45:22 -0600

Test passes on Linux and cygwin 1.7, but fails everywhere that
open_memstream is not implemented.

* modules/open_memstream-tests: New file.
* tests/test-open_memstream.c: Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                    |    6 ++++
 modules/open_memstream-tests |   12 ++++++++
 tests/test-open_memstream.c  |   58 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 modules/open_memstream-tests
 create mode 100644 tests/test-open_memstream.c

diff --git a/ChangeLog b/ChangeLog
index dc4aed3..78f9667 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-04-23  Eric Blake  <address@hidden>
+
+       open_memstream-tests: new module
+       * modules/open_memstream-tests: New file.
+       * tests/test-open_memstream.c: Likewise.
+
 2010-04-23  Jim Meyering  <address@hidden>

        vc-list-files tests: convert to use init.sh
diff --git a/modules/open_memstream-tests b/modules/open_memstream-tests
new file mode 100644
index 0000000..b3bf049
--- /dev/null
+++ b/modules/open_memstream-tests
@@ -0,0 +1,12 @@
+Files:
+tests/test-open_memstream.c
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-open_memstream
+check_PROGRAMS += test-open_memstream
diff --git a/tests/test-open_memstream.c b/tests/test-open_memstream.c
new file mode 100644
index 0000000..1c6e090
--- /dev/null
+++ b/tests/test-open_memstream.c
@@ -0,0 +1,58 @@
+/* Test of opening a stream around a malloc'd string.
+   Copyright (C) 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2010.  */
+
+#include <config.h>
+
+/* None of the files accessed by this test are large, so disable the
+   fseek link warning if we are not using the gnulib fseek module.  */
+#define _GL_NO_LARGE_FILES
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (open_memstream, FILE *, (char **, size_t *));
+
+#include <string.h>
+
+#include "macros.h"
+
+#define STREQ(s1, s2) (strcmp (s1, s2) == 0)
+
+int
+main (void)
+{
+  size_t len;
+  char *buf;
+  off_t off;
+  FILE *f;
+
+  ASSERT ((f = open_memstream (&buf, &len)) != NULL);
+  ASSERT (fputs ("hello my world", f) >= 0);
+  ASSERT (fflush (f) == 0);
+  ASSERT (STREQ (buf, "hello my world"));
+  ASSERT (len = strlen (buf));
+  off = ftell (f);
+  ASSERT (off == len);
+  ASSERT (fseek (f, 0, SEEK_SET) == 0);
+  ASSERT (fputs ("good-bye", f) >= 0);
+  ASSERT (fseek (f, off, SEEK_SET) == 0);
+  ASSERT (fclose (f) == 0);
+  ASSERT (STREQ (buf, "good-bye world"));
+  ASSERT (len = strlen (buf));
+  free (buf);
+  return 0;
+}
-- 
1.6.6.1





reply via email to

[Prev in Thread] Current Thread [Next in Thread]