2 Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/config.h"
23 #include "lib/content_factory.h"
24 #include "lib/dcp_content.h"
25 #include "lib/examine_content_job.h"
26 #include "lib/ffmpeg_content.h"
28 #include "lib/job_manager.h"
29 #include "lib/text_content.h"
31 #include <boost/test/unit_test.hpp>
35 using std::dynamic_pointer_cast;
36 using std::make_shared;
39 using boost::optional;
42 /** Check for bug #1126 whereby making a new DCP using the same video asset as an old one
43 * corrupts the old one.
45 BOOST_AUTO_TEST_CASE (remake_id_test1)
48 auto content = content_factory("test/data/flat_red.png");
49 auto film = new_test_film2 ("remake_id_test1_1", content);
50 make_and_verify_dcp (film);
52 /* Copy the video file */
53 auto first_video = dcp_file(film, "j2c");
54 boost::filesystem::copy_file (first_video, first_video.string() + ".copy");
56 /* Make a new DCP with the same video file */
57 film->set_name ("remake_id_test1_2");
58 make_and_verify_dcp (film);
60 /* Check that the video in the first DCP hasn't changed */
61 check_file (first_video, first_video.string() + ".copy");
65 /** Check for bug #1232 where remaking an encrypted DCP causes problems with HMAC IDs (?) */
66 BOOST_AUTO_TEST_CASE (remake_id_test2)
69 auto content = content_factory("test/data/flat_red.png");
70 auto film = new_test_film2 ("remake_id_test2_1", content);
71 film->set_encrypted (true);
72 make_and_verify_dcp (film);
74 /* Remove and remake it */
75 boost::filesystem::remove_all(film->dir(film->dcp_name()));
76 make_and_verify_dcp (film);
79 optional<boost::filesystem::path> cpl;
80 for (auto i: boost::filesystem::directory_iterator(film->dir(film->dcp_name()))) {
81 if (i.path().filename().string().substr(0, 4) == "cpl_") {
88 auto kdm = film->make_kdm (
89 Config::instance()->decryption_chain()->leaf(),
92 dcp::LocalTime ("2030-01-01T01:00:00+00:00"),
93 dcp::LocalTime ("2031-01-01T01:00:00+00:00"),
94 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
99 /* Import the DCP into a new film */
100 auto dcp_content = make_shared<DCPContent>(film->dir(film->dcp_name()));
101 auto film2 = new_test_film2("remake_id_test2_2", { dcp_content });
102 dcp_content->add_kdm(kdm);
103 JobManager::instance()->add(make_shared<ExamineContentJob>(film2, dcp_content));
104 BOOST_REQUIRE(!wait_for_jobs());
105 make_and_verify_dcp (film2);