Try to fix text-file-checking test on Windows.
[dcpomatic.git] / test / test.cc
index 292b4e1d9436b60365c6ad5e604a512f52cc108e..27393386bd1ebdcdb266cbf0bb2580b943bec14d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
+
 /** @file  test/test.cc
  *  @brief Overall test stuff and useful methods for tests.
  */
 
+
 #include "lib/compose.hpp"
 #include "lib/config.h"
 #include "lib/cross.h"
@@ -61,6 +64,7 @@ extern "C" {
 #include <list>
 #include <vector>
 
+
 using std::abs;
 using std::cerr;
 using std::cout;
@@ -115,8 +119,15 @@ setup_test_config ()
                LogEntry::TYPE_DISK
                );
        Config::instance()->set_automatic_audio_analysis (false);
+       auto signer = make_shared<dcp::CertificateChain>(dcp::file_to_string("test/data/signer_chain"));
+       signer->set_key(dcp::file_to_string("test/data/signer_key"));
+       Config::instance()->set_signer_chain (signer);
+       auto decryption = make_shared<dcp::CertificateChain>(dcp::file_to_string("test/data/decryption_chain"));
+       decryption->set_key(dcp::file_to_string("test/data/decryption_key"));
+       Config::instance()->set_decryption_chain (decryption);
 }
 
+
 class TestSignalManager : public SignalManager
 {
 public:
@@ -150,8 +161,10 @@ struct TestConfig
        }
 };
 
+
 BOOST_GLOBAL_FIXTURE (TestConfig);
 
+
 boost::filesystem::path
 test_film_dir (string name)
 {
@@ -162,6 +175,7 @@ test_film_dir (string name)
        return p;
 }
 
+
 shared_ptr<Film>
 new_test_film (string name)
 {
@@ -175,8 +189,9 @@ new_test_film (string name)
        return film;
 }
 
+
 shared_ptr<Film>
-new_test_film2 (string name, Cleanup* cleanup)
+new_test_film2 (string name, vector<shared_ptr<Content>> content, Cleanup* cleanup)
 {
        auto p = test_film_dir (name);
        if (boost::filesystem::exists (p)) {
@@ -190,9 +205,16 @@ new_test_film2 (string name, Cleanup* cleanup)
        film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
        film->set_container (Ratio::from_id ("185"));
        film->write_metadata ();
+
+       for (auto i: content) {
+               film->examine_and_add_content (i);
+               BOOST_REQUIRE (!wait_for_jobs());
+       }
+
        return film;
 }
 
+
 void
 check_wav_file (boost::filesystem::path ref, boost::filesystem::path check)
 {
@@ -236,6 +258,7 @@ check_wav_file (boost::filesystem::path ref, boost::filesystem::path check)
        }
 }
 
+
 void
 check_mxf_audio_file (boost::filesystem::path ref, boost::filesystem::path check)
 {
@@ -422,13 +445,13 @@ check_image (boost::filesystem::path ref, boost::filesystem::path check, double
 
 
 void
-check_file (boost::filesystem::path ref, boost::filesystem::path check)
+check_file (boost::filesystem::path ref, boost::filesystem::path check, bool binary_mode)
 {
        auto N = boost::filesystem::file_size (ref);
        BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check));
-       auto ref_file = fopen_boost (ref, "rb");
+       auto ref_file = fopen_boost (ref, binary_mode ? "rb" : "r");
        BOOST_CHECK (ref_file);
-       auto check_file = fopen_boost (check, "rb");
+       auto check_file = fopen_boost (check, binary_mode ? "rb" : "r");
        BOOST_CHECK (check_file);
 
        int const buffer_size = 65536;
@@ -459,6 +482,7 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check)
        fclose (check_file);
 }
 
+
 static void
 note (dcp::NoteType t, string n)
 {
@@ -830,3 +854,26 @@ Cleanup::run ()
                boost::filesystem::remove_all (i, ec);
        }
 }
+
+
+void stage (string, boost::optional<boost::filesystem::path>) {}
+void progress (float) {}
+
+
+void
+make_and_verify_dcp (shared_ptr<Film> film, vector<dcp::VerificationNote::Code> ignore)
+{
+       film->write_metadata ();
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs());
+       auto notes = dcp::verify ({film->dir(film->dcp_name())}, &stage, &progress, TestPaths::xsd());
+       bool ok = true;
+       for (auto i: notes) {
+               if (find(ignore.begin(), ignore.end(), i.code()) == ignore.end()) {
+                       std::cout << "\t" << dcp::note_to_string(i) << "\n";
+                       ok = false;
+               }
+       }
+       BOOST_CHECK(ok);
+}
+