1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2026-10-24 00:48:56 +03:00
Files
gnulib/tests/test-localeconv.c
Bruno Haible 87b9d1e086 localeconv: Detect invalid writes to the returned struct in some cases.
* lib/locale.in.h (localeconv): Change the return type to
'const struct lconv *'.
(GNULIB_defined_localeconv): New macro.
* lib/localeconv.c (localeconv): Change the return type to
'const struct lconv *'. Change a variable from 'struct lconv *' to
'const struct lconv *'.
* doc/posix-functions/localeconv.texi: Document that Gnulib uses the
return type 'const struct lconv *'.
* NEWS: Mention the change.
* m4/localeconv.m4 (gl_FUNC_LOCALECONV): Change a variable from
'struct lconv *' to 'const struct lconv *'.
* tests/test-localeconv.c (localeconv): Update expected signature.
(main): Change a variable from 'struct lconv *' to
'const struct lconv *'.
* tests/test-locale-h-c++.cc (GNULIB_NAMESPACE::localeconv): Update
expected signature.
2026-06-08 16:06:41 +02:00

77 lines
2.4 KiB
C

/* Test of localeconv() function.
Copyright (C) 2012-2026 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>, 2012. */
#include <config.h>
#include <locale.h>
#include "signature.h"
#if GNULIB_defined_localeconv
SIGNATURE_CHECK (localeconv, const struct lconv *, (void));
#else
SIGNATURE_CHECK (localeconv, struct lconv *, (void));
#endif
#include <limits.h>
#include <string.h>
#include "macros.h"
int
main ()
{
/* Test localeconv() result in the "C" locale. */
{
const struct lconv *l = localeconv ();
ASSERT (streq (l->decimal_point, "."));
ASSERT (streq (l->thousands_sep, ""));
#if !((defined __FreeBSD__ || defined __DragonFly__) || defined __sun || defined __CYGWIN__)
ASSERT (streq (l->grouping, ""));
#endif
ASSERT (streq (l->mon_decimal_point, ""));
ASSERT (streq (l->mon_thousands_sep, ""));
#if !((defined __FreeBSD__ || defined __DragonFly__) || defined __sun || defined __CYGWIN__)
ASSERT (streq (l->mon_grouping, ""));
#endif
ASSERT (streq (l->positive_sign, ""));
ASSERT (streq (l->negative_sign, ""));
ASSERT (streq (l->currency_symbol, ""));
ASSERT (l->frac_digits == CHAR_MAX);
ASSERT (l->p_cs_precedes == CHAR_MAX);
ASSERT (l->p_sign_posn == CHAR_MAX);
ASSERT (l->p_sep_by_space == CHAR_MAX);
ASSERT (l->n_cs_precedes == CHAR_MAX);
ASSERT (l->n_sign_posn == CHAR_MAX);
ASSERT (l->n_sep_by_space == CHAR_MAX);
ASSERT (streq (l->int_curr_symbol, ""));
ASSERT (l->int_frac_digits == CHAR_MAX);
ASSERT (l->int_p_cs_precedes == CHAR_MAX);
ASSERT (l->int_p_sign_posn == CHAR_MAX);
ASSERT (l->int_p_sep_by_space == CHAR_MAX);
ASSERT (l->int_n_cs_precedes == CHAR_MAX);
ASSERT (l->int_n_sign_posn == CHAR_MAX);
ASSERT (l->int_n_sep_by_space == CHAR_MAX);
}
return test_exit_status;
}