2024-06-25 Bruno Haible <bruno@clisp.org>
+ c-vazsprintf-gnu: Add tests.
+ * tests/test-vazsprintf-gnu.h: New file, extracted from
+ tests/test-vazsprintf-gnu.c.
+ * tests/test-vazsprintf-gnu.c: Include test-vazsprintf-gnu.h.
+ (test_function): Moved out to tests/test-vazsprintf-gnu.h.
+ * modules/vazsprintf-gnu-tests (Files): Add tests/test-vazsprintf-gnu.h.
+ * tests/test-c-vazsprintf-gnu.c: New file.
+ * tests/test-c-vazsprintf-gnu.sh: New file, based on
+ tests/test-c-snprintf.sh.
+ * modules/c-vazsprintf-gnu-tests: New file.
+
c-vazsprintf-gnu: New module.
* modules/c-vazsprintf-gnu: New file.
--- /dev/null
+Files:
+tests/test-c-vazsprintf-gnu.c
+tests/test-vazsprintf-gnu.h
+tests/test-c-vazsprintf-gnu.sh
+tests/macros.h
+m4/locale-fr.m4
+m4/codeset.m4
+
+Depends-on:
+setlocale
+
+configure.ac:
+gt_LOCALE_FR
+
+Makefile.am:
+TESTS += test-c-vazsprintf-gnu.sh
+TESTS_ENVIRONMENT += LOCALE_FR='@LOCALE_FR@'
+check_PROGRAMS += test-c-vazsprintf-gnu
+test_c_vazsprintf_gnu_LDADD = $(LDADD) $(SETLOCALE_LIB)
Files:
tests/test-vazsprintf-gnu.c
+tests/test-vazsprintf-gnu.h
tests/macros.h
Depends-on:
--- /dev/null
+/* Test of POSIX and GNU compatible c_vazsprintf() and c_azsprintf() functions.
+ Copyright (C) 2011-2024 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 <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024. */
+
+#include <config.h>
+
+#include "c-vasprintf.h"
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+
+#include "test-vazsprintf-gnu.h"
+
+static ptrdiff_t
+my_c_azsprintf (char **result, const char *format, ...)
+{
+ va_list args;
+ ptrdiff_t ret;
+
+ va_start (args, format);
+ ret = c_vazsprintf (result, format, args);
+ va_end (args);
+ return ret;
+}
+
+static void
+test_c_vazsprintf ()
+{
+ test_function (my_c_azsprintf);
+}
+
+static void
+test_c_azsprintf ()
+{
+ test_function (c_azsprintf);
+}
+
+int
+main (int argc, char *argv[])
+{
+ /* configure should already have checked that the locale is supported. */
+ if (setlocale (LC_ALL, "") == NULL)
+ return 1;
+
+ test_c_vazsprintf ();
+ test_c_azsprintf ();
+
+ return test_exit_status;
+}
--- /dev/null
+#!/bin/sh
+
+# Test in an ISO-8859-1 or ISO-8859-15 locale.
+: "${LOCALE_FR=fr_FR}"
+if test $LOCALE_FR = none; then
+ if test -f /usr/bin/localedef; then
+ echo "Skipping test: no traditional french locale is installed"
+ else
+ echo "Skipping test: no traditional french locale is supported"
+ fi
+ exit 77
+fi
+
+LC_ALL=$LOCALE_FR \
+${CHECKER} ./test-c-vazsprintf-gnu${EXEEXT} 1
#include "macros.h"
-static void
-test_function (ptrdiff_t (*my_azsprintf) (char **, const char *, ...))
-{
- char result[5000];
-
- /* Test the support of the 'B' conversion specifier for binary output of
- integers. */
-
- { /* This test would fail on all platforms other than glibc ≥ 2.35. */
- char *result;
- ptrdiff_t retval =
- my_azsprintf (&result, "%#B %d", 12345, 33, 44, 55);
- ASSERT (result != NULL);
- ASSERT (strcmp (result, "0B11000000111001 33") == 0);
- ASSERT (retval == strlen (result));
- free (result);
- }
-}
+#include "test-vazsprintf-gnu.h"
static ptrdiff_t
my_azsprintf (char **result, const char *format, ...)
--- /dev/null
+/* Test of POSIX and GNU compatible vazsprintf() and azsprintf() functions.
+ Copyright (C) 2007-2024 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 <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2024. */
+
+static void
+test_function (ptrdiff_t (*my_azsprintf) (char **, const char *, ...))
+{
+ /* Test the support of the 'B' conversion specifier for binary output of
+ integers. */
+
+ { /* This test would fail on all platforms other than glibc ≥ 2.35. */
+ char *result;
+ ptrdiff_t retval =
+ my_azsprintf (&result, "%#B %d", 12345, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "0B11000000111001 33") == 0);
+ ASSERT (retval == strlen (result));
+ free (result);
+ }
+}