X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Ftest.cc;h=8cbb2408b467a7004bea352c5a3c3f779118ef06;hb=67544a255ffd7a27f5388e18cd0207f23ecce5ed;hp=eba0fc49055cb8747edc5de568a1b46f9dd0fe6d;hpb=41262015eb2bb1fc3da8585883420975de381a65;p=dcpomatic.git diff --git a/test/test.cc b/test/test.cc index eba0fc490..8cbb2408b 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,10 +18,13 @@ */ + + /** @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 #include + 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::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::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 new_test_film (string name) { @@ -175,6 +189,7 @@ new_test_film (string name) return film; } + shared_ptr new_test_film2 (string name, vector> content, Cleanup* cleanup) { @@ -199,6 +214,7 @@ new_test_film2 (string name, vector> content, Cleanup* clean return film; } + void check_wav_file (boost::filesystem::path ref, boost::filesystem::path check) { @@ -242,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) { @@ -465,6 +482,39 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) fclose (check_file); } + +void +check_text_file (boost::filesystem::path ref, boost::filesystem::path check) +{ + auto ref_file = fopen_boost (ref, "r"); + BOOST_CHECK (ref_file); + auto check_file = fopen_boost (check, "r"); + BOOST_CHECK (check_file); + + int const buffer_size = std::max( + boost::filesystem::file_size(ref), + boost::filesystem::file_size(check) + ); + + DCPOMATIC_ASSERT (buffer_size < 1024 * 1024); + + auto ref_buffer = new uint8_t[buffer_size]; + auto ref_read = fread(ref_buffer, 1, buffer_size, ref_file); + auto check_buffer = new uint8_t[buffer_size]; + auto check_read = fread(check_buffer, 1, buffer_size, check_file); + BOOST_CHECK_EQUAL (ref_read, check_read); + + string const error = "File " + check.string() + " differs from reference " + ref.string(); + BOOST_CHECK_MESSAGE(memcmp(ref_buffer, check_buffer, ref_read) == 0, error); + + delete[] ref_buffer; + delete[] check_buffer; + + fclose (ref_file); + fclose (check_file); +} + + static void note (dcp::NoteType t, string n) {