Write player debug logs from tests on -- --log=debug-player
[dcpomatic.git] / test / test.cc
index f1fd40fb791597c4bf5da7e960a05b523b5878cb..9d6a785b8a9d3be45e84c7f7d5be615814e05eed 100644 (file)
@@ -155,6 +155,16 @@ struct TestConfig
                signal_manager = new TestSignalManager ();
 
                dcpomatic_log.reset (new FileLog("build/test/log"));
+
+               auto const& suite = boost::unit_test::framework::master_test_suite();
+               int types = LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR;
+               for (int i = 1; i < suite.argc; ++i) {
+                       if (string(suite.argv[i]) == "--log=debug-player") {
+                               types |= LogEntry::TYPE_DEBUG_PLAYER;
+                       }
+               }
+
+               dcpomatic_log->set_types(types);
        }
 
        ~TestConfig ()
@@ -980,3 +990,27 @@ find_file (boost::filesystem::path dir, string filename_part)
        BOOST_REQUIRE (found);
        return *found;
 }
+
+
+Editor::Editor(boost::filesystem::path path)
+       : _path(path)
+       , _content(dcp::file_to_string(path))
+{
+
+}
+
+Editor::~Editor()
+{
+       auto f = fopen(_path.string().c_str(), "w");
+       BOOST_REQUIRE(f);
+       fwrite(_content.c_str(), _content.length(), 1, f);
+       fclose(f);
+}
+
+void
+Editor::replace(string a, string b)
+{
+       auto old_content = _content;
+       boost::algorithm::replace_all(_content, a, b);
+       BOOST_REQUIRE(_content != old_content);
+}