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