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