More verification of DCPs during tests.
[dcpomatic.git] / test / dcp_decoder_test.cc
1 /*
2     Copyright (C) 2019-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 /** @file  test/dcp_decoder_test.cc
23  *  @brief Test DCPDecoder class.
24  *  @ingroup selfcontained
25  */
26
27
28 #include "lib/film.h"
29 #include "lib/dcp_content.h"
30 #include "lib/dcp_decoder.h"
31 #include "lib/content_factory.h"
32 #include "lib/player.h"
33 #include "lib/examine_content_job.h"
34 #include "lib/job_manager.h"
35 #include "lib/config.h"
36 #include "test.h"
37 #include <dcp/dcp.h>
38 #include <boost/test/unit_test.hpp>
39 #include <iostream>
40
41
42 using std::list;
43 using std::string;
44 using std::vector;
45 using std::make_shared;
46 using std::shared_ptr;
47
48
49 /* Check that DCPDecoder reuses old data when it should */
50 BOOST_AUTO_TEST_CASE (check_reuse_old_data_test)
51 {
52         /* Make some DCPs */
53
54         auto ov = new_test_film2 ("check_reuse_old_data_ov", {content_factory("test/data/flat_red.png").front()});
55         make_and_verify_dcp (ov);
56
57         auto ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
58         auto vf = new_test_film2 ("check_reuse_old_data_vf", {ov_content, content_factory("test/data/L.wav").front()});
59         ov_content->set_reference_video (true);
60         make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
61
62         auto encrypted = new_test_film2 ("check_reuse_old_data_decrypted");
63         encrypted->examine_and_add_content (content_factory("test/data/flat_red.png").front());
64         BOOST_REQUIRE (!wait_for_jobs());
65         encrypted->set_encrypted (true);
66         make_and_verify_dcp (encrypted);
67
68         dcp::DCP encrypted_dcp (encrypted->dir(encrypted->dcp_name()));
69         encrypted_dcp.read ();
70
71         auto kdm = encrypted->make_kdm (
72                 Config::instance()->decryption_chain()->leaf(),
73                 vector<string>(),
74                 encrypted_dcp.cpls().front()->file().get(),
75                 dcp::LocalTime ("2030-07-21T00:00:00+00:00"),
76                 dcp::LocalTime ("2031-07-21T00:00:00+00:00"),
77                 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
78                 true, 0
79                 );
80
81
82         /* Add just the OV to a new project, move it around a bit and check that
83            the _reels get reused.
84         */
85         auto test = new_test_film2 ("check_reuse_old_data_test1");
86         ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
87         test->examine_and_add_content (ov_content);
88         BOOST_REQUIRE (!wait_for_jobs());
89         auto player = make_shared<Player>(test);
90
91         auto decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
92         BOOST_REQUIRE (decoder);
93         auto reels = decoder->reels();
94
95         ov_content->set_position (test, dcpomatic::DCPTime(96000));
96         decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
97         BOOST_REQUIRE (decoder);
98         BOOST_REQUIRE (reels == decoder->reels());
99
100         /* Add the VF to a new project, then add the OV and check that the
101            _reels did not get reused.
102         */
103         test = new_test_film2 ("check_reuse_old_data_test2");
104         auto vf_content = make_shared<DCPContent>(vf->dir(vf->dcp_name(false)));
105         test->examine_and_add_content (vf_content);
106         BOOST_REQUIRE (!wait_for_jobs());
107         player.reset (new Player(test));
108
109         decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
110         BOOST_REQUIRE (decoder);
111         reels = decoder->reels();
112
113         vf_content->add_ov (ov->dir(ov->dcp_name(false)));
114         JobManager::instance()->add (make_shared<ExamineContentJob>(test, vf_content));
115         BOOST_REQUIRE (!wait_for_jobs());
116         decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
117         BOOST_REQUIRE (decoder);
118         BOOST_REQUIRE (reels != decoder->reels());
119
120         /* Add a KDM to an encrypted DCP and check that the _reels did not get reused */
121         test = new_test_film2 ("check_reuse_old_data_test3");
122         auto encrypted_content = make_shared<DCPContent>(encrypted->dir(encrypted->dcp_name(false)));
123         test->examine_and_add_content (encrypted_content);
124         BOOST_REQUIRE (!wait_for_jobs());
125         player = make_shared<Player>(test);
126
127         decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
128         BOOST_REQUIRE (decoder);
129         reels = decoder->reels();
130
131         encrypted_content->add_kdm (kdm);
132         JobManager::instance()->add (make_shared<ExamineContentJob>(test, encrypted_content));
133         BOOST_REQUIRE (!wait_for_jobs());
134         decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
135         BOOST_REQUIRE (decoder);
136         BOOST_REQUIRE (reels != decoder->reels());
137 }