Add ConfigRestorer and use it instead of setup_test_config() directly.
authorCarl Hetherington <cth@carlh.net>
Tue, 2 Nov 2021 22:14:04 +0000 (23:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 4 Nov 2021 10:46:03 +0000 (11:46 +0100)
test/config_test.cc
test/import_dcp_test.cc
test/test.cc
test/test.h
test/vf_kdm_test.cc

index 035d778281936f9ddc3f4eb7de119d1b5819957b..48dec27d76543e9b13566ae1f614f3f9c75d62c8 100644 (file)
@@ -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();
 }
 
index 8107aa77a0300e560607f8d21ca2f85d78265da4..46deea53931480b2bb35965f548245036d7e9bc8 100644 (file)
@@ -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 ();
 }
 
 
index 8417b30d2ec197111fb809958ee111b7fa5d2171..c63dd132a1d7a446c3757a2d79f82ae298c7cf2b 100644 (file)
@@ -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();
+}
+
index 217b738f48d2144d81fba4f4dc589f7f745fd09f..2b01db294286743dbca0a2631ff72c6f8174be5a 100644 (file)
@@ -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);
index 44d497e6df89fe6993d29320b47a8a249e5f3a41..5248ee798d7bb328001650fcf0811f85048f8510 100644 (file)
@@ -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 ();
 }