Back to index

glibc  2.9
tst-ngettext.c
Go to the documentation of this file.
00001 /* Test of the ngettext functions.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <langinfo.h>
00022 #include <libintl.h>
00023 #include <locale.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 
00029 int
00030 main (void)
00031 {
00032   const char *strs[2] = { "singular", "plural" };
00033   unsigned long int i;
00034   int res = 0;
00035 
00036   /* We don't want any translation here.  */
00037   setenv ("LANGUAGE", "C", 1);
00038   unsetenv ("OUTPUT_CHARSET");
00039 
00040   for (i = 0; i < 30; ++i)
00041     {
00042       char *tr;
00043 
00044       tr = ngettext (strs[0], strs[1], i);
00045 #define TEST \
00046       do                                                             \
00047        if (tr != strs[i != 1])                                              \
00048          {                                                           \
00049            if (strcmp (tr, strs[i != 1]) == 0)                              \
00050              printf ("%lu: correct string, wrong pointer (%s)\n", i, tr);    \
00051            else                                                      \
00052              printf ("%lu: wrong result (%s)\n", i, tr);                    \
00053            res = 1;                                                  \
00054          }                                                           \
00055       while (0)
00056       TEST;
00057 
00058       tr = dngettext ("messages", strs[0], strs[1], i);
00059       TEST;
00060 
00061       tr = dcngettext ("messages", strs[0], strs[1], i, LC_MESSAGES);
00062       TEST;
00063     }
00064 
00065   return res;
00066 }