Imported Upstream version 0.18.1.1
[platform/upstream/gettext.git] / gettext-tools / tests / lang-csharp
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: pnet, pnetlib.
6
7 # Note: This test fails with mono-0.28 because the CultureInfo.Parent pointers
8 # are wrong for locales containing a language and a territory. This is fixed
9 # in mono-0.29.
10
11 tmpfiles=""
12 trap 'rm -fr $tmpfiles' 1 2 3 15
13
14 # Test whether we can build and test C# programs.
15 test "${CSHARP_CHOICE}" != no || {
16   echo "Skipping test: configured with --disable-csharp"
17   exit 77
18 }
19 test "${BUILDCSHARP}" = yes || {
20   echo "Skipping test: C# compiler not found"
21   exit 77
22 }
23 test "${TESTCSHARP}" = yes || {
24   echo "Skipping test: C# engine not found"
25   exit 77
26 }
27
28 tmpfiles="$tmpfiles program.cs"
29 cat <<\EOF > program.cs
30 using System;
31 using GNU.Gettext;
32 class Program {
33   static void Main (String[] args) {
34     #if __MonoCS__
35     // Some systems don't set CurrentCulture and CurrentUICulture as specified
36     // by LC_ALL. So set it by hand.
37     System.Threading.Thread.CurrentThread.CurrentCulture =
38     System.Threading.Thread.CurrentThread.CurrentUICulture =
39       new System.Globalization.CultureInfo("fr-FR");
40     #endif
41     int n = Int32.Parse(args[0]);
42     GettextResourceManager catalog = new GettextResourceManager("prog");
43     Console.WriteLine(catalog.GetString("'Your command, please?', asked the waiter."));
44     Console.WriteLine(String.Format(catalog.GetPluralString("a piece of cake","{0} pieces of cake",n), n));
45     Console.WriteLine(String.Format(catalog.GetString("{0} is replaced by {1}."), "FF", "EUR"));
46     Console.WriteLine(String.Format(catalog.GetParticularPluralString("++","a piece of cake","{0} pieces of cake",n), n));
47     Console.WriteLine(String.Format(catalog.GetParticularString("++","{0} is replaced by {1}."), "FF", "EUR"));
48   }
49 }
50 EOF
51
52 tmpfiles="$tmpfiles program.exe"
53 : ${CSHARPCOMP="/bin/sh ../csharpcomp.sh"}
54 ${CSHARPCOMP} -o program.exe -L ../../gettext-runtime/intl-csharp -l GNU.Gettext program.cs || exit 1
55
56 tmpfiles="$tmpfiles prog.tmp prog.pot"
57 : ${XGETTEXT=xgettext}
58 ${XGETTEXT} -o prog.tmp --omit-header --no-location program.cs
59 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
60 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot
61 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
62
63 tmpfiles="$tmpfiles prog.ok"
64 cat <<EOF > prog.ok
65 msgid "'Your command, please?', asked the waiter."
66 msgstr ""
67
68 #, csharp-format
69 msgid "a piece of cake"
70 msgid_plural "{0} pieces of cake"
71 msgstr[0] ""
72 msgstr[1] ""
73
74 #, csharp-format
75 msgid "{0} is replaced by {1}."
76 msgstr ""
77
78 #, csharp-format
79 msgctxt "++"
80 msgid "a piece of cake"
81 msgid_plural "{0} pieces of cake"
82 msgstr[0] ""
83 msgstr[1] ""
84
85 #, csharp-format
86 msgctxt "++"
87 msgid "{0} is replaced by {1}."
88 msgstr ""
89 EOF
90
91 : ${DIFF=diff}
92 ${DIFF} prog.ok prog.pot || exit 1
93
94 tmpfiles="$tmpfiles fr.po"
95 cat <<\EOF > fr.po
96 msgid ""
97 msgstr ""
98 "Content-Type: text/plain; charset=ISO-8859-1\n"
99 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
100
101 msgid "'Your command, please?', asked the waiter."
102 msgstr "«Votre commande, s'il vous plait», dit le garçon."
103
104 # Les gateaux allemands sont les meilleurs du monde.
105 #, csharp-format
106 msgid "a piece of cake"
107 msgid_plural "{0} pieces of cake"
108 msgstr[0] "un morceau de gateau"
109 msgstr[1] "{0} morceaux de gateau"
110
111 # Reverse the arguments.
112 #, csharp-format
113 msgid "{0} is replaced by {1}."
114 msgstr "{1} remplace {0}."
115
116 # Euphemistic formulation.
117 #, csharp-format
118 msgctxt "++"
119 msgid "a piece of cake"
120 msgid_plural "{0} pieces of cake"
121 msgstr[0] "un morceau de gateau succulent"
122 msgstr[1] "{0} morceaux de gateau succulent"
123
124 # Euphemistic formulation.
125 #, csharp-format
126 msgctxt "++"
127 msgid "{0} is replaced by {1}."
128 msgstr "Le nouveau {1} remplace le vieux {0}."
129 EOF
130
131 tmpfiles="$tmpfiles fr.po.tmp fr.po.new"
132 : ${MSGMERGE=msgmerge}
133 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot
134 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
135 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new
136 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
137
138 : ${DIFF=diff}
139 ${DIFF} fr.po fr.po.new || exit 1
140
141 tmpfiles="$tmpfiles fr/prog.dll"
142 : ${MSGFMT=msgfmt}
143 GETTEXTCSHARPLIBDIR=../../gettext-runtime/intl-csharp \
144 ${MSGFMT} --csharp -d . -r prog -l fr fr.po || exit 1
145
146 # Test which of the fr_FR locales are installed.
147 : ${LOCALE_FR=fr_FR}
148 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
149 if test $LOCALE_FR != none; then
150   LC_ALL=$LOCALE_FR ./testlocale
151   case $? in
152     0) ;;
153     77) LOCALE_FR=none;;
154     *) exit 1;;
155   esac
156 fi
157 if test $LOCALE_FR_UTF8 != none; then
158   LC_ALL=$LOCALE_FR_UTF8 ./testlocale
159   case $? in
160     0) ;;
161     77) LOCALE_FR_UTF8=none;;
162     *) exit 1;;
163   esac
164 fi
165 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
166   if test -f /usr/bin/localedef; then
167     echo "Skipping test: no french locale is installed"
168   else
169     echo "Skipping test: no french locale is supported"
170   fi
171   rm -fr $tmpfiles; exit 77
172 fi
173
174 tmpfiles="$tmpfiles prog.ok prog.oku prog.out"
175 : ${DIFF=diff}
176 cat <<\EOF > prog.ok
177 «Votre commande, s'il vous plait», dit le garçon.
178 2 morceaux de gateau
179 EUR remplace FF.
180 2 morceaux de gateau succulent
181 Le nouveau EUR remplace le vieux FF.
182 EOF
183 cat <<\EOF > prog.oku
184 «Votre commande, s'il vous plait», dit le garçon.
185 2 morceaux de gateau
186 EUR remplace FF.
187 2 morceaux de gateau succulent
188 Le nouveau EUR remplace le vieux FF.
189 EOF
190
191 : ${LOCALE_FR=fr_FR}
192 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
193 : ${CSHARPEXEC="/bin/sh ../csharpexec.sh"}
194 if test $LOCALE_FR != none; then
195   LANGUAGE= LC_ALL=$LOCALE_FR ${CSHARPEXEC} -L ../../gettext-runtime/intl-csharp program.exe 2 > prog.out || exit 1
196   ${DIFF} prog.ok prog.out || exit 1
197 fi
198 if test $LOCALE_FR_UTF8 != none; then
199   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 ${CSHARPEXEC} -L ../../gettext-runtime/intl-csharp program.exe 2 > prog.out || exit 1
200   ${DIFF} prog.oku prog.out || exit 1
201 fi
202
203 rm -fr $tmpfiles
204
205 exit 0