Supporters update.
[dcpomatic.git] / test / remake_id_test.cc
1 /*
2     Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
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"
27 #include "lib/film.h"
28 #include "lib/job_manager.h"
29 #include "lib/text_content.h"
30 #include "test.h"
31 #include <boost/test/unit_test.hpp>
32 #include <iostream>
33
34
35 using std::dynamic_pointer_cast;
36 using std::make_shared;
37 using std::string;
38 using std::vector;
39 using boost::optional;
40
41
42 /** Check for bug #1126 whereby making a new DCP using the same video asset as an old one
43  *  corrupts the old one.
44  */
45 BOOST_AUTO_TEST_CASE (remake_id_test1)
46 {
47         /* Make a DCP */
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);
51
52         /* Copy the video file */
53         auto first_video = dcp_file(film, "j2c");
54         boost::filesystem::copy_file (first_video, first_video.string() + ".copy");
55
56         /* Make a new DCP with the same video file */
57         film->set_name ("remake_id_test1_2");
58         make_and_verify_dcp (film);
59
60         /* Check that the video in the first DCP hasn't changed */
61         check_file (first_video, first_video.string() + ".copy");
62 }
63
64
65 /** Check for bug #1232 where remaking an encrypted DCP causes problems with HMAC IDs (?) */
66 BOOST_AUTO_TEST_CASE (remake_id_test2)
67 {
68         /* Make a DCP */
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);
73
74         /* Remove and remake it */
75         boost::filesystem::remove_all(film->dir(film->dcp_name()));
76         make_and_verify_dcp (film);
77
78         /* Find the CPL */
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_") {
82                         cpl = i.path();
83                 }
84         }
85         BOOST_REQUIRE(cpl);
86
87         auto signer = Config::instance()->signer_chain();
88         BOOST_REQUIRE(signer->valid());
89
90         /* Make a DKDM */
91         auto const decrypted_kdm = film->make_kdm(*cpl, dcp::LocalTime ("2030-01-01T01:00:00+00:00"), dcp::LocalTime ("2031-01-01T01:00:00+00:00"));
92         auto const kdm = decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
93
94         /* Import the DCP into a new film */
95         auto dcp_content = make_shared<DCPContent>(film->dir(film->dcp_name()));
96         auto film2 = new_test_film2("remake_id_test2_2", { dcp_content });
97         dcp_content->add_kdm(kdm);
98         JobManager::instance()->add(make_shared<ExamineContentJob>(film2, dcp_content));
99         BOOST_REQUIRE(!wait_for_jobs());
100         make_and_verify_dcp (film2);
101 }