2 Copyright (C) 2014-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 /** @file test/import_dcp_test.cc
23 * @brief Test import of encrypted DCPs.
30 #include "lib/screen.h"
31 #include "lib/dcp_subtitle_content.h"
32 #include "lib/ratio.h"
33 #include "lib/dcp_content_type.h"
34 #include "lib/dcp_content.h"
35 #include "lib/ffmpeg_content.h"
36 #include "lib/examine_content_job.h"
37 #include "lib/job_manager.h"
38 #include "lib/config.h"
39 #include "lib/cross.h"
40 #include "lib/video_content.h"
41 #include "lib/content_factory.h"
43 #include <boost/test/unit_test.hpp>
49 using std::shared_ptr;
50 using std::dynamic_pointer_cast;
51 using std::make_shared;
54 /** Make an encrypted DCP, import it and make a new unencrypted DCP */
55 BOOST_AUTO_TEST_CASE (import_dcp_test)
57 auto A = new_test_film ("import_dcp_test");
58 A->set_container (Ratio::from_id ("185"));
59 A->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
60 A->set_name ("frobozz");
61 A->set_interop (false);
63 auto c = make_shared<FFmpegContent>("test/data/test.mp4");
64 A->examine_and_add_content (c);
65 A->set_encrypted (true);
66 BOOST_CHECK (!wait_for_jobs ());
69 BOOST_CHECK (!wait_for_jobs ());
71 dcp::DCP A_dcp ("build/test/import_dcp_test/" + A->dcp_name());
74 Config::instance()->set_decryption_chain (make_shared<dcp::CertificateChain>(openssl_path()));
76 /* Dear future-carl: I suck! I thought you wouldn't still be running these tests in 2030! Sorry! */
77 auto kdm = A->make_kdm (
78 Config::instance()->decryption_chain()->leaf (),
80 A_dcp.cpls().front()->file().get(),
81 dcp::LocalTime ("2030-07-21T00:00:00+00:00"),
82 dcp::LocalTime ("2031-07-21T00:00:00+00:00"),
83 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
87 auto B = new_test_film ("import_dcp_test2");
88 B->set_container (Ratio::from_id ("185"));
89 B->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
90 B->set_name ("frobozz");
91 B->set_interop (false);
93 auto d = make_shared<DCPContent>("build/test/import_dcp_test/" + A->dcp_name());
94 B->examine_and_add_content (d);
95 BOOST_CHECK (!wait_for_jobs ());
97 JobManager::instance()->add (make_shared<ExamineContentJob>(B, d));
98 BOOST_CHECK (!wait_for_jobs ());
101 BOOST_CHECK (!wait_for_jobs ());
103 /* Should be 1s red, 1s green, 1s blue */
104 check_dcp ("test/data/import_dcp_test2", "build/test/import_dcp_test2/" + B->dcp_name());
108 /** Check that DCP markers are imported correctly */
109 BOOST_AUTO_TEST_CASE (import_dcp_markers_test)
113 /* Make a DCP with some markers */
114 auto film = new_test_film2 ("import_dcp_markers_test", &cl);
115 auto content = content_factory("test/data/flat_red.png").front();
116 film->examine_and_add_content (content);
117 BOOST_REQUIRE (!wait_for_jobs());
119 content->video->set_length (24 * 60 * 10);
121 film->set_marker(dcp::Marker::FFOC, dcpomatic::DCPTime::from_seconds(1.91));
122 film->set_marker(dcp::Marker::FFMC, dcpomatic::DCPTime::from_seconds(9.4));
123 film->set_marker(dcp::Marker::LFMC, dcpomatic::DCPTime::from_seconds(9.99));
126 BOOST_REQUIRE (!wait_for_jobs());
128 /* Import the DCP to a new film and check the markers */
129 auto film2 = new_test_film2 ("import_dcp_markers_test2", &cl);
130 auto imported = make_shared<DCPContent>(film->dir(film->dcp_name()));
131 film2->examine_and_add_content (imported);
132 BOOST_REQUIRE (!wait_for_jobs());
133 film2->write_metadata ();
135 /* When import_dcp_markers_test was made a LFOC marker will automatically
138 BOOST_CHECK_EQUAL (imported->markers().size(), 4U);
140 auto markers = imported->markers();
141 BOOST_REQUIRE(markers.find(dcp::Marker::FFOC) != markers.end());
142 BOOST_CHECK(markers[dcp::Marker::FFOC] == dcpomatic::ContentTime(184000));
143 BOOST_REQUIRE(markers.find(dcp::Marker::FFMC) != markers.end());
144 BOOST_CHECK(markers[dcp::Marker::FFMC] == dcpomatic::ContentTime(904000));
145 BOOST_REQUIRE(markers.find(dcp::Marker::LFMC) != markers.end());
146 BOOST_CHECK(markers[dcp::Marker::LFMC] == dcpomatic::ContentTime(960000));
148 /* Load that film and check that the markers have been loaded */
149 auto film3 = make_shared<Film>(boost::filesystem::path("build/test/import_dcp_markers_test2"));
150 film3->read_metadata ();
151 BOOST_REQUIRE_EQUAL (film3->content().size(), 1U);
152 shared_ptr<DCPContent> reloaded = dynamic_pointer_cast<DCPContent>(film3->content().front());
153 BOOST_REQUIRE (reloaded);
155 BOOST_CHECK_EQUAL (reloaded->markers().size(), 4U);
157 markers = reloaded->markers();
158 BOOST_REQUIRE(markers.find(dcp::Marker::FFOC) != markers.end());
159 BOOST_CHECK(markers[dcp::Marker::FFOC] == dcpomatic::ContentTime(184000));
160 BOOST_REQUIRE(markers.find(dcp::Marker::FFMC) != markers.end());
161 BOOST_CHECK(markers[dcp::Marker::FFMC] == dcpomatic::ContentTime(904000));
162 BOOST_REQUIRE(markers.find(dcp::Marker::LFMC) != markers.end());
163 BOOST_CHECK(markers[dcp::Marker::LFMC] == dcpomatic::ContentTime(960000));
169 /** Check that DCP metadata (ratings and content version) are imported correctly */
170 BOOST_AUTO_TEST_CASE (import_dcp_metadata_test)
172 /* Make a DCP with some ratings and a content version */
173 auto film = new_test_film2 ("import_dcp_metadata_test");
174 auto content = content_factory("test/data/flat_red.png").front();
175 film->examine_and_add_content (content);
176 BOOST_REQUIRE (!wait_for_jobs());
178 content->video->set_length (10);
180 vector<dcp::Rating> ratings = { {"BBFC", "15"}, {"MPAA", "NC-17"} };
181 film->set_ratings (ratings);
183 vector<string> cv = { "Fred "};
184 film->set_content_versions (cv);
187 BOOST_REQUIRE (!wait_for_jobs());
189 /* Import the DCP to a new film and check the metadata */
190 auto film2 = new_test_film2 ("import_dcp_metadata_test2");
191 auto imported = make_shared<DCPContent>(film->dir(film->dcp_name()));
192 film2->examine_and_add_content (imported);
193 BOOST_REQUIRE (!wait_for_jobs());
194 film2->write_metadata ();
196 BOOST_CHECK (imported->ratings() == ratings);
197 BOOST_CHECK (imported->content_versions() == cv);
199 /* Load that film and check that the metadata has been loaded */
200 auto film3 = make_shared<Film>(boost::filesystem::path("build/test/import_dcp_metadata_test2"));
201 film3->read_metadata ();
202 BOOST_REQUIRE_EQUAL (film3->content().size(), 1U);
203 auto reloaded = dynamic_pointer_cast<DCPContent>(film3->content().front());
204 BOOST_REQUIRE (reloaded);
206 BOOST_CHECK (reloaded->ratings() == ratings);
207 BOOST_CHECK (reloaded->content_versions() == cv);