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