1/* Test program, used by the format-c-5 test. 2 Copyright (C) 2004 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 2, or (at your option) 7 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, write to the Free Software Foundation, 16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 17 18#ifdef HAVE_CONFIG_H 19# include "config.h" 20#endif 21 22#include <locale.h> 23#include <stdio.h> 24#include <stdlib.h> 25#include <string.h> 26#include "xsetenv.h" 27 28/* For %Id to work, we need the real setlocale(), not the fake one. */ 29#if !(__GLIBC__ >= 2) 30# include "setlocale.c" 31#endif 32 33/* Make sure we use the included libintl, not the system's one. */ 34#undef _LIBINTL_H 35#include "libgnuintl.h" 36 37#define _(string) gettext (string) 38 39int 40main (int argc, char *argv[]) 41{ 42 int n = 5; 43 const char *en; 44 const char *s; 45 const char *expected_translation; 46 const char *expected_result; 47 char buf[100]; 48 49 xsetenv ("LC_ALL", argv[1], 1); 50 if (setlocale (LC_ALL, "") == NULL) 51 { 52 fprintf (stderr, "Couldn't set locale.\n"); 53 exit (77); 54 } 55 56 textdomain ("fc5"); 57 bindtextdomain ("fc5", "."); 58 59 s = gettext ("father of %d children"); 60 en = "father of %d children"; 61#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) 62 expected_translation = "Vater von %Id Kindern"; 63 expected_result = "Vater von \xdb\xb5 Kindern"; 64#else 65 expected_translation = "Vater von %d Kindern"; 66 expected_result = "Vater von 5 Kindern"; 67#endif 68 69 if (strcmp (s, en) == 0) 70 { 71 fprintf (stderr, "String untranslated.\n"); 72 exit (1); 73 } 74 if (strcmp (s, expected_translation) != 0) 75 { 76 fprintf (stderr, "String incorrectly translated.\n"); 77 exit (1); 78 } 79 sprintf (buf, s, n); 80 if (strcmp (buf, expected_result) != 0) 81 { 82 fprintf (stderr, "printf of translation wrong.\n"); 83 exit (1); 84 } 85 return 0; 86} 87