From 4bee9f40969db94aa7edc7816e1b12a7db3cab07 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 24 Nov 2020 01:29:11 +0100 Subject: Calculate hashes for any referenced assets that do not already have one. This is necessary so that we always include in CPLs even when referencing DCPs that do not have it. --- test/cpl_hash_test.cc | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/cpl_hash_test.cc (limited to 'test/cpl_hash_test.cc') diff --git a/test/cpl_hash_test.cc b/test/cpl_hash_test.cc new file mode 100644 index 000000000..28a9420da --- /dev/null +++ b/test/cpl_hash_test.cc @@ -0,0 +1,97 @@ +/* + Copyright (C) 2020 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +/** @file test/cpl_hash_test.cc + * @brief Make sure that tags are always written to CPLs where required. + * @ingroup feature + */ + + +#include "lib/content_factory.h" +#include "lib/cross.h" +#include "lib/dcp_content.h" +#include "lib/film.h" +#include "test.h" +#include +#include + + +using std::string; +using boost::shared_ptr; + + +BOOST_AUTO_TEST_CASE (hash_added_to_imported_dcp_test) +{ + using namespace boost::filesystem; + + string const ov_name = "hash_added_to_imported_dcp_test_ov"; + shared_ptr ov = new_test_film2 (ov_name); + ov->examine_and_add_content (content_factory("test/data/flat_red.png").front()); + BOOST_REQUIRE (!wait_for_jobs()); + ov->make_dcp(); + BOOST_REQUIRE (!wait_for_jobs()); + + /* Remove tags from the CPL */ + for (directory_iterator i = directory_iterator(String::compose("build/test/%1/%2", ov_name, ov->dcp_name())); i != directory_iterator(); ++i) { + if (boost::algorithm::starts_with(i->path().filename().string(), "cpl_")) { + FILE* in = fopen_boost(i->path(), "r"); + BOOST_REQUIRE (in); + FILE* out = fopen_boost(i->path().string() + ".tmp", "w"); + BOOST_REQUIRE (out); + char buffer[256]; + while (fgets (buffer, sizeof(buffer), in)) { + if (string(buffer).find("Hash") == string::npos) { + fputs (buffer, out); + } + } + fclose (in); + fclose (out); + rename (i->path().string() + ".tmp", i->path()); + } + } + + string const vf_name = "hash_added_to_imported_dcp_test_vf"; + shared_ptr vf = new_test_film2 (vf_name); + shared_ptr ov_content(new DCPContent(String::compose("build/test/%1/%2", ov_name, ov->dcp_name()))); + vf->examine_and_add_content (ov_content); + BOOST_REQUIRE (!wait_for_jobs()); + + ov_content->set_reference_video (true); + vf->make_dcp (); + BOOST_REQUIRE (!wait_for_jobs()); + + /* Check for Hash tags in the VF DCP */ + int hashes = 0; + for (directory_iterator i = directory_iterator(String::compose("build/test/%1/%2", vf_name, vf->dcp_name())); i != directory_iterator(); ++i) { + if (boost::algorithm::starts_with(i->path().filename().string(), "cpl_")) { + FILE* in = fopen_boost(i->path(), "r"); + BOOST_REQUIRE (in); + char buffer[256]; + while (fgets (buffer, sizeof(buffer), in)) { + if (string(buffer).find("Hash") != string::npos) { + ++hashes; + } + } + fclose (in); + } + } + BOOST_CHECK_EQUAL (hashes, 2); +} + -- cgit v1.2.3