summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-05-20 17:53:36 +0200
committerCarl Hetherington <cth@carlh.net>2025-05-24 00:44:18 +0200
commit354cf55bb0e8e70d4c9f40c91ae3f89e7922da01 (patch)
tree74a3c5843f0e6f163b123150d6456d3419376508 /test
parent11ee457964181fbc59aa1b06e3788de24a2763b8 (diff)
Add some wxWidgets-based i18n tests.
Diffstat (limited to 'test')
-rw-r--r--test/wscript1
-rw-r--r--test/wx/i18n_test.cc207
-rw-r--r--test/wx/wscript38
3 files changed, 246 insertions, 0 deletions
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 <cth@carlh.net>
+
+ 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 <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "../test.h"
+#include "wx/wx_util.h"
+#include "lib/util.h"
+#include <dcp/scope_guard.h>
+#include <wx/wx.h>
+#include <fmt/format.h>
+#include <boost/test/unit_test.hpp>
+#include <stdlib.h>
+
+
+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<string>(1.23), "1.23");
+#define numbers_de BOOST_CHECK_EQUAL(dcp::locale_convert<string>(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 <cth@carlh.net>
+#
+# 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 <http://www.gnu.org/licenses/>.
+#
+
+
+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 = ''
+