summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarc Nieper-Wißkirchen <marc@nieper-wisskirchen.de>2020-05-20 13:59:31 +0200
committerBruno Haible <bruno@clisp.org>2020-06-25 21:14:50 +0200
commit39be62df3b9b2453392109f4b6c4bb418e8d175a (patch)
tree330a9a9744072f8651d8e2d108cedcfba7553938 /tests
parent1921016d67285da9460db5cadd5e5ed32a6581d1 (diff)
downloadgnulib-39be62df3b9b2453392109f4b6c4bb418e8d175a.tar.gz
c-dtoastr, c-ldtoastr: new modules
These modules provide the same functionality as the modules dtoastr and ldtoastr except for the formatting taking place in the C locale. * MODULES.html.sh: Add c-dtoastr and c-ldtoastr. * lib/c-dtoastr.c, lib/c-ldtoastr.c: New files. * lib/ftoastr.c: Prefix exported functions when the macro C_LOCALE is defined. Use c_snprintf and c_strtod/c_strtold instead of snprintf and strtod/strtold whhen the macro C_LOCALE is defined. * lib/ftoastr.h: Add prototypes for c_dtoastr and c_ldtoastr. * modules/c-dtoastr, modules/c-dtoastr-tests, modules/c-ldtoastr, modules/c-ldtoastr-tests: New files. * tests/test-c-dtoastr.c, tests/test-c-dtoastr.sh, tests-c-ldtoastr.c tests-c-ldtoastr.sh: New files.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-c-dtoastr.c58
-rw-r--r--tests/test-c-dtoastr.sh15
-rw-r--r--tests/test-c-ldtoastr.c58
-rw-r--r--tests/test-c-ldtoastr.sh15
4 files changed, 146 insertions, 0 deletions
diff --git a/tests/test-c-dtoastr.c b/tests/test-c-dtoastr.c
new file mode 100644
index 0000000000..373e7c4bc7
--- /dev/null
+++ b/tests/test-c-dtoastr.c
@@ -0,0 +1,58 @@
+/* Test of c_dtoastr() function.
+ Copyright (C) 2020 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/>. */
+
+#include <config.h>
+
+#include "ftoastr.h"
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+ /* configure should already have checked that the locale is supported. */
+ if (setlocale (LC_ALL, "") == NULL)
+ return 1;
+
+ /* Test behaviour of snprintf() as a "control group".
+ (We should be running in a locale where ',' is the decimal point.) */
+ {
+ char s[16];
+
+ snprintf (s, sizeof s, "%#.0f", 1.0);
+ if (!strcmp (s, "1."))
+ {
+ /* Skip the test, since we're not in a useful locale for testing. */
+ return 77;
+ }
+ ASSERT (!strcmp (s, "1,"));
+ }
+
+ /* Test behaviour of c_dtoastr().
+ It should always use '.' as the decimal point. */
+ {
+ char buf[DBL_BUFSIZE_BOUND];
+
+ c_dtoastr (buf, sizeof buf, 0, 0, 0.1);
+ ASSERT (!strcmp (buf, "0.1"));
+ }
+
+ return 0;
+}
diff --git a/tests/test-c-dtoastr.sh b/tests/test-c-dtoastr.sh
new file mode 100644
index 0000000000..ef0e459b47
--- /dev/null
+++ b/tests/test-c-dtoastr.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-dtoastr${EXEEXT} 1
diff --git a/tests/test-c-ldtoastr.c b/tests/test-c-ldtoastr.c
new file mode 100644
index 0000000000..140f0c6d8b
--- /dev/null
+++ b/tests/test-c-ldtoastr.c
@@ -0,0 +1,58 @@
+/* Test of c_ldtoastr() function.
+ Copyright (C) 2020 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/>. */
+
+#include <config.h>
+
+#include "ftoastr.h"
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+ /* configure should already have checked that the locale is supported. */
+ if (setlocale (LC_ALL, "") == NULL)
+ return 1;
+
+ /* Test behaviour of snprintf() as a "control group".
+ (We should be running in a locale where ',' is the decimal point.) */
+ {
+ char s[16];
+
+ snprintf (s, sizeof s, "%#.0f", 1.0);
+ if (!strcmp (s, "1."))
+ {
+ /* Skip the test, since we're not in a useful locale for testing. */
+ return 77;
+ }
+ ASSERT (!strcmp (s, "1,"));
+ }
+
+ /* Test behaviour of c_ldtoastr().
+ It should always use '.' as the decimal point. */
+ {
+ char buf[DBL_BUFSIZE_BOUND];
+
+ c_ldtoastr (buf, sizeof buf, 0, 0, 0.1);
+ ASSERT (!strcmp (buf, "0.1"));
+ }
+
+ return 0;
+}
diff --git a/tests/test-c-ldtoastr.sh b/tests/test-c-ldtoastr.sh
new file mode 100644
index 0000000000..ad7a32a14f
--- /dev/null
+++ b/tests/test-c-ldtoastr.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-ldtoastr${EXEEXT} 1