• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 g++.
7
8# This test fails if the gettext package was configured with --disable-nls,
9# because in this case the gettext-runtime/intl/ directory does not produce
10# a <libintl.h> header file.
11
12# Test whether a C++ compiler is found and libasprintf is built.
13test "${CXX}" != "no" || {
14  echo "Skipping test: no C++ compiler found"
15  Exit 77
16}
17test "${TESTLIBASPRINTF}" = yes || {
18  echo "Skipping test: configured with --disable-libasprintf"
19  Exit 77
20}
21
22cat <<\EOF > prog.cc
23#include "config.h"
24
25/* Avoid deprecation warnings from g++ 3.1 or newer.  */
26#if (defined __GNUG__ && defined __DEPRECATED) || defined _MSC_VER
27# include <iostream>
28using namespace std;
29#else
30# include <iostream.h>
31#endif
32
33#include <libintl.h>
34#include <locale.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include "xsetenv.h"
38#include "autosprintf.h"
39using gnu::autosprintf;
40#define _(string) gettext (string)
41
42int main (int argc, char *argv[])
43{
44  int n = atoi (argv[2]);
45
46  xsetenv ("LC_ALL", argv[1], 1);
47  if (setlocale (LC_ALL, "") == NULL)
48    // Couldn't set locale.
49    exit (77);
50
51  textdomain ("prog");
52  bindtextdomain ("prog", ".");
53
54  cout << _("'Your command, please?', asked the waiter.") << endl;
55
56  cout << autosprintf (ngettext ("a piece of cake", "%d pieces of cake", n), n)
57       << endl;
58
59  cout << autosprintf (_("%s is replaced by %s."), "FF", "EUR") << endl;
60}
61EOF
62
63# Compile in two steps from .cc to .o and from .o to 'prog'. This way,
64# relinking is faster because doesn't need to redo the first step.
65# Put the -I flags before ${CXXFLAGS} ${CPPFLAGS}, to make sure that libintl.h
66# is found in the build directory, regardless of -I options present in
67# ${CXXFLAGS} or ${CPPFLAGS}.
68${CXX} -I../.. -I../../../gettext-runtime/libasprintf -I"$abs_top_srcdir"/gnulib-lib -I../../intl ${CXXFLAGS} ${CPPFLAGS} -c prog.cc \
69  || Exit 1
70# Remove the -Wl,--disable-auto-import option here that is added by
71# woe32-dll.m4. Cygwin 1.7.2 does not support it in C++ mode: It gives
72# a link error about 'std::cout'.
73: ${CONFIG_SHELL=${SHELL-/bin/sh}}
74${CONFIG_SHELL} "$top_builddir"/libtool --quiet --tag=CXX --mode=link \
75                ${CXX} ${CXXFLAGS} `echo "X ${LDFLAGS} " | sed -e 's/^X//' -e 's/ -Wl,--disable-auto-import / /'` -o prog prog.${OBJEXT} \
76                ../../../gettext-runtime/libasprintf/libasprintf.la \
77                ../../gnulib-lib/libgettextlib.la ${LTLIBINTL} \
78		|| Exit 1
79
80: ${XGETTEXT=xgettext}
81${XGETTEXT} -o prog.tmp --omit-header --no-location -k_ prog.cc || Exit 1
82LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1
83
84cat <<EOF > prog.ok
85msgid "'Your command, please?', asked the waiter."
86msgstr ""
87
88#, c-format
89msgid "a piece of cake"
90msgid_plural "%d pieces of cake"
91msgstr[0] ""
92msgstr[1] ""
93
94#, c-format
95msgid "%s is replaced by %s."
96msgstr ""
97EOF
98
99: ${DIFF=diff}
100${DIFF} prog.ok prog.pot || Exit 1
101
102cat <<\EOF > fr.po
103msgid ""
104msgstr ""
105"Content-Type: text/plain; charset=ISO-8859-1\n"
106"Plural-Forms: nplurals=2; plural=(n > 1);\n"
107
108msgid "'Your command, please?', asked the waiter."
109msgstr "�Votre commande, s'il vous plait�, dit le gar�on."
110
111# Les gateaux allemands sont les meilleurs du monde.
112#, c-format
113msgid "a piece of cake"
114msgid_plural "%d pieces of cake"
115msgstr[0] "un morceau de gateau"
116msgstr[1] "%d morceaux de gateau"
117
118# Reverse the arguments.
119#, c-format
120msgid "%s is replaced by %s."
121msgstr "%2$s remplace %1$s."
122EOF
123
124: ${MSGMERGE=msgmerge}
125${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1
126LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1
127
128: ${DIFF=diff}
129${DIFF} fr.po fr.po.new || Exit 1
130
131test -d fr || mkdir fr
132test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
133
134: ${MSGFMT=msgfmt}
135${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
136
137: ${DIFF=diff}
138cat <<\EOF > prog.ok
139Votre commande, s'il vous plait�, dit le gar�on.
1402 morceaux de gateau
141EUR remplace FF.
142EOF
143cat <<\EOF > prog.oku
144«Votre commande, s'il vous plait», dit le garçon.
1452 morceaux de gateau
146EUR remplace FF.
147EOF
148
149: ${LOCALE_FR=fr_FR}
150: ${LOCALE_FR_UTF8=fr_FR.UTF-8}
151if test $LOCALE_FR != none; then
152  prepare_locale_ fr $LOCALE_FR
153  LANGUAGE= ./prog $LOCALE_FR 2 > prog.tmp
154  case $? in
155    0) case "$host_os" in
156         mingw*) LC_ALL=C tr -d '\r' < prog.tmp > prog.out || Exit 1 ;;
157         *) cp prog.tmp prog.out || Exit 1 ;;
158       esac
159       ${DIFF} prog.ok prog.out || Exit 1;;
160    77) LOCALE_FR=none;;
161    *) Exit 1;;
162  esac
163fi
164if test $LOCALE_FR_UTF8 != none; then
165  prepare_locale_ fr $LOCALE_FR_UTF8
166  LANGUAGE= ./prog $LOCALE_FR_UTF8 2 > prog.tmp
167  case $? in
168    0) case "$host_os" in
169         mingw*) LC_ALL=C tr -d '\r' < prog.tmp > prog.out || Exit 1 ;;
170         *) cp prog.tmp prog.out || Exit 1 ;;
171       esac
172       ${DIFF} prog.oku prog.out || Exit 1;;
173    77) LOCALE_FR_UTF8=none;;
174    *) Exit 1;;
175  esac
176fi
177if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
178  if test -f /usr/bin/localedef; then
179    echo "Skipping test: no french locale is installed"
180  else
181    echo "Skipping test: no french locale is supported"
182  fi
183  Exit 77
184fi
185
186Exit 0
187