Home | History | Annotate | Line # | Download | only in tests
lang-c revision 1.1
      1 #! /bin/sh
      2 
      3 # Test of gettext facilities in the C language.
      4 # Assumes an fr_FR locale is installed.
      5 # Assumes the following packages are installed: gcc.
      6 
      7 tmpfiles=""
      8 trap 'rm -fr $tmpfiles' 1 2 3 15
      9 
     10 tmpfiles="$tmpfiles prog.c"
     11 cat <<\EOF > prog.c
     12 #include "config.h"
     13 #include <libintl.h>
     14 #include <locale.h>
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 #include "xsetenv.h"
     18 #define _(string) gettext (string)
     19 
     20 int main (int argc, char *argv[])
     21 {
     22   int n = atoi (argv[2]);
     23 
     24   xsetenv ("LC_ALL", argv[1], 1);
     25   if (setlocale (LC_ALL, "") == NULL)
     26     /* Couldn't set locale.  */
     27     exit (77);
     28 
     29   textdomain ("prog");
     30   bindtextdomain ("prog", ".");
     31 
     32   printf (_("'Your command, please?', asked the waiter."));
     33   printf ("\n");
     34 
     35   printf (ngettext ("a piece of cake", "%d pieces of cake", n), n);
     36   printf ("\n");
     37 
     38   printf (_("%s is replaced by %s."), "FF", "EUR");
     39   printf ("\n");
     40 
     41   exit (0);
     42 }
     43 EOF
     44 
     45 # Variable needed by LTLIBINTL.
     46 top_builddir=..
     47 
     48 tmpfiles="$tmpfiles prog.${OBJEXT} prog${EXEEXT}"
     49 # Put the -I flags before ${CFLAGS} ${CPPFLAGS}, to make sure that libintl.h
     50 # is found in the build directory, regardless of -I options present in
     51 # ${CFLAGS} or ${CPPFLAGS}.
     52 ${LIBTOOL} --quiet --mode=link ${CC} -I.. -I$top_srcdir/gnulib-lib ../gnulib-lib/libgettextlib.la -I../intl ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -o prog prog.c ${LTLIBINTL} \
     53   || exit 1
     54 
     55 tmpfiles="$tmpfiles prog.pot"
     56 : ${XGETTEXT=xgettext}
     57 ${XGETTEXT} -o prog.pot --omit-header --no-location -k_ prog.c
     58 
     59 tmpfiles="$tmpfiles prog.ok"
     60 cat <<EOF > prog.ok
     61 #, c-format
     62 msgid "'Your command, please?', asked the waiter."
     63 msgstr ""
     64 
     65 #, c-format
     66 msgid "a piece of cake"
     67 msgid_plural "%d pieces of cake"
     68 msgstr[0] ""
     69 msgstr[1] ""
     70 
     71 #, c-format
     72 msgid "%s is replaced by %s."
     73 msgstr ""
     74 EOF
     75 
     76 : ${DIFF=diff}
     77 ${DIFF} prog.ok prog.pot || exit 1
     78 
     79 tmpfiles="$tmpfiles fr.po"
     80 cat <<\EOF > fr.po
     81 msgid ""
     82 msgstr ""
     83 "Content-Type: text/plain; charset=ISO-8859-1\n"
     84 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
     85 
     86 #, c-format
     87 msgid "'Your command, please?', asked the waiter."
     88 msgstr "Votre commande, s'il vous plait, dit le garon."
     89 
     90 # Les gateaux allemands sont les meilleurs du monde.
     91 #, c-format
     92 msgid "a piece of cake"
     93 msgid_plural "%d pieces of cake"
     94 msgstr[0] "un morceau de gateau"
     95 msgstr[1] "%d morceaux de gateau"
     96 
     97 # Reverse the arguments.
     98 #, c-format
     99 msgid "%s is replaced by %s."
    100 msgstr "%2$s remplace %1$s."
    101 EOF
    102 
    103 tmpfiles="$tmpfiles fr.po.new"
    104 : ${MSGMERGE=msgmerge}
    105 ${MSGMERGE} -q -o fr.po.new fr.po prog.pot
    106 
    107 : ${DIFF=diff}
    108 ${DIFF} fr.po fr.po.new || exit 1
    109 
    110 tmpfiles="$tmpfiles fr"
    111 test -d fr || mkdir fr
    112 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
    113 
    114 : ${MSGFMT=msgfmt}
    115 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
    116 
    117 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
    118 : ${DIFF=diff}
    119 cat <<\EOF > prog.ok
    120 Votre commande, s'il vous plait, dit le garon.
    121 2 morceaux de gateau
    122 EUR remplace FF.
    123 EOF
    124 cat <<\EOF > prog.oku
    125 Votre commande, s'il vous plait, dit le garon.
    126 2 morceaux de gateau
    127 EUR remplace FF.
    128 EOF
    129 
    130 : ${LOCALE_FR=fr_FR}
    131 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
    132 if test $LOCALE_FR != none; then
    133   LANGUAGE= ./prog $LOCALE_FR 2 > prog.out
    134   case $? in
    135     0) ${DIFF} prog.ok prog.out || exit 1;;
    136     77) LOCALE_FR=none;;
    137     *) exit 1;;
    138   esac
    139 fi
    140 if test $LOCALE_FR_UTF8 != none; then
    141   LANGUAGE= ./prog $LOCALE_FR_UTF8 2 > prog.out
    142   case $? in
    143     0) ${DIFF} prog.oku prog.out || exit 1;;
    144     77) LOCALE_FR_UTF8=none;;
    145     *) exit 1;;
    146   esac
    147 fi
    148 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
    149   if test -f /usr/bin/localedef; then
    150     echo "Skipping test: no french locale is installed"
    151   else
    152     echo "Skipping test: no french locale is supported"
    153   fi
    154   rm -fr $tmpfiles; exit 77
    155 fi
    156 
    157 rm -fr $tmpfiles
    158 
    159 exit 0
    160