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/ffmpeg_content.h"
23 #include "lib/content_factory.h"
24 #include "lib/text_content.h"
25 #include "lib/job_manager.h"
27 #include "lib/dcp_content.h"
28 #include "lib/examine_content_job.h"
29 #include "lib/config.h"
31 #include <boost/test/unit_test.hpp>
37 using std::shared_ptr;
38 using std::dynamic_pointer_cast;
39 using std::make_shared;
40 using boost::optional;
43 /** Check for bug #1126 whereby making a new DCP using the same video asset as an old one
44 * corrupts the old one.
46 BOOST_AUTO_TEST_CASE (remake_id_test1)
49 auto content = content_factory("test/data/flat_red.png").front();
50 auto film = new_test_film2 ("remake_id_test1_1", {content});
51 make_and_verify_dcp (film);
53 /* Copy the video file */
54 auto first_video = dcp_file(film, "j2c");
55 boost::filesystem::copy_file (first_video, first_video.string() + ".copy");
57 /* Make a new DCP with the same video file */
58 film->set_name ("remake_id_test1_2");
59 make_and_verify_dcp (film);
61 /* Check that the video in the first DCP hasn't changed */
62 check_file (first_video, first_video.string() + ".copy");
66 /** Check for bug #1232 where remaking an encrypted DCP causes problems with HMAC IDs (?) */
67 BOOST_AUTO_TEST_CASE (remake_id_test2)
70 auto content = content_factory("test/data/flat_red.png").front();
71 auto film = new_test_film2 ("remake_id_test2_1", {content});
72 film->set_encrypted (true);
73 make_and_verify_dcp (film);
75 /* Remove and remake it */
76 boost::filesystem::remove_all(film->dir(film->dcp_name()));
77 make_and_verify_dcp (film);
80 optional<boost::filesystem::path> cpl;
81 for (auto i: boost::filesystem::directory_iterator(film->dir(film->dcp_name()))) {
82 if (i.path().filename().string().substr(0, 4) == "cpl_") {
89 auto kdm = film->make_kdm (
90 Config::instance()->decryption_chain()->leaf(),
93 dcp::LocalTime ("2030-01-01T01:00:00+00:00"),
94 dcp::LocalTime ("2031-01-01T01:00:00+00:00"),
95 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
100 /* Import the DCP into a new film */
101 auto dcp_content = make_shared<DCPContent>(film->dir(film->dcp_name()));
102 auto film2 = new_test_film2("remake_id_test2_2", {dcp_content});
103 dcp_content->add_kdm(kdm);
104 JobManager::instance()->add(make_shared<ExamineContentJob>(film2, dcp_content));
105 BOOST_REQUIRE(!wait_for_jobs());
106 make_and_verify_dcp (film2);