From: Bruno Haible Date: Mon, 28 Oct 2019 00:11:21 +0000 (+0100) Subject: libtextstyle: Add test for ostream_printf. X-Git-Tag: v0.21~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55b8fe9a2f12b22eb3ee6baf973e03e60b3a9915;p=thirdparty%2Fgettext.git libtextstyle: Add test for ostream_printf. * libtextstyle/gnulib-local/tests/test-memory-ostream.c: New file. * libtextstyle/gnulib-local/modules/memory-ostream-tests: New file. * libtextstyle/Makefile.am (EXTRA_DIST): Add them. * libtextstyle/autogen.sh (GNULIB_MODULES): Add 'memory-ostream-tests'. --- diff --git a/libtextstyle/Makefile.am b/libtextstyle/Makefile.am index 0f4576cf1..318c0320f 100644 --- a/libtextstyle/Makefile.am +++ b/libtextstyle/Makefile.am @@ -144,6 +144,7 @@ EXTRA_DIST = \ gnulib-local/modules/libglib \ gnulib-local/modules/libxml.diff \ gnulib-local/modules/memory-ostream \ + gnulib-local/modules/memory-ostream-tests \ gnulib-local/modules/moo \ gnulib-local/modules/moo-tests \ gnulib-local/modules/noop-styled-ostream \ @@ -156,6 +157,7 @@ EXTRA_DIST = \ gnulib-local/modules/term-ostream \ gnulib-local/modules/term-ostream-tests \ gnulib-local/modules/term-styled-ostream \ + gnulib-local/tests/test-memory-ostream.c \ gnulib-local/tests/test-moo-aroot.oo.c \ gnulib-local/tests/test-moo-aroot.oo.h \ gnulib-local/tests/test-moo-assign.c \ diff --git a/libtextstyle/autogen.sh b/libtextstyle/autogen.sh index 9edce49ca..160bae4d8 100755 --- a/libtextstyle/autogen.sh +++ b/libtextstyle/autogen.sh @@ -91,6 +91,7 @@ if test $skip_gnulib = false; then xalloc xconcat-filename + memory-ostream-tests term-ostream-tests ' $GNULIB_TOOL --lib=libtextstyle --source-base=lib --m4-base=gnulib-m4 --tests-base=tests \ diff --git a/libtextstyle/gnulib-local/modules/memory-ostream-tests b/libtextstyle/gnulib-local/modules/memory-ostream-tests new file mode 100644 index 000000000..fb6ef8434 --- /dev/null +++ b/libtextstyle/gnulib-local/modules/memory-ostream-tests @@ -0,0 +1,10 @@ +Files: +tests/test-memory-ostream.c + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-memory-ostream +check_PROGRAMS += test-memory-ostream diff --git a/libtextstyle/gnulib-local/tests/test-memory-ostream.c b/libtextstyle/gnulib-local/tests/test-memory-ostream.c new file mode 100644 index 000000000..bc6dfdc8e --- /dev/null +++ b/libtextstyle/gnulib-local/tests/test-memory-ostream.c @@ -0,0 +1,33 @@ +/* Test for the memory-ostream API. */ + +#include + +#include "memory-ostream.h" + +#include +#include + +int +main () +{ + memory_ostream_t stream = memory_ostream_create (); + + ostream_write_str (stream, "foo"); + ostream_printf (stream, "%d%d", 73, 55); + ostream_write_str (stream, "\n"); + + { + const void *buf; + size_t buflen; + memory_ostream_contents (stream, &buf, &buflen); + + if (!(buflen == 8)) + exit (2); + if (!(memcmp (buf, "foo7355\n", 8) == 0)) + exit (3); + + ostream_free (stream); + } + + return 0; +}