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