From: Carl Hetherington Date: Tue, 2 Nov 2021 22:14:04 +0000 (+0100) Subject: Add ConfigRestorer and use it instead of setup_test_config() directly. X-Git-Tag: checked-for-v2.16.x~198 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=7846d4bfb77c117d931aad20239941a491492a78 Add ConfigRestorer and use it instead of setup_test_config() directly. --- diff --git a/test/config_test.cc b/test/config_test.cc index 035d77828..48dec27d7 100644 --- a/test/config_test.cc +++ b/test/config_test.cc @@ -47,6 +47,8 @@ rewrite_bad_config () BOOST_AUTO_TEST_CASE (config_backup_test) { + ConfigRestorer cr; + Config::override_path = "build/test/bad_config"; Config::drop(); @@ -88,16 +90,13 @@ BOOST_AUTO_TEST_CASE (config_backup_test) BOOST_CHECK (boost::filesystem::exists("build/test/bad_config/2.16/config.xml.2")); BOOST_CHECK (boost::filesystem::exists("build/test/bad_config/2.16/config.xml.3")); BOOST_CHECK (boost::filesystem::exists("build/test/bad_config/2.16/config.xml.4")); - - /* This test has called Config::set_defaults(), so take us back - to the config that we want for our tests. - */ - setup_test_config (); } BOOST_AUTO_TEST_CASE (config_write_utf8_test) { + ConfigRestorer cr; + boost::filesystem::remove_all ("build/test/config.xml"); boost::filesystem::copy_file ("test/data/utf8_config.xml", "build/test/config.xml"); Config::override_path = "build/test"; @@ -105,16 +104,13 @@ BOOST_AUTO_TEST_CASE (config_write_utf8_test) Config::instance()->write(); check_text_file ("test/data/utf8_config.xml", "build/test/config.xml"); - - /* This test has called Config::set_defaults(), so take us back - to the config that we want for our tests. - */ - setup_test_config (); } BOOST_AUTO_TEST_CASE (config_upgrade_test) { + ConfigRestorer cr; + boost::filesystem::path dir = "build/test/config_upgrade_test"; Config::override_path = dir; Config::drop (); @@ -139,7 +135,5 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test) #endif /* cinemas.xml is not copied into 2.16 as its format has not changed */ BOOST_REQUIRE (!boost::filesystem::exists(dir / "2.16" / "cinemas.xml")); - - setup_test_config(); } diff --git a/test/import_dcp_test.cc b/test/import_dcp_test.cc index 8107aa77a..46deea539 100644 --- a/test/import_dcp_test.cc +++ b/test/import_dcp_test.cc @@ -54,6 +54,8 @@ using std::make_shared; /** Make an encrypted DCP, import it and make a new unencrypted DCP */ BOOST_AUTO_TEST_CASE (import_dcp_test) { + ConfigRestorer cr; + auto A = new_test_film ("import_dcp_test"); A->set_container (Ratio::from_id ("185")); A->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR")); @@ -100,9 +102,6 @@ BOOST_AUTO_TEST_CASE (import_dcp_test) /* Should be 1s red, 1s green, 1s blue */ check_dcp ("test/data/import_dcp_test2", "build/test/import_dcp_test2/" + B->dcp_name()); - - /* Restore the reference decryption chain */ - setup_test_config (); } diff --git a/test/test.cc b/test/test.cc index b40d5eed6..d1677a107 100644 --- a/test/test.cc +++ b/test/test.cc @@ -99,10 +99,10 @@ boost::filesystem::path TestPaths::xsd () } -void +static void setup_test_config () { - Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency()); + Config::instance()->set_master_encoding_threads (boost::thread::hardware_concurrency() / 2); Config::instance()->set_server_encoding_threads (1); Config::instance()->set_server_port_base (61921); Config::instance()->set_default_container (Ratio::from_id ("185")); @@ -914,3 +914,10 @@ check_int_close (std::pair a, std::pair b, int d) check_int_close (a.first, b.first, d); check_int_close (a.second, b.second, d); } + + +ConfigRestorer::~ConfigRestorer() +{ + setup_test_config(); +} + diff --git a/test/test.h b/test/test.h index 217b738f4..2b01db294 100644 --- a/test/test.h +++ b/test/test.h @@ -56,7 +56,6 @@ private: extern bool wait_for_jobs (); -extern void setup_test_config (); extern std::shared_ptr new_test_film (std::string); extern std::shared_ptr new_test_film2 (std::string, std::vector> content = {}, Cleanup* cleanup = nullptr); extern void check_dcp (boost::filesystem::path, boost::filesystem::path); @@ -91,6 +90,13 @@ private: }; +class ConfigRestorer +{ +public: + ~ConfigRestorer(); +}; + + namespace dcp { std::ostream& operator<< (std::ostream& s, dcp::Size i); diff --git a/test/vf_kdm_test.cc b/test/vf_kdm_test.cc index 44d497e6d..5248ee798 100644 --- a/test/vf_kdm_test.cc +++ b/test/vf_kdm_test.cc @@ -47,6 +47,8 @@ using std::vector; BOOST_AUTO_TEST_CASE (vf_kdm_test) { + ConfigRestorer cr; + /* Make an encrypted DCP from test.mp4 */ auto A = new_test_film ("vf_kdm_test_ov"); @@ -124,7 +126,4 @@ BOOST_AUTO_TEST_CASE (vf_kdm_test) /* Should be 1s red, 1s green, 1s blue */ check_dcp ("test/data/vf_kdm_test_check", "build/test/vf_kdm_test_check/" + C->dcp_name()); - - /* Restore the reference decryption chain */ - setup_test_config (); }