Fill test disk partitions with random noise to expose more bugs.
[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/ffmpeg_content.h"
23 #include "lib/content_factory.h"
24 #include "lib/text_content.h"
25 #include "lib/job_manager.h"
26 #include "lib/film.h"
27 #include "lib/dcp_content.h"
28 #include "lib/examine_content_job.h"
29 #include "lib/config.h"
30 #include "test.h"
31 #include <boost/test/unit_test.hpp>
32 #include <iostream>
33
34
35 using std::string;
36 using std::vector;
37 using std::shared_ptr;
38 using std::dynamic_pointer_cast;
39 using std::make_shared;
40 using boost::optional;
41
42
43 /** Check for bug #1126 whereby making a new DCP using the same video asset as an old one
44  *  corrupts the old one.
45  */
46 BOOST_AUTO_TEST_CASE (remake_id_test1)
47 {
48         /* Make a DCP */
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);
52
53         /* Copy the video file */
54         auto first_video = dcp_file(film, "j2c");
55         boost::filesystem::copy_file (first_video, first_video.string() + ".copy");
56
57         /* Make a new DCP with the same video file */
58         film->set_name ("remake_id_test1_2");
59         make_and_verify_dcp (film);
60
61         /* Check that the video in the first DCP hasn't changed */
62         check_file (first_video, first_video.string() + ".copy");
63 }
64
65
66 /** Check for bug #1232 where remaking an encrypted DCP causes problems with HMAC IDs (?) */
67 BOOST_AUTO_TEST_CASE (remake_id_test2)
68 {
69         /* Make a DCP */
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);
74
75         /* Remove and remake it */
76         boost::filesystem::remove_all(film->dir(film->dcp_name()));
77         make_and_verify_dcp (film);
78
79         /* Find the CPL */
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_") {
83                         cpl = i.path();
84                 }
85         }
86         BOOST_REQUIRE(cpl);
87
88         /* Make a DKDM */
89         auto kdm = film->make_kdm (
90                 Config::instance()->decryption_chain()->leaf(),
91                 vector<string>(),
92                 *cpl,
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,
96                 true,
97                 0
98                 );
99
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);
107 }