From: Bruno Haible Date: Sat, 20 Oct 2018 14:58:33 +0000 (+0200) Subject: New test intl-thread-1. X-Git-Tag: v0.20~318 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41cab627f5299c5e64ea8ed532d30058821fa482;p=thirdparty%2Fgettext.git New test intl-thread-1. * gettext-tools/tests/intl-thread-1: New file. * gettext-tools/tests/intl-thread-1-prg.c: New file. * gettext-tools/tests/intl-thread-1.po: New file. * gettext-tools/tests/Makefile.am: Update. --- diff --git a/.gitignore b/.gitignore index 471436af6..9a6db83bf 100644 --- a/.gitignore +++ b/.gitignore @@ -677,6 +677,8 @@ autom4te.cache/ /gettext-tools/tests/intl-setlocale-1-prg.exe /gettext-tools/tests/intl-setlocale-2-prg /gettext-tools/tests/intl-setlocale-2-prg.exe +/gettext-tools/tests/intl-thread-1-prg +/gettext-tools/tests/intl-thread-1-prg.exe /gettext-tools/tests/sentence-1-prg /gettext-tools/tests/sentence-1-prg.exe /gettext-tools/tests/testlocale diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 496e91820..5312b6b5b 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -23,6 +23,7 @@ MOSTLYCLEANFILES = core *.stackdump TESTS = gettext-1 gettext-2 \ intl-1 intl-2 intl-3 intl-4 \ intl-setlocale-1 intl-setlocale-2 \ + intl-thread-1 \ gettext-6 gettext-7 gettext-8 \ msgattrib-1 msgattrib-2 msgattrib-3 msgattrib-4 msgattrib-5 \ msgattrib-6 msgattrib-7 msgattrib-8 msgattrib-9 msgattrib-10 \ @@ -165,6 +166,7 @@ EXTRA_DIST += init.sh init.cfg $(TESTS) \ qttest2_de.po qttest2_de.qm qttest2_de.ts \ intl-1.po intl-2-1.po intl-2-2.po intl-4.po \ intl-setlocale-1-1.po intl-setlocale-1-2.po intl-setlocale-2.po \ + intl-thread-1.po \ gettext-6-1.po gettext-6-2.po gettext-7.po \ gettextpo-1.de.po \ xgettext-1 \ @@ -222,7 +224,7 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ LDADD = $(LDADD_@USE_INCLUDED_LIBINTL@) @INTL_MACOSX_LIBS@ LDADD_yes = ../intl/libintl.la @LTLIBTHREAD@ LDADD_no = ../intl/libgnuintl.la @LTLIBTHREAD@ @LTLIBINTL@ -check_PROGRAMS = tstgettext tstngettext testlocale intl-1-prg intl-3-prg intl-4-prg intl-setlocale-1-prg intl-setlocale-2-prg gettext-6-prg gettext-7-prg gettext-8-prg cake fc3 fc4 fc5 gettextpo-1-prg sentence-1-prg +check_PROGRAMS = tstgettext tstngettext testlocale intl-1-prg intl-3-prg intl-4-prg intl-setlocale-1-prg intl-setlocale-2-prg intl-thread-1-prg gettext-6-prg gettext-7-prg gettext-8-prg cake fc3 fc4 fc5 gettextpo-1-prg sentence-1-prg tstgettext_SOURCES = tstgettext.c setlocale.c tstgettext_CFLAGS = -DINSTALLDIR=\".\" tstgettext_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) @@ -240,6 +242,11 @@ intl_setlocale_1_prg_SOURCES = intl-setlocale-1-prg.c intl_setlocale_1_prg_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) intl_setlocale_2_prg_SOURCES = intl-setlocale-2-prg.c intl_setlocale_2_prg_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) +intl_thread_1_prg_SOURCES = intl-thread-1-prg.c +intl_thread_1_prg_CFLAGS = $(intl_thread_1_prg_CFLAGS_@HAVE_NEWLOCALE@) +intl_thread_1_prg_CFLAGS_1 = -DUSE_POSIX_THREADS +intl_thread_1_prg_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) $(intl_thread_1_prg_LDADD_@HAVE_NEWLOCALE@) +intl_thread_1_prg_LDADD_1 = -lpthread gettext_6_prg_SOURCES = gettext-6-prg.c gettext_6_prg_CFLAGS = $(gettext_6_prg_CFLAGS_@HAVE_NEWLOCALE@) gettext_6_prg_CFLAGS_1 = -DUSE_POSIX_THREADS diff --git a/gettext-tools/tests/intl-thread-1 b/gettext-tools/tests/intl-thread-1 new file mode 100755 index 000000000..61d37659e --- /dev/null +++ b/gettext-tools/tests/intl-thread-1 @@ -0,0 +1,53 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test that gettext() in multithreaded applications correctly uses the +# per-thread locale. + +test -d in-th-1 || mkdir in-th-1 +test -d in-th-1/fr || mkdir in-th-1/fr +test -d in-th-1/fr/LC_MESSAGES || mkdir in-th-1/fr/LC_MESSAGES + +: ${MSGFMT=msgfmt} +${MSGFMT} -o in-th-1/fr/LC_MESSAGES/tstthread.mo "$abs_srcdir"/intl-thread-1.po + +: ${LOCALE_FR=fr_FR} +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR != none; then + prepare_locale_ in-th-1/fr in-th-1/$LOCALE_FR + ../intl-thread-1-prg $LOCALE_FR > in-th-1.out + case $? in + 0) ;; + 77) + echo "Skipping test: POSIX per-thread locales not supported" + Exit 77 + ;; + *) + Exit 1 + ;; + esac +fi +if test $LOCALE_FR_UTF8 != none; then + prepare_locale_ in-th-1/fr in-th-1/$LOCALE_FR_UTF8 + ../intl-thread-1-prg $LOCALE_FR_UTF8 > in-th-1.out + case $? in + 0) ;; + 77) + echo "Skipping test: POSIX per-thread locales not supported" + Exit 77 + ;; + *) + Exit 1 + ;; + esac +fi +if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no french locale is installed" + else + echo "Skipping test: no french locale is supported" + fi + Exit 77 +fi + +Exit 0 diff --git a/gettext-tools/tests/intl-thread-1-prg.c b/gettext-tools/tests/intl-thread-1-prg.c new file mode 100644 index 000000000..77d64266f --- /dev/null +++ b/gettext-tools/tests/intl-thread-1-prg.c @@ -0,0 +1,93 @@ +/* Test program, used by the intl-thread-1 test. + Copyright (C) 2005-2007, 2009-2010, 2015-2016, 2018 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2005, 2018. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include + +#if USE_POSIX_THREADS && HAVE_USELOCALE + +#include + +/* Make sure we use the included libintl, not the system's one. */ +#undef _LIBINTL_H +#include "libgnuintl.h" + +/* Name of locale to use in thread1. */ +const char *locale_name_1; + +/* Set to 1 if the program is not behaving correctly. */ +int result; + +void * +thread1_execution (void *arg) +{ + char *s; + + uselocale (newlocale (LC_ALL_MASK, locale_name_1, NULL)); + + /* Here we expect translated output. */ + + s = gettext ("cheese"); + puts (s); + if (strcmp (s, "fromage")) + { + fprintf (stderr, "thread 1 call 1 returned: %s\n", s); + result = 1; + } + + return NULL; +} + +int +main (int argc, char *argv[]) +{ + pthread_t thread1; + + locale_name_1 = argv[1]; + + unsetenv ("LANGUAGE"); + unsetenv ("OUTPUT_CHARSET"); + textdomain ("tstthread"); + bindtextdomain ("tstthread", "in-th-1"); + result = 0; + + if (pthread_create (&thread1, NULL, &thread1_execution, NULL)) + exit (2); + if (pthread_join (thread1, NULL)) + exit (3); + + return result; +} + +#else + +/* This test is not executed. */ + +int +main (void) +{ + return 77; +} + +#endif diff --git a/gettext-tools/tests/intl-thread-1.po b/gettext-tools/tests/intl-thread-1.po new file mode 100644 index 000000000..5fad117b6 --- /dev/null +++ b/gettext-tools/tests/intl-thread-1.po @@ -0,0 +1,8 @@ +msgid "" +msgstr "" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=US-ASCII\n" +"Content-Transfer-Encoding: 7-bit\n" + +msgid "cheese" +msgstr "fromage"