From e7c993deb424cf29a3b87ab5fe3ad00350012981 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 26 Jun 2024 01:05:05 +0200 Subject: [PATCH] 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. --- ChangeLog | 11 ++++++ modules/c-vazsprintf-gnu-tests | 19 ++++++++++ modules/vazsprintf-gnu-tests | 1 + tests/test-c-vazsprintf-gnu.c | 66 ++++++++++++++++++++++++++++++++++ tests/test-c-vazsprintf-gnu.sh | 15 ++++++++ tests/test-vazsprintf-gnu.c | 19 +--------- tests/test-vazsprintf-gnu.h | 34 ++++++++++++++++++ 7 files changed, 147 insertions(+), 18 deletions(-) create mode 100644 modules/c-vazsprintf-gnu-tests create mode 100644 tests/test-c-vazsprintf-gnu.c create mode 100755 tests/test-c-vazsprintf-gnu.sh create mode 100644 tests/test-vazsprintf-gnu.h diff --git a/ChangeLog b/ChangeLog index 1fdcd9b45c..359250daf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2024-06-25 Bruno Haible + 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 index 0000000000..a7c5762b9c --- /dev/null +++ b/modules/c-vazsprintf-gnu-tests @@ -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) diff --git a/modules/vazsprintf-gnu-tests b/modules/vazsprintf-gnu-tests index 33cb15cd56..80de638ce8 100644 --- a/modules/vazsprintf-gnu-tests +++ b/modules/vazsprintf-gnu-tests @@ -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 index 0000000000..0db9948d06 --- /dev/null +++ b/tests/test-c-vazsprintf-gnu.c @@ -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 . */ + +/* Written by Bruno Haible , 2024. */ + +#include + +#include "c-vasprintf.h" + +#include +#include +#include + +#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 index 0000000000..1410b4e51e --- /dev/null +++ b/tests/test-c-vazsprintf-gnu.sh @@ -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 diff --git a/tests/test-vazsprintf-gnu.c b/tests/test-vazsprintf-gnu.c index cd31b378ce..f0c015d1fb 100644 --- a/tests/test-vazsprintf-gnu.c +++ b/tests/test-vazsprintf-gnu.c @@ -31,24 +31,7 @@ #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 index 0000000000..0aba9faa6a --- /dev/null +++ b/tests/test-vazsprintf-gnu.h @@ -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 . */ + +/* Written by Bruno Haible , 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); + } +} -- 2.39.5