Use libc_hidden_* for fputs (bug 15105).
[glibc.git] / stdlib / tst-strfrom-locale.c
blobe9e5b959ea4c5a78bc1697cc559e49b2e7bdff33
1 /* Tests for strfromf, strfromd, strfroml functions.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include "tst-strfrom.h"
21 static const struct test tests[] = {
22 TEST ("12,345000", "%f", 50, 9, 12.345),
23 TEST ("9,999", "%.3f", 50, 5, 9.999),
24 TEST ("0,125000", "%f", 50, 8, .125),
25 TEST ("0,000000", "%f", 50, 8, .0),
26 TEST ("0", "%g", 50, 1, .0),
27 TEST ("9,900000", "%f", 50, 8, 9.9),
28 TEST ("9,1", "%.5f", 4, 7, 9.123456),
29 TEST ("9,91235", "%g", 50, 7, 9.91234567812345678),
30 TEST ("79,8765", "%G", 50, 7, 79.8765432111),
31 TEST ("79,9", "%.3g", 50, 4, 79.8765432111),
32 TEST ("1,000000e+38", "%e", 50, 12, 1e+38),
33 TEST ("1,000000e+38", "%e", 50, 12, 1e38),
34 TEST ("-1,000000e-37", "%e", 50, 13, -1e-37),
35 TEST ("1,000000e-37", "%e", 50, 12, 0.00000001e-29),
36 TEST ("1,000000e-37", "%e", 50, 12, 1.000000e-37),
37 TEST ("5,900000e-16", "%e", 50, 12, 5.9e-16),
38 TEST ("1,234500e+20", "%e", 50, 12, 12.345e19),
39 TEST ("1,000000e+05", "%e", 50, 12, 1e5),
40 TEST ("-NAN", "%G", 50, 4, -NAN_),
41 TEST ("-inf", "%g", 50, 4, -INF),
42 TEST ("inf", "%g", 50, 3, INF)
44 /* Tests with buffer size small. */
45 static const struct test stest[] = {
46 TEST ("1234", "%g", 5, 7, 12345.345),
47 TEST ("0,12", "%f", 5, 8, .125),
48 TEST ("9,99", "%.3f", 5, 5, 9.999),
49 TEST ("100", "%g", 5, 3, 1e2)
51 /* Hexadecimal tests. */
52 static const struct htests htest[] = {
53 HTEST ("%a", { "0x1,ffp+6", "0x3,fep+5", "0x7,fcp+4", "0xf,f8p+3" },
54 0x1.ffp+6),
55 HTEST ("%a", { "0x1,88p+4", "0x3,1p+3", "0x6,2p+2", "0xc,4p+1" },
56 0x1.88p+4),
57 HTEST ("%A", { "-0X1,88P+5", "-0X3,1P+4", "-0X6,2P+3", "-0XC,4P+2" },
58 -0x1.88p+5),
59 HTEST ("%a", { "0x1,44p+10", "0x2,88p+9", "0x5,1p+8", "0xa,2p+7" },
60 0x1.44p+10),
61 HTEST ("%a", { "0x1p-10", "0x2p-11", "0x4p-12", "0x8p-13" },
62 0x0.0040p+0),
63 HTEST ("%a", { "0x1,4p+3", "0x2,8p+2", "0x5p+1", "0xap+0" },
64 10.0)
67 GEN_TEST_STRTOD_FOREACH (TEST_STRFROM)
69 static int
70 test_locale (const char *locale)
72 printf ("Testing in locale: %s\n", locale);
73 if (setlocale (LC_ALL, locale) == NULL)
75 printf ("Cannot set locale %s\n", locale);
77 return STRTOD_TEST_FOREACH (test_);
80 static int
81 do_test (void)
83 int result = 0;
84 result += test_locale ("de_DE.UTF-8");
85 result += test_locale ("tr_TR.ISO-8859-9");
86 result += test_locale ("tr_TR.UTF-8");
87 return result;
90 #define TEST_FUNCTION do_test ()
91 #include "../test-skeleton.c"