From 354cf55bb0e8e70d4c9f40c91ae3f89e7922da01 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 20 May 2025 17:53:36 +0200 Subject: Add some wxWidgets-based i18n tests. --- run/tests | 12 ++- run/tests.bat | 2 + test/wscript | 1 + test/wx/i18n_test.cc | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/wx/wscript | 38 ++++++++++ 5 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 test/wx/i18n_test.cc create mode 100644 test/wx/wscript diff --git a/run/tests b/run/tests index 67b190661..9151afb4d 100755 --- a/run/tests +++ b/run/tests @@ -123,5 +123,15 @@ elif [ "$type" == "helgrind" ]; then valgrind --tool="helgrind" build/test/unit-tests $* else ulimit -c unlimited - build/test/lib/unit-tests --catch_system_errors=no $* + if [ "$(uname)" == "Darwin" ]; then + if [ "$(defaults read -g AppleLocale)" == "en_DE" ]; then + build/test/lib/unit-tests --catch_system_errors=no $* + build/test/wx/unit-tests --catch_system_errors=no $* -t !i18n_test_de_de + else + build/test/wx/unit-tests --catch_system_errors=no $* -t i18n_test_de_de + fi + else + build/test/lib/unit-tests --catch_system_errors=no $* + build/test/wx/unit-tests --catch_system_errors=no $* + fi fi diff --git a/run/tests.bat b/run/tests.bat index a50335307..f09b3c4a0 100644 --- a/run/tests.bat +++ b/run/tests.bat @@ -8,10 +8,12 @@ if "%1" == "2057" ( REM en-DE set PATH=%PATH%;c:\users\ci\bin_v2.18.x;c:\users\ci\workspace\dcpomatic\bin;c:\users\ci\workspace\dcpomatic\lib build\test\lib\unit-tests.exe --log_level=test_suite %2 %3 -t !i18n_test_de_de + build\test\wx\unit-tests.exe --log_level=test_suite %2 %3 -t !i18n_test_de_de ) else ( REM Presumably de-DE set PATH=%PATH%;c:\users\ci-de\bin_v2.18.x;c:\users\ci-de\workspace\dcpomatic\bin;c:\users\ci-de\workspace\dcpomatic\lib build\test\lib\unit-tests.exe --log_level=test_suite -t i18n_test_de_de + build\test\wx\unit-tests.exe --log_level=test_suite -t i18n_test_de_de ) diff --git a/test/wscript b/test/wscript index edb2a4b45..23286751e 100644 --- a/test/wscript +++ b/test/wscript @@ -34,6 +34,7 @@ def configure(conf): def build(bld): bld.recurse('lib') + bld.recurse('wx') def pot(bld): bld.recurse('lib') diff --git a/test/wx/i18n_test.cc b/test/wx/i18n_test.cc new file mode 100644 index 000000000..8527e63c2 --- /dev/null +++ b/test/wx/i18n_test.cc @@ -0,0 +1,207 @@ +/* + Copyright (C) 2025 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic 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 2 of the License, or + (at your option) any later version. + + DCP-o-matic 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 DCP-o-matic. If not, see . + +*/ + + +#include "../test.h" +#include "wx/wx_util.h" +#include "lib/util.h" +#include +#include +#include +#include +#include + + +using std::string; + + +#define translation_en BOOST_CHECK_EQUAL(_("3D right only"), char_to_wx("3D right only")); +#define translation_de BOOST_CHECK_EQUAL(_("3D right only"), char_to_wx("3D nur rechts")); +#define fmt_en BOOST_CHECK_EQUAL(fmt::to_string("1.23"), "1.23"); +#define numbers_en BOOST_CHECK_EQUAL(dcp::locale_convert(1.23), "1.23"); +#define numbers_de BOOST_CHECK_EQUAL(dcp::locale_convert(1.23), "1,23"); + + +static void restore() +{ + dcpomatic_setup_c_and_gettext_i18n("C"); + tell_gettext_about_language_change(); +} + + +#ifdef DCPOMATIC_LINUX +BOOST_AUTO_TEST_CASE(i18n_test) +{ + wxApp app; + + /* cscript sets LC_ALL=C. Undo this first */ + unsetenv("LC_ALL"); + dcp::ScopeGuard sg = []() { restore(); }; + + /* English language, German numbers */ + putenv(strdup("LANG=en_GB.UTF-8")); + putenv(strdup("LC_NUMERIC=de_DE.UTF-8")); + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_en + numbers_de + + /* German language, German numbers */ + putenv(strdup("LANG=de_DE.UTF-8")); + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_de + numbers_de + + /* German language, German numbers, forced to English */ + ConfigRestorer cr; + Config::instance()->set_language("en_GB"); + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_en + numbers_de +} +#endif + + +#ifdef DCPOMATIC_OSX +/* This test is only run on a user account set to en_DE */ +BOOST_AUTO_TEST_CASE(i18n_test_en_de) +{ + wxApp app; + + /* cscript sets LC_ALL=C. Undo this first */ + unsetenv("LC_ALL"); + dcp::ScopeGuard sg = []() { restore(); }; + + /* As far as I can see this simulates the environment when loading DoM direct + * from the .app + */ + putenv(strdup("LANG=\"\"")); + + /* English language, German numbers */ + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_en + numbers_de +} + + +/* This test is only run on a user account set to de_DE */ +BOOST_AUTO_TEST_CASE(i18n_test_de_de) +{ + wxApp app; + + /* SSHing in brings the client's LANG and LC_*, so reset those here */ + putenv(strdup("LANG=de_DE.UTF-8")); + putenv(strdup("LC_NUMERIC=de_DE.UTF-8")); + + /* German language, German numbers */ + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_de + numbers_de + + /* German language, German numbers, forced to English */ + ConfigRestorer cr; + Config::instance()->set_language("en_GB"); + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_en + numbers_de +} +#endif + + + +#ifdef DCPOMATIC_WINDOWS +/* This test is only run on a user account set to en_DE */ +BOOST_AUTO_TEST_CASE(i18n_test_en_de) +{ + wxApp app; + + override_mo_path = boost::filesystem::current_path().parent_path().parent_path() / "share" / "locale"; + + /* cscript sets LC_ALL=C. Undo this first */ + putenv("LC_ALL="); + dcp::ScopeGuard sg = []() { restore(); }; + + /* English language, German numbers */ + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_en + numbers_de + + /* English language, German numbers, forced to German */ + ConfigRestorer cr; + Config::instance()->set_language("de_DE"); + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_de + numbers_de +} + + +/* This test is only run on a user account set to de_DE */ +BOOST_AUTO_TEST_CASE(i18n_test_de_de) +{ + wxApp app; + + override_mo_path = boost::filesystem::current_path().parent_path().parent_path() / "share" / "locale"; + + /* cscript sets LC_ALL=C. Undo this first */ + putenv("LC_ALL="); + dcp::ScopeGuard sg = []() { restore(); }; + + /* German language, German numbers */ + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_de + numbers_de + + /* German language, German numbers, forced back to English */ + ConfigRestorer cr; + Config::instance()->set_language("en_GB"); + dcpomatic_setup_i18n(); + tell_gettext_about_language_change(); + fmt_en + + translation_en + numbers_de +} +#endif diff --git a/test/wx/wscript b/test/wx/wscript new file mode 100644 index 000000000..b64ce4fe1 --- /dev/null +++ b/test/wx/wscript @@ -0,0 +1,38 @@ +# +# Copyright (C) 2025 Carl Hetherington +# +# This file is part of DCP-o-matic. +# +# DCP-o-matic 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 2 of the License, or +# (at your option) any later version. +# +# DCP-o-matic 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 DCP-o-matic. If not, see . +# + + +def build(bld): + obj = bld(features='cxx cxxprogram') + obj.name = 'unit-tests' + obj.uselib = 'BOOST_TEST BOOST_THREAD BOOST_FILESYSTEM SNDFILE DCP PNG ' + obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE SWRESAMPLE ' + obj.uselib += 'WXWIDGETS LIBZ GLIB ICU CURL PANGO CAIRO SSH PANGOMM FONTCONFIG NETTLE CXML ' + obj.uselib += 'XMLPP SUB XMLSEC SAMPLERATE SQLITE3 LEQM_NRT ZIP BOOST_REGEX ' + if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32: + obj.uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE ' + if bld.env.TARGET_LINUX: + obj.uselib += 'DL ' + if bld.env.BUILD_STATIC or bld.env.TARGET_LINUX: + obj.uselib += 'GTK ' + obj.use = 'libdcpomatic2-wx' + obj.source = "../test.cc i18n_test.cc" + obj.target = 'unit-tests' + obj.install_path = '' + -- cgit v1.2.3