(root)/
glibc-2.38/
stdlib/
tst-strtod-nan-locale-main.c
       1  /* Test strtod functions work with all ASCII letters in NAN(...) in
       2     Turkish locales (bug 19266).
       3     Copyright (C) 2015-2023 Free Software Foundation, Inc.
       4     This file is part of the GNU C Library.
       5  
       6     The GNU C Library is free software; you can redistribute it and/or
       7     modify it under the terms of the GNU Lesser General Public
       8     License as published by the Free Software Foundation; either
       9     version 2.1 of the License, or (at your option) any later version.
      10  
      11     The GNU C Library is distributed in the hope that it will be useful,
      12     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14     Lesser General Public License for more details.
      15  
      16     You should have received a copy of the GNU Lesser General Public
      17     License along with the GNU C Library; if not, see
      18     <https://www.gnu.org/licenses/>.  */
      19  
      20  #include <locale.h>
      21  #include <math.h>
      22  #include <stdio.h>
      23  #include <stdlib.h>
      24  #include <wchar.h>
      25  
      26  #include <stdlib/tst-strtod.h>
      27  
      28  #define STR_(X) #X
      29  #define STR(X) STR_(X)
      30  #define FNPFXS STR (FNPFX)
      31  #define CONCAT_(X, Y) X ## Y
      32  #define CONCAT(X, Y) CONCAT_ (X, Y)
      33  #define FNX(FN) CONCAT (FNPFX, FN)
      34  
      35  #define TEST_STRTOD(FSUF, FTYPE, FTOSTR, LSUF, CSUF)			\
      36  static int								\
      37  test_strto ## FSUF (const char * loc, CHAR * s)				\
      38  {									\
      39    CHAR *ep;								\
      40    FTYPE val = FNX (FSUF) (s, &ep);					\
      41    if (isnan (val) && *ep == 0)						\
      42      printf ("PASS: %s: " FNPFXS #FSUF " (" SFMT ")\n", loc, s);		\
      43    else									\
      44      {									\
      45        printf ("FAIL: %s: " FNPFXS #FSUF " (" SFMT ")\n", loc, s);	\
      46        return 1;							        \
      47      }									\
      48    return 0;								\
      49  }
      50  GEN_TEST_STRTOD_FOREACH (TEST_STRTOD)
      51  
      52  static int
      53  test_one_locale (const char *loc)
      54  {
      55    if (setlocale (LC_ALL, loc) == NULL)
      56      {
      57        printf ("setlocale (LC_ALL, \"%s\") failed\n", loc);
      58        return 1;
      59      }
      60    int result = 0;
      61    for (int i = 10; i < 36; i++)
      62      {
      63        CHAR s[7];
      64        s[0] = L_('N');
      65        s[1] = L_('A');
      66        s[2] = L_('N');
      67        s[3] = L_('(');
      68        s[4] = L_('A') + i - 10;
      69        s[5] = L_(')');
      70        s[6] = 0;
      71        result |= STRTOD_TEST_FOREACH (test_strto, loc, s);
      72        s[4] = L_('a') + i - 10;
      73        result |= STRTOD_TEST_FOREACH (test_strto, loc, s);
      74      }
      75    return result;
      76  }
      77  
      78  static int
      79  do_test (void)
      80  {
      81    int result = 0;
      82    result |= test_one_locale ("C");
      83    result |= test_one_locale ("tr_TR.UTF-8");
      84    result |= test_one_locale ("tr_TR.ISO-8859-9");
      85    return result;
      86  }
      87  
      88  #define TEST_FUNCTION do_test ()
      89  #include "../test-skeleton.c"