summaryrefslogtreecommitdiff
path: root/gl/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-05-01 11:32:10 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-05-01 11:34:43 +0200
commit150738f7f3c113272486329931fa20bbbf3d7f36 (patch)
tree668ff1b2a6db84527d485ce16d4e61357ad6cac4 /gl/tests
parenta65dcbbf9c36047e1df51f360873d40bddf72902 (diff)
downloadgnutls-150738f7f3c113272486329931fa20bbbf3d7f36.tar.gz
Added missing m4 gl files.
Diffstat (limited to 'gl/tests')
-rw-r--r--gl/tests/.gitignore22
-rw-r--r--gl/tests/intprops.h86
-rw-r--r--gl/tests/test-byteswap.c32
-rw-r--r--gl/tests/test-func.c40
-rw-r--r--gl/tests/test-hmac-md5.c147
-rw-r--r--gl/tests/test-md5.c67
-rw-r--r--gl/tests/test-strings.c27
-rw-r--r--gl/tests/test-strverscmp.c46
-rw-r--r--gl/tests/test-u64.c47
-rw-r--r--gl/tests/test-vasprintf.c103
-rw-r--r--gl/tests/test-vsnprintf.c77
11 files changed, 672 insertions, 22 deletions
diff --git a/gl/tests/.gitignore b/gl/tests/.gitignore
deleted file mode 100644
index fd28609a7e..0000000000
--- a/gl/tests/.gitignore
+++ /dev/null
@@ -1,22 +0,0 @@
-/intprops.h
-/test-byteswap.c
-/test-func.c
-/test-hmac-md5.c
-/test-md5.c
-/test-strings.c
-/test-strverscmp.c
-/test-vasprintf.c
-/test-vsnprintf.c
-/test-netinet_in.c
-/test-fseeko.c
-/test-fseeko.sh
-/test-fseeko2.sh
-/test-getdelim.c
-/test-getline.c
-/test-u64.c
-/test-version-etc.c
-/test-version-etc.sh
-/version-etc-fsf.c
-/dummy.c
-/test-gettimeofday.c
-/test-sys_time.c
diff --git a/gl/tests/intprops.h b/gl/tests/intprops.h
new file mode 100644
index 0000000000..58b1b3fbf4
--- /dev/null
+++ b/gl/tests/intprops.h
@@ -0,0 +1,86 @@
+/* intprops.h -- properties of integer types
+
+ Copyright (C) 2001-2005, 2009-2011 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 Paul Eggert. */
+
+#ifndef GL_INTPROPS_H
+# define GL_INTPROPS_H
+
+# include <limits.h>
+
+/* The extra casts in the following macros work around compiler bugs,
+ e.g., in Cray C 5.0.3.0. */
+
+/* True if the arithmetic type T is an integer type. bool counts as
+ an integer. */
+# define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
+
+/* True if negative values of the signed integer type T use two's
+ complement, ones' complement, or signed magnitude representation,
+ respectively. Much GNU code assumes two's complement, but some
+ people like to be portable to all possible C hosts. */
+# define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
+# define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
+# define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+
+/* True if the arithmetic type T is signed. */
+# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* The maximum and minimum values for the integer type T. These
+ macros have undefined behavior if T is signed and has padding bits.
+ If this is a problem for you, please let us know how to fix it for
+ your host. */
+# define TYPE_MINIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) 0 \
+ : TYPE_SIGNED_MAGNITUDE (t) \
+ ? ~ (t) 0 \
+ : ~ TYPE_MAXIMUM (t)))
+# define TYPE_MAXIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) -1 \
+ : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
+
+/* Return zero if T can be determined to be an unsigned type.
+ Otherwise, return 1.
+ When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
+ tighter bound. Otherwise, it overestimates the true bound by one byte
+ when applied to unsigned types of size 2, 4, 16, ... bytes.
+ The symbol signed_type_or_expr__ is private to this header file. */
+# if __GNUC__ >= 2
+# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
+# else
+# define signed_type_or_expr__(t) 1
+# endif
+
+/* Bound on length of the string representing an unsigned integer
+ value representable in B bits. log10 (2.0) < 146/485. The
+ smallest value of B where this bound is not tight is 2621. */
+# define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485)
+
+/* Bound on length of the string representing an integer type or expression T.
+ Subtract 1 for the sign bit if T is signed, and then add 1 more for
+ a minus sign if needed. */
+# define INT_STRLEN_BOUND(t) \
+ (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) \
+ + signed_type_or_expr__ (t))
+
+/* Bound on buffer size needed to represent an integer type or expression T,
+ including the terminating null. */
+# define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
+
+#endif /* GL_INTPROPS_H */
diff --git a/gl/tests/test-byteswap.c b/gl/tests/test-byteswap.c
new file mode 100644
index 0000000000..e9878b3c7b
--- /dev/null
+++ b/gl/tests/test-byteswap.c
@@ -0,0 +1,32 @@
+/* Test of <byteswap.h> substitute.
+ Copyright (C) 2007-2011 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 Bruno Haible <bruno@clisp.org>, 2007. */
+
+#include <config.h>
+
+#include <byteswap.h>
+
+#include "macros.h"
+
+int
+main ()
+{
+ ASSERT (bswap_16 (0xABCD) == 0xCDAB);
+ ASSERT (bswap_32 (0xDEADBEEF) == 0xEFBEADDE);
+
+ return 0;
+}
diff --git a/gl/tests/test-func.c b/gl/tests/test-func.c
new file mode 100644
index 0000000000..19de6d3ada
--- /dev/null
+++ b/gl/tests/test-func.c
@@ -0,0 +1,40 @@
+/* Test whether __func__ is available
+ Copyright (C) 2008-2011 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 Bruno Haible <bruno@clisp.org>, 2008. */
+
+#include <config.h>
+
+#include <string.h>
+
+#include "macros.h"
+
+int
+main ()
+{
+ ASSERT (strlen (__func__) > 0);
+
+ /* On SunPRO C 5.9, sizeof __func__ evaluates to 0. The compiler warns:
+ "warning: null dimension: sizeof()". */
+#if !defined __SUNPRO_C
+ ASSERT (strlen (__func__) + 1 == sizeof __func__);
+#endif
+
+ ASSERT (strcmp (__func__, "main") == 0
+ || strcmp (__func__, "<unknown function>") == 0);
+
+ return 0;
+}
diff --git a/gl/tests/test-hmac-md5.c b/gl/tests/test-hmac-md5.c
new file mode 100644
index 0000000000..575a7164cb
--- /dev/null
+++ b/gl/tests/test-hmac-md5.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2005, 2010-2011 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 Simon Josefsson. */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+#include "hmac.h"
+
+/* Test vectors from RFC 2104. */
+
+int
+main (int argc, char *argv[])
+{
+ {
+ /*
+ key = 0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
+ key_len = 16 bytes
+ data = "Hi There"
+ data_len = 8 bytes
+ digest = 0x9294727a3638bb1c13f48ef8158bfc9d
+ */
+ char *key =
+ "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
+ size_t key_len = 16;
+ char *data = "Hi There";
+ size_t data_len = 8;
+ char *digest =
+ "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
+ char out[16];
+
+ if (hmac_md5 (key, key_len, data, data_len, out) != 0)
+ {
+ printf ("call failure\n");
+ return 1;
+ }
+
+ if (memcmp (digest, out, 16) != 0)
+ {
+ size_t i;
+ printf ("hash 1 mismatch. expected:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", digest[i] & 0xFF);
+ printf ("\ncomputed:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", out[i] & 0xFF);
+ printf ("\n");
+ return 1;
+ }
+ }
+
+ {
+ /*
+ key = "Jefe"
+ data = "what do ya want for nothing?"
+ data_len = 28 bytes
+ digest = 0x750c783e6ab0b503eaa86e310a5db738
+ */
+ char *key = "Jefe";
+ size_t key_len = 4;
+ char *data = "what do ya want for nothing?";
+ size_t data_len = 28;
+ char *digest =
+ "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
+ char out[16];
+
+ if (hmac_md5 (key, key_len, data, data_len, out) != 0)
+ {
+ printf ("call failure\n");
+ return 1;
+ }
+
+ if (memcmp (digest, out, 16) != 0)
+ {
+ size_t i;
+ printf ("hash 2 mismatch. expected:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", digest[i] & 0xFF);
+ printf ("\ncomputed:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", out[i] & 0xFF);
+ printf ("\n");
+ return 1;
+ }
+ }
+
+ {
+ /*
+ key = 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ key_len 16 bytes
+ data = 0xDDDDDDDDDDDDDDDDDDDD...
+ ..DDDDDDDDDDDDDDDDDDDD...
+ ..DDDDDDDDDDDDDDDDDDDD...
+ ..DDDDDDDDDDDDDDDDDDDD...
+ ..DDDDDDDDDDDDDDDDDDDD
+ data_len = 50 bytes
+ digest = 0x56be34521d144c88dbb8c733f0e8b3f6
+ */
+ char *key =
+ "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
+ size_t key_len = 16;
+ char *data = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
+ "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
+ "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
+ "\xDD\xDD";
+ size_t data_len = 50;
+ char *digest =
+ "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6";
+ char out[16];
+
+ if (hmac_md5 (key, key_len, data, data_len, out) != 0)
+ {
+ printf ("call failure\n");
+ return 1;
+ }
+
+ if (memcmp (digest, out, 16) != 0)
+ {
+ size_t i;
+ printf ("hash 3 mismatch. expected:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", digest[i] & 0xFF);
+ printf ("\ncomputed:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", out[i] & 0xFF);
+ printf ("\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
diff --git a/gl/tests/test-md5.c b/gl/tests/test-md5.c
new file mode 100644
index 0000000000..99d49b868f
--- /dev/null
+++ b/gl/tests/test-md5.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2005, 2009-2011 Free Software Foundation, Inc.
+ * Written by Simon Josefsson
+ *
+ * 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 Simon Josefsson. */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include "md5.h"
+
+int
+main (void)
+{
+ /* Test vectors from RFC 1321. */
+
+ const char *in1 = "abc";
+ const char *out1 =
+ "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72";
+ const char *in2 = "message digest";
+ const char *out2 =
+ "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0";
+ char buf[MD5_DIGEST_SIZE];
+
+ if (memcmp (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE) != 0)
+ {
+ size_t i;
+ printf ("expected:\n");
+ for (i = 0; i < MD5_DIGEST_SIZE; i++)
+ printf ("%02x ", out1[i] & 0xFF);
+ printf ("\ncomputed:\n");
+ for (i = 0; i < MD5_DIGEST_SIZE; i++)
+ printf ("%02x ", buf[i] & 0xFF);
+ printf ("\n");
+ return 1;
+ }
+
+ if (memcmp (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE) != 0)
+ {
+ size_t i;
+ printf ("expected:\n");
+ for (i = 0; i < MD5_DIGEST_SIZE; i++)
+ printf ("%02x ", out2[i] & 0xFF);
+ printf ("\ncomputed:\n");
+ for (i = 0; i < MD5_DIGEST_SIZE; i++)
+ printf ("%02x ", buf[i] & 0xFF);
+ printf ("\n");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/gl/tests/test-strings.c b/gl/tests/test-strings.c
new file mode 100644
index 0000000000..ee2ad62714
--- /dev/null
+++ b/gl/tests/test-strings.c
@@ -0,0 +1,27 @@
+/* Test of <strings.h> substitute.
+ Copyright (C) 2007, 2009-2011 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 Bruno Haible <bruno@clisp.org>, 2007. */
+
+#include <config.h>
+
+#include <strings.h>
+
+int
+main ()
+{
+ return 0;
+}
diff --git a/gl/tests/test-strverscmp.c b/gl/tests/test-strverscmp.c
new file mode 100644
index 0000000000..9a9da1025e
--- /dev/null
+++ b/gl/tests/test-strverscmp.c
@@ -0,0 +1,46 @@
+/* Test of strverscmp() function.
+ Copyright (C) 2008-2011 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, 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, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Eric Blake <ebb9@byu.net>, 2008. */
+
+#include <config.h>
+
+#include <string.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (strverscmp, int, (const char *, const char *));
+
+#include "macros.h"
+
+int
+main (void)
+{
+ ASSERT (strverscmp ("", "") == 0);
+ ASSERT (strverscmp ("a", "a") == 0);
+ ASSERT (strverscmp ("a", "b") < 0);
+ ASSERT (strverscmp ("b", "a") > 0);
+ ASSERT (strverscmp ("000", "00") < 0);
+ ASSERT (strverscmp ("00", "000") > 0);
+ ASSERT (strverscmp ("a0", "a") > 0);
+ ASSERT (strverscmp ("00", "01") < 0);
+ ASSERT (strverscmp ("01", "010") < 0);
+ ASSERT (strverscmp ("010", "09") < 0);
+ ASSERT (strverscmp ("09", "0") < 0);
+ ASSERT (strverscmp ("9", "10") < 0);
+ ASSERT (strverscmp ("0a", "0") > 0);
+ return 0;
+}
diff --git a/gl/tests/test-u64.c b/gl/tests/test-u64.c
new file mode 100644
index 0000000000..bdfc95f6c5
--- /dev/null
+++ b/gl/tests/test-u64.c
@@ -0,0 +1,47 @@
+/* Test of <u64.h>
+ Copyright (C) 2009-2011 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 Simon Josefsson <simon@josefsson.org>, 2009. */
+
+#include <config.h>
+
+#include <u64.h>
+
+int
+main (void)
+{
+ u64 i = u64init (42, 4711);
+ u64 j, k, l;
+
+ j = u64hilo (42, 4711);
+
+ if (u64lt (i, j) || u64lt (j, i))
+ return 1;
+
+ i = u64hilo (0, 42);
+ j = u64hilo (0, 43);
+
+ if (!u64lt (i, j))
+ return 1;
+
+ k = u64plus (i, j);
+ l = u64hilo (0, 42 + 43);
+
+ if (u64lt (k, l) || u64lt (l, k))
+ return 1;
+
+ return 0;
+}
diff --git a/gl/tests/test-vasprintf.c b/gl/tests/test-vasprintf.c
new file mode 100644
index 0000000000..6882d18d62
--- /dev/null
+++ b/gl/tests/test-vasprintf.c
@@ -0,0 +1,103 @@
+/* Test of vasprintf() and asprintf() functions.
+ Copyright (C) 2007-2011 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 Bruno Haible <bruno@clisp.org>, 2007. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (asprintf, int, (char **, char const *, ...));
+SIGNATURE_CHECK (vasprintf, int, (char **, char const *, va_list));
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "macros.h"
+
+static int
+my_asprintf (char **result, const char *format, ...)
+{
+ va_list args;
+ int ret;
+
+ va_start (args, format);
+ ret = vasprintf (result, format, args);
+ va_end (args);
+ return ret;
+}
+
+static void
+test_vasprintf ()
+{
+ int repeat;
+
+ for (repeat = 0; repeat <= 8; repeat++)
+ {
+ char *result;
+ int retval = my_asprintf (&result, "%d", 12345);
+ ASSERT (retval == 5);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "12345") == 0);
+ free (result);
+ }
+
+ for (repeat = 0; repeat <= 8; repeat++)
+ {
+ char *result;
+ int retval = my_asprintf (&result, "%08lx", 12345UL);
+ ASSERT (retval == 8);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "00003039") == 0);
+ free (result);
+ }
+}
+
+static void
+test_asprintf ()
+{
+ int repeat;
+
+ for (repeat = 0; repeat <= 8; repeat++)
+ {
+ char *result;
+ int retval = asprintf (&result, "%d", 12345);
+ ASSERT (retval == 5);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "12345") == 0);
+ free (result);
+ }
+
+ for (repeat = 0; repeat <= 8; repeat++)
+ {
+ char *result;
+ int retval = asprintf (&result, "%08lx", 12345UL);
+ ASSERT (retval == 8);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "00003039") == 0);
+ free (result);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ test_vasprintf ();
+ test_asprintf ();
+ return 0;
+}
diff --git a/gl/tests/test-vsnprintf.c b/gl/tests/test-vsnprintf.c
new file mode 100644
index 0000000000..5060836e78
--- /dev/null
+++ b/gl/tests/test-vsnprintf.c
@@ -0,0 +1,77 @@
+/* Test of vsnprintf() function.
+ Copyright (C) 2007-2011 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 Bruno Haible <bruno@clisp.org>, 2007. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (vsnprintf, int, (char *, size_t, char const *, va_list));
+
+#include <stdarg.h>
+#include <string.h>
+
+#include "macros.h"
+
+static int
+my_snprintf (char *buf, int size, const char *format, ...)
+{
+ va_list args;
+ int ret;
+
+ va_start (args, format);
+ ret = vsnprintf (buf, size, format, args);
+ va_end (args);
+ return ret;
+}
+
+int
+main (int argc, char *argv[])
+{
+ char buf[8];
+ int size;
+ int retval;
+
+ retval = my_snprintf (NULL, 0, "%d", 12345);
+ ASSERT (retval == 5);
+
+ for (size = 0; size <= 8; size++)
+ {
+ memcpy (buf, "DEADBEEF", 8);
+ retval = my_snprintf (buf, size, "%d", 12345);
+ ASSERT (retval == 5);
+ if (size < 6)
+ {
+ if (size > 0)
+ {
+ ASSERT (memcmp (buf, "12345", size - 1) == 0);
+ ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size);
+ }
+#if !CHECK_VSNPRINTF_POSIX
+ if (size > 0)
+#endif
+ ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
+ }
+ else
+ {
+ ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
+ }
+ }
+
+ return 0;
+}