summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-11-02 23:14:04 +0100
committerCarl Hetherington <cth@carlh.net>2021-11-04 11:46:03 +0100
commite1555a8837da05f135a3705112469206fc17ec80 (patch)
tree591de2b5330e351b733a7f5488f35c35aeae2f2b
parent89c0fc8bf6893ecde5e220dca96444afd069bf7f (diff)
Add ConfigRestorer and use it instead of setup_test_config() directly.
-rw-r--r--test/config_test.cc18
-rw-r--r--test/import_dcp_test.cc5
-rw-r--r--test/test.cc11
-rw-r--r--test/test.h8
-rw-r--r--test/vf_kdm_test.cc5
5 files changed, 26 insertions, 21 deletions
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 8417b30d2..c63dd132a 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"));
@@ -920,3 +920,10 @@ check_int_close (std::pair<int, int> a, std::pair<int, int> 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<Film> new_test_film (std::string);
extern std::shared_ptr<Film> new_test_film2 (std::string, std::vector<std::shared_ptr<Content>> 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 ();
}