Imported Upstream version 0.18.1.1
[platform/upstream/gettext.git] / gettext-tools / tests / lang-c
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.tmp prog.pot"
56 : ${XGETTEXT=xgettext}
57 ${XGETTEXT} -o prog.tmp --omit-header --no-location -k_ prog.c
58 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
59 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot
60 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
61
62 tmpfiles="$tmpfiles prog.ok"
63 cat <<EOF > prog.ok
64 #, c-format
65 msgid "'Your command, please?', asked the waiter."
66 msgstr ""
67
68 #, c-format
69 msgid "a piece of cake"
70 msgid_plural "%d pieces of cake"
71 msgstr[0] ""
72 msgstr[1] ""
73
74 #, c-format
75 msgid "%s is replaced by %s."
76 msgstr ""
77 EOF
78
79 : ${DIFF=diff}
80 ${DIFF} prog.ok prog.pot || exit 1
81
82 tmpfiles="$tmpfiles fr.po"
83 cat <<\EOF > fr.po
84 msgid ""
85 msgstr ""
86 "Content-Type: text/plain; charset=ISO-8859-1\n"
87 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
88
89 #, c-format
90 msgid "'Your command, please?', asked the waiter."
91 msgstr "«Votre commande, s'il vous plait», dit le garçon."
92
93 # Les gateaux allemands sont les meilleurs du monde.
94 #, c-format
95 msgid "a piece of cake"
96 msgid_plural "%d pieces of cake"
97 msgstr[0] "un morceau de gateau"
98 msgstr[1] "%d morceaux de gateau"
99
100 # Reverse the arguments.
101 #, c-format
102 msgid "%s is replaced by %s."
103 msgstr "%2$s remplace %1$s."
104 EOF
105
106 tmpfiles="$tmpfiles fr.po.tmp fr.po.new"
107 : ${MSGMERGE=msgmerge}
108 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot
109 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
110 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new
111 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
112
113 : ${DIFF=diff}
114 ${DIFF} fr.po fr.po.new || exit 1
115
116 tmpfiles="$tmpfiles fr"
117 test -d fr || mkdir fr
118 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
119
120 : ${MSGFMT=msgfmt}
121 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
122
123 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
124 : ${DIFF=diff}
125 cat <<\EOF > prog.ok
126 «Votre commande, s'il vous plait», dit le garçon.
127 2 morceaux de gateau
128 EUR remplace FF.
129 EOF
130 cat <<\EOF > prog.oku
131 «Votre commande, s'il vous plait», dit le garçon.
132 2 morceaux de gateau
133 EUR remplace FF.
134 EOF
135
136 : ${LOCALE_FR=fr_FR}
137 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
138 if test $LOCALE_FR != none; then
139   LANGUAGE= ./prog $LOCALE_FR 2 > prog.out
140   case $? in
141     0) ${DIFF} prog.ok prog.out || exit 1;;
142     77) LOCALE_FR=none;;
143     *) exit 1;;
144   esac
145 fi
146 if test $LOCALE_FR_UTF8 != none; then
147   LANGUAGE= ./prog $LOCALE_FR_UTF8 2 > prog.out
148   case $? in
149     0) ${DIFF} prog.oku prog.out || exit 1;;
150     77) LOCALE_FR_UTF8=none;;
151     *) exit 1;;
152   esac
153 fi
154 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
155   if test -f /usr/bin/localedef; then
156     echo "Skipping test: no french locale is installed"
157   else
158     echo "Skipping test: no french locale is supported"
159   fi
160   rm -fr $tmpfiles; exit 77
161 fi
162
163 rm -fr $tmpfiles
164
165 exit 0