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