root/maint/gnulib/tests/test-nl_langinfo.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of nl_langinfo replacement.
   2    Copyright (C) 2009-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
  18 
  19 #include <config.h>
  20 
  21 #include <langinfo.h>
  22 
  23 #include "signature.h"
  24 SIGNATURE_CHECK (nl_langinfo, char *, (nl_item));
  25 
  26 #include <locale.h>
  27 #include <stdlib.h>
  28 #include <string.h>
  29 
  30 #include "c-strcase.h"
  31 #include "macros.h"
  32 
  33 /* For GCC >= 4.3, silence the warnings
  34      "comparison of unsigned expression >= 0 is always true"
  35    in this file.  */
  36 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
  37 # pragma GCC diagnostic ignored "-Wtype-limits"
  38 #endif
  39 
  40 int
  41 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43   int pass = atoi (argv[1]);
  44   /* pass    locale
  45       0        C
  46       1        traditional French locale
  47       2        French UTF-8 locale
  48    */
  49 
  50   setlocale (LC_ALL, "");
  51 
  52   /* nl_langinfo items of the LC_CTYPE category */
  53   ASSERT (strlen (nl_langinfo (CODESET)) > 0);
  54   if (pass == 2)
  55     {
  56       const char *codeset = nl_langinfo (CODESET);
  57       ASSERT (c_strcasecmp (codeset, "UTF-8") == 0 || c_strcasecmp (codeset, "UTF8") == 0);
  58     }
  59   /* nl_langinfo items of the LC_NUMERIC category */
  60   ASSERT (strlen (nl_langinfo (RADIXCHAR)) > 0);
  61   ASSERT (strlen (nl_langinfo (THOUSEP)) >= 0);
  62   /* nl_langinfo items of the LC_TIME category */
  63   ASSERT (strlen (nl_langinfo (D_T_FMT)) > 0);
  64   ASSERT (strlen (nl_langinfo (D_FMT)) > 0);
  65   ASSERT (strlen (nl_langinfo (T_FMT)) > 0);
  66   ASSERT (strlen (nl_langinfo (T_FMT_AMPM)) >= (pass == 0 ? 1 : 0));
  67   ASSERT (strlen (nl_langinfo (AM_STR)) >= (pass == 0 ? 1 : 0));
  68   ASSERT (strlen (nl_langinfo (PM_STR)) >= (pass == 0 ? 1 : 0));
  69   ASSERT (strlen (nl_langinfo (DAY_1)) > 0);
  70   ASSERT (strlen (nl_langinfo (DAY_2)) > 0);
  71   ASSERT (strlen (nl_langinfo (DAY_3)) > 0);
  72   ASSERT (strlen (nl_langinfo (DAY_4)) > 0);
  73   ASSERT (strlen (nl_langinfo (DAY_5)) > 0);
  74   ASSERT (strlen (nl_langinfo (DAY_6)) > 0);
  75   ASSERT (strlen (nl_langinfo (DAY_7)) > 0);
  76   ASSERT (strlen (nl_langinfo (ABDAY_1)) > 0);
  77   ASSERT (strlen (nl_langinfo (ABDAY_2)) > 0);
  78   ASSERT (strlen (nl_langinfo (ABDAY_3)) > 0);
  79   ASSERT (strlen (nl_langinfo (ABDAY_4)) > 0);
  80   ASSERT (strlen (nl_langinfo (ABDAY_5)) > 0);
  81   ASSERT (strlen (nl_langinfo (ABDAY_6)) > 0);
  82   ASSERT (strlen (nl_langinfo (ABDAY_7)) > 0);
  83   ASSERT (strlen (nl_langinfo (MON_1)) > 0);
  84   ASSERT (strlen (nl_langinfo (MON_2)) > 0);
  85   ASSERT (strlen (nl_langinfo (MON_3)) > 0);
  86   ASSERT (strlen (nl_langinfo (MON_4)) > 0);
  87   ASSERT (strlen (nl_langinfo (MON_5)) > 0);
  88   ASSERT (strlen (nl_langinfo (MON_6)) > 0);
  89   ASSERT (strlen (nl_langinfo (MON_7)) > 0);
  90   ASSERT (strlen (nl_langinfo (MON_8)) > 0);
  91   ASSERT (strlen (nl_langinfo (MON_9)) > 0);
  92   ASSERT (strlen (nl_langinfo (MON_10)) > 0);
  93   ASSERT (strlen (nl_langinfo (MON_11)) > 0);
  94   ASSERT (strlen (nl_langinfo (MON_12)) > 0);
  95   ASSERT (strlen (nl_langinfo (ALTMON_1)) > 0);
  96   ASSERT (strlen (nl_langinfo (ALTMON_2)) > 0);
  97   ASSERT (strlen (nl_langinfo (ALTMON_3)) > 0);
  98   ASSERT (strlen (nl_langinfo (ALTMON_4)) > 0);
  99   ASSERT (strlen (nl_langinfo (ALTMON_5)) > 0);
 100   ASSERT (strlen (nl_langinfo (ALTMON_6)) > 0);
 101   ASSERT (strlen (nl_langinfo (ALTMON_7)) > 0);
 102   ASSERT (strlen (nl_langinfo (ALTMON_8)) > 0);
 103   ASSERT (strlen (nl_langinfo (ALTMON_9)) > 0);
 104   ASSERT (strlen (nl_langinfo (ALTMON_10)) > 0);
 105   ASSERT (strlen (nl_langinfo (ALTMON_11)) > 0);
 106   ASSERT (strlen (nl_langinfo (ALTMON_12)) > 0);
 107   /* In the tested locales, alternate month names and month names ought to be
 108      the same.  */
 109   ASSERT (strcmp (nl_langinfo (ALTMON_1), nl_langinfo (MON_1)) == 0);
 110   ASSERT (strcmp (nl_langinfo (ALTMON_2), nl_langinfo (MON_2)) == 0);
 111   ASSERT (strcmp (nl_langinfo (ALTMON_3), nl_langinfo (MON_3)) == 0);
 112   ASSERT (strcmp (nl_langinfo (ALTMON_4), nl_langinfo (MON_4)) == 0);
 113   ASSERT (strcmp (nl_langinfo (ALTMON_5), nl_langinfo (MON_5)) == 0);
 114   ASSERT (strcmp (nl_langinfo (ALTMON_6), nl_langinfo (MON_6)) == 0);
 115   ASSERT (strcmp (nl_langinfo (ALTMON_7), nl_langinfo (MON_7)) == 0);
 116   ASSERT (strcmp (nl_langinfo (ALTMON_8), nl_langinfo (MON_8)) == 0);
 117   ASSERT (strcmp (nl_langinfo (ALTMON_9), nl_langinfo (MON_9)) == 0);
 118   ASSERT (strcmp (nl_langinfo (ALTMON_10), nl_langinfo (MON_10)) == 0);
 119   ASSERT (strcmp (nl_langinfo (ALTMON_11), nl_langinfo (MON_11)) == 0);
 120   ASSERT (strcmp (nl_langinfo (ALTMON_12), nl_langinfo (MON_12)) == 0);
 121   ASSERT (strlen (nl_langinfo (ABMON_1)) > 0);
 122   ASSERT (strlen (nl_langinfo (ABMON_2)) > 0);
 123   ASSERT (strlen (nl_langinfo (ABMON_3)) > 0);
 124   ASSERT (strlen (nl_langinfo (ABMON_4)) > 0);
 125   ASSERT (strlen (nl_langinfo (ABMON_5)) > 0);
 126   ASSERT (strlen (nl_langinfo (ABMON_6)) > 0);
 127   ASSERT (strlen (nl_langinfo (ABMON_7)) > 0);
 128   ASSERT (strlen (nl_langinfo (ABMON_8)) > 0);
 129   ASSERT (strlen (nl_langinfo (ABMON_9)) > 0);
 130   ASSERT (strlen (nl_langinfo (ABMON_10)) > 0);
 131   ASSERT (strlen (nl_langinfo (ABMON_11)) > 0);
 132   ASSERT (strlen (nl_langinfo (ABMON_12)) > 0);
 133   ASSERT (strlen (nl_langinfo (ERA)) >= 0);
 134   ASSERT (strlen (nl_langinfo (ERA_D_FMT)) >= 0);
 135   ASSERT (strlen (nl_langinfo (ERA_D_T_FMT)) >= 0);
 136   ASSERT (strlen (nl_langinfo (ERA_T_FMT)) >= 0);
 137   ASSERT (nl_langinfo (ALT_DIGITS) != NULL);
 138   /* nl_langinfo items of the LC_MONETARY category */
 139   {
 140     const char *currency = nl_langinfo (CRNCYSTR);
 141     ASSERT (strlen (currency) >= 0);
 142 #if !defined __NetBSD__
 143     if (pass > 0)
 144       ASSERT (strlen (currency) >= 1);
 145 #endif
 146   }
 147   /* nl_langinfo items of the LC_MESSAGES category */
 148   ASSERT (strlen (nl_langinfo (YESEXPR)) > 0);
 149   ASSERT (strlen (nl_langinfo (NOEXPR)) > 0);
 150 
 151   return 0;
 152 }

/* [previous][next][first][last][top][bottom][index][help] */