Back to index

glibc  2.9
tst-codeset.c
Go to the documentation of this file.
00001 /* Test of bind_textdomain_codeset.
00002    Copyright (C) 2001 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Bruno Haible <haible@clisp.cons.org>, 2001.
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 <libintl.h>
00022 #include <locale.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 int
00028 main (void)
00029 {
00030   char *s;
00031   int result = 0;
00032 
00033   unsetenv ("LANGUAGE");
00034   unsetenv ("OUTPUT_CHARSET");
00035   setlocale (LC_ALL, "de_DE.ISO-8859-1");
00036   textdomain ("codeset");
00037   bindtextdomain ("codeset", OBJPFX "domaindir");
00038 
00039   /* Here we expect output in ISO-8859-1.  */
00040   s = gettext ("cheese");
00041   if (strcmp (s, "K\344se"))
00042     {
00043       printf ("call 1 returned: %s\n", s);
00044       result = 1;
00045     }
00046 
00047   bind_textdomain_codeset ("codeset", "UTF-8");
00048 
00049   /* Here we expect output in UTF-8.  */
00050   s = gettext ("cheese");
00051   if (strcmp (s, "K\303\244se"))
00052     {
00053       printf ("call 2 returned: %s\n", s);
00054       result = 1;
00055     }
00056 
00057   return result;
00058 }