diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-05-18 22:20:02 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-05-19 21:25:35 +0200 |
| commit | 8d18da108282203a90f4b5ae0123700b827e3eb7 (patch) | |
| tree | 627bf6dad0c0cf0c7bff5ca4f147f0baa5c683a3 | |
| parent | 0866fe0a549a489a140fd4670a5245ba231fc8ec (diff) | |
Tidy up finding required files during tests.
In particular, prefer not to use lots of fallback attempts. It seems
that something funny is going on with how we find Liberation Sans on
Linux, meaning that we were sometimes using the OS copy of the font when
we didn't mean to.
| -rwxr-xr-x | run/tests | 13 | ||||
| -rw-r--r-- | run/tests.bat | 7 | ||||
| -rw-r--r-- | src/lib/cross_linux.cc | 6 | ||||
| -rw-r--r-- | src/lib/cross_osx.cc | 7 | ||||
| -rw-r--r-- | src/lib/cross_windows.cc | 6 | ||||
| -rw-r--r-- | src/lib/util.cc | 43 | ||||
| -rw-r--r-- | src/lib/util.h | 1 | ||||
| -rw-r--r-- | test/test.cc | 1 |
8 files changed, 44 insertions, 40 deletions
@@ -58,6 +58,9 @@ done if [ "$(uname)" == "Linux" ]; then rm -f build/test/dcpomatic2_openssl mkdir -p build/test + cp -r ../libdcp/tags build/test + cp -r ../libdcp/xsd build/test + cp ../libdcp/ratings build/test # This must be our patched openssl or tests will fail if [ ! -f build/test/dcpomatic2_openssl ]; then ln -s ../../../openssl/apps/openssl build/test/dcpomatic2_openssl @@ -75,13 +78,9 @@ if [ "$(uname)" == "Linux" ]; then fi if [ "$(uname)" == "Darwin" ]; then - resources=build/Resources - rm -rf $resources - mkdir -p $resources - cp fonts/*.ttf $resources - cp -r ../libdcp/tags $resources - cp -r ../libdcp/xsd $resources - cp ../libdcp/ratings $resources + cp -r ../libdcp/tags build/test + cp -r ../libdcp/xsd build/test + cp ../libdcp/ratings build/test rm -f build/test/openssl ln -s ../../../openssl/apps/openssl build/test/openssl # We need to find ffcmp in here diff --git a/run/tests.bat b/run/tests.bat index f419027bc..3eb422d7d 100644 --- a/run/tests.bat +++ b/run/tests.bat @@ -1,8 +1,7 @@ set PATH=%PATH%;c:\users\ci\bin_v2.18.x;c:\users\ci\workspace\dcpomatic\bin;c:\users\ci\workspace\dcpomatic\lib set DCPOMATIC_TEST_PRIVATE=c:\users\ci\dcpomatic-test-private -xcopy ..\libdcp\tags build\tags\ -copy ..\libdcp\ratings build\ +xcopy ..\libdcp\tags build\test\tags\ +copy ..\libdcp\ratings build\test\ copy ..\openssl\apps\openssl.exe build\test\ -xcopy fonts build\fonts\ -move build\fonts\fonts.conf.windows build\fonts\fonts.conf +copy fonts\fonts.conf.windows fonts\fonts.conf build\test\unit-tests.exe --log_level=test_suite %1 %2 diff --git a/src/lib/cross_linux.cc b/src/lib/cross_linux.cc index be3233b32..ccd78a3b1 100644 --- a/src/lib/cross_linux.cc +++ b/src/lib/cross_linux.cc @@ -26,6 +26,7 @@ #include "dcpomatic_log.h" #include "exceptions.h" #include "log.h" +#include "util.h" #include <dcp/filesystem.h> #include <dcp/raw_convert.h> #include <dcp/warnings.h> @@ -90,6 +91,7 @@ resources_path () return installed; } + /* Fallback for running from the source tree */ return directory_containing_executable().parent_path().parent_path().parent_path(); } @@ -97,6 +99,10 @@ resources_path () boost::filesystem::path libdcp_resources_path () { + if (running_tests) { + return directory_containing_executable(); + } + if (auto appdir = getenv("APPDIR")) { return boost::filesystem::path(appdir) / "usr" / "share" / "libdcp"; } diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index 350287e75..7d03ce1b3 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -25,6 +25,7 @@ #include "dcpomatic_log.h" #include "exceptions.h" #include "log.h" +#include "util.h" #include "variant.h" #include <dcp/filesystem.h> #include <glib.h> @@ -99,7 +100,11 @@ resources_path() boost::filesystem::path libdcp_resources_path() { - return resources_path(); + if (running_tests) { + return directory_containing_executable(); + } else { + return resources_path(); + } } diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc index ad71a3849..3fdaad61a 100644 --- a/src/lib/cross_windows.cc +++ b/src/lib/cross_windows.cc @@ -229,7 +229,11 @@ resources_path() boost::filesystem::path libdcp_resources_path() { - return resources_path(); + if (running_tests) { + return directory_containing_executable(); + } else { + return resources_path(); + } } diff --git a/src/lib/util.cc b/src/lib/util.cc index 81ae4c494..5ac75134d 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -136,6 +136,7 @@ using namespace dcpomatic; */ string program_name; bool is_batch_converter = false; +bool running_tests = false; static boost::thread::id ui_thread; static boost::filesystem::path backtrace_file; @@ -458,18 +459,22 @@ LIBDCP_ENABLE_WARNINGS #ifdef DCPOMATIC_WINDOWS putenv("PANGOCAIRO_BACKEND=fontconfig"); - if (dcp::filesystem::exists(resources_path() / "fonts.conf")) { - /* The actual application after installation */ - putenv(String::compose("FONTCONFIG_PATH=%1", resources_path().string()).c_str()); + if (running_tests) { + putenv("FONTCONFIG_PATH=fonts"); } else { - /* The place where fonts.conf is during tests */ - putenv("FONTCONFIG_PATH=build\\fonts"); + putenv(String::compose("FONTCONFIG_PATH=%1", resources_path().string()).c_str()); } #endif #ifdef DCPOMATIC_OSX setenv("PANGOCAIRO_BACKEND", "fontconfig", 1); - setenv("FONTCONFIG_PATH", resources_path().string().c_str(), 1); + boost::filesystem::path fontconfig; + if (running_tests) { + fontconfig = directory_containing_executable().parent_path().parent_path() / "fonts"; + } else { + fontconfig = resources_path(); + } + setenv("FONTCONFIG_PATH", fontconfig.string().c_str(), 1); #endif Pango::init(); @@ -1042,29 +1047,13 @@ decrypt_kdm_with_helpful_error(dcp::EncryptedKDM kdm) boost::filesystem::path default_font_file() { - boost::filesystem::path liberation_normal; - try { - liberation_normal = resources_path() / "LiberationSans-Regular.ttf"; - if (!dcp::filesystem::exists(liberation_normal)) { - /* Hack for unit tests */ - liberation_normal = resources_path() / "fonts" / "LiberationSans-Regular.ttf"; - } - } catch (boost::filesystem::filesystem_error& e) { - - } - - if (!dcp::filesystem::exists(liberation_normal)) { - liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"; - } - if (!dcp::filesystem::exists(liberation_normal)) { - liberation_normal = "/usr/share/fonts/liberation-sans/LiberationSans-Regular.ttf"; - } - if (!dcp::filesystem::exists(liberation_normal)) { - /* Fedora 41 puts it here */ - liberation_normal = "/usr/share/fonts/liberation-sans-fonts/LiberationSans-Regular.ttf"; + if (running_tests) { + auto const liberation = directory_containing_executable().parent_path().parent_path() / "fonts" / "LiberationSans-Regular.ttf"; + DCPOMATIC_ASSERT(dcp::filesystem::exists(liberation)); + return liberation; } - return liberation_normal; + return resources_path() / "LiberationSans-Regular.ttf"; } diff --git a/src/lib/util.h b/src/lib/util.h index 525deeb75..80ba4a1f6 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -55,6 +55,7 @@ namespace dcp { extern std::string program_name; extern bool is_batch_converter; +extern bool running_tests; class AudioBuffers; class TextDecoder; diff --git a/test/test.cc b/test/test.cc index ba9b4d66f..f518cdccc 100644 --- a/test/test.cc +++ b/test/test.cc @@ -156,6 +156,7 @@ struct TestConfig { TestConfig () { + running_tests = true; State::override_path = "build/test/state"; boost::filesystem::remove_all (*State::override_path); |
