Take Film pointer out of Content.
[dcpomatic.git] / test / vf_kdm_test.cc
1 /*
2     Copyright (C) 2017 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 /** @file  test/vf_kdm_test.cc
22  *  @brief Test encrypted VF creation and import
23  *  @ingroup specific
24  */
25
26 #include "test.h"
27 #include "lib/film.h"
28 #include "lib/dcp_subtitle_content.h"
29 #include "lib/ratio.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/dcp_content.h"
32 #include "lib/ffmpeg_content.h"
33 #include "lib/config.h"
34 #include "lib/cross.h"
35 #include "lib/screen.h"
36 #include <dcp/cpl.h>
37 #include <boost/test/unit_test.hpp>
38
39 using std::vector;
40 using std::string;
41 using boost::shared_ptr;
42
43 BOOST_AUTO_TEST_CASE (vf_kdm_test)
44 {
45         /* Make an encrypted DCP from test.mp4 */
46
47         shared_ptr<Film> A = new_test_film ("vf_kdm_test_ov");
48         A->set_container (Ratio::from_id ("185"));
49         A->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
50         A->set_name ("frobozz");
51         A->set_interop (true);
52
53         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
54         A->examine_and_add_content (c);
55         A->set_encrypted (true);
56         wait_for_jobs ();
57         A->make_dcp ();
58         wait_for_jobs ();
59
60         dcp::DCP A_dcp ("build/test/vf_kdm_test_ov/" + A->dcp_name());
61         A_dcp.read ();
62
63         Config::instance()->set_decryption_chain (shared_ptr<dcp::CertificateChain> (new dcp::CertificateChain (openssl_path ())));
64
65         dcp::EncryptedKDM A_kdm = A->make_kdm (
66                 Config::instance()->decryption_chain()->leaf (),
67                 vector<string>(),
68                 A_dcp.cpls().front()->file().get(),
69                 dcp::LocalTime ("2014-07-21T00:00:00+00:00"),
70                 dcp::LocalTime ("2024-07-21T00:00:00+00:00"),
71                 dcp::MODIFIED_TRANSITIONAL_1,
72                 true, 0
73                 );
74
75         /* Import A into a new project, with the required KDM, and make a VF that refers to it */
76
77         shared_ptr<Film> B = new_test_film ("vf_kdm_test_vf");
78         B->set_container (Ratio::from_id ("185"));
79         B->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
80         B->set_name ("frobozz");
81         B->set_interop (true);
82
83         shared_ptr<DCPContent> d (new DCPContent ("build/test/vf_kdm_test_ov/" + A->dcp_name()));
84         d->add_kdm (A_kdm);
85         d->set_reference_video (true);
86         B->examine_and_add_content (d);
87         B->set_encrypted (true);
88         wait_for_jobs ();
89         B->make_dcp ();
90         wait_for_jobs ();
91
92         dcp::DCP B_dcp ("build/test/vf_kdm_test_vf/" + B->dcp_name());
93         B_dcp.read ();
94
95         dcp::EncryptedKDM B_kdm = B->make_kdm (
96                 Config::instance()->decryption_chain()->leaf (),
97                 vector<string>(),
98                 B_dcp.cpls().front()->file().get(),
99                 dcp::LocalTime ("2014-07-21T00:00:00+00:00"),
100                 dcp::LocalTime ("2024-07-21T00:00:00+00:00"),
101                 dcp::MODIFIED_TRANSITIONAL_1,
102                 true, 0
103                 );
104
105         /* Import the OV and VF into a new project with the KDM that was created for the VF.
106            This KDM should decrypt assets from the OV too.
107         */
108
109         shared_ptr<Film> C = new_test_film ("vf_kdm_test_check");
110         C->set_container (Ratio::from_id ("185"));
111         C->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
112         C->set_name ("frobozz");
113         C->set_interop (true);
114
115         shared_ptr<DCPContent> e (new DCPContent ("build/test/vf_kdm_test_vf/" + B->dcp_name()));
116         e->add_kdm (B_kdm);
117         e->add_ov ("build/test/vf_kdm_test_ov/" + A->dcp_name());
118         C->examine_and_add_content (e);
119         wait_for_jobs ();
120         C->make_dcp ();
121         wait_for_jobs ();
122
123         /* Should be 1s red, 1s green, 1s blue */
124         check_dcp ("test/data/vf_kdm_test_check", "build/test/vf_kdm_test_check/" + C->dcp_name());
125 }