]> Savannah Git Hosting - gnulib.git/commitdiff
c-vazsprintf-gnu: Add tests.
authorBruno Haible <bruno@clisp.org>
Tue, 25 Jun 2024 23:05:05 +0000 (01:05 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 25 Jun 2024 23:05:09 +0000 (01:05 +0200)
* 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.

ChangeLog
modules/c-vazsprintf-gnu-tests [new file with mode: 0644]
modules/vazsprintf-gnu-tests
tests/test-c-vazsprintf-gnu.c [new file with mode: 0644]
tests/test-c-vazsprintf-gnu.sh [new file with mode: 0755]
tests/test-vazsprintf-gnu.c
tests/test-vazsprintf-gnu.h [new file with mode: 0644]

index 1fdcd9b45ce22538f2636303b94bfc0fae789314..359250daf22c80616be3fbea611b51ea65d85286 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 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.
 
diff --git a/modules/c-vazsprintf-gnu-tests b/modules/c-vazsprintf-gnu-tests
new file mode 100644 (file)
index 0000000..a7c5762
--- /dev/null
@@ -0,0 +1,19 @@
+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)
index 33cb15cd568cf7596ab5e4f5bb51c50a59db7f9f..80de638ce8618554efcd3d007ffc000af3cb2b43 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-vazsprintf-gnu.c
+tests/test-vazsprintf-gnu.h
 tests/macros.h
 
 Depends-on:
diff --git a/tests/test-c-vazsprintf-gnu.c b/tests/test-c-vazsprintf-gnu.c
new file mode 100644 (file)
index 0000000..0db9948
--- /dev/null
@@ -0,0 +1,66 @@
+/* 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;
+}
diff --git a/tests/test-c-vazsprintf-gnu.sh b/tests/test-c-vazsprintf-gnu.sh
new file mode 100755 (executable)
index 0000000..1410b4e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/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
index cd31b378ce98a282f5a2c7f99cdfca87179e51c0..f0c015d1fbc7840c14e401f4694f38d4a2b8c8c2 100644 (file)
 
 #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, ...)
diff --git a/tests/test-vazsprintf-gnu.h b/tests/test-vazsprintf-gnu.h
new file mode 100644 (file)
index 0000000..0aba9fa
--- /dev/null
@@ -0,0 +1,34 @@
+/* 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);
+  }
+}