Take Film pointer out of Content.
[dcpomatic.git] / test / import_dcp_test.cc
1 /*
2     Copyright (C) 2014 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/import_dcp_test.cc
22  *  @brief Test import of encrypted DCPs.
23  *  @ingroup specific
24  */
25
26 #include "test.h"
27 #include "lib/film.h"
28 #include "lib/screen.h"
29 #include "lib/dcp_subtitle_content.h"
30 #include "lib/ratio.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/dcp_content.h"
33 #include "lib/ffmpeg_content.h"
34 #include "lib/examine_content_job.h"
35 #include "lib/job_manager.h"
36 #include "lib/config.h"
37 #include "lib/cross.h"
38 #include <dcp/cpl.h>
39 #include <boost/test/unit_test.hpp>
40
41 using std::vector;
42 using std::string;
43 using boost::shared_ptr;
44
45 /** Make an encrypted DCP, import it and make a new unencrypted DCP */
46 BOOST_AUTO_TEST_CASE (import_dcp_test)
47 {
48         shared_ptr<Film> A = new_test_film ("import_dcp_test");
49         A->set_container (Ratio::from_id ("185"));
50         A->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
51         A->set_name ("frobozz");
52         A->set_interop (false);
53
54         shared_ptr<FFmpegContent> c (new FFmpegContent("test/data/test.mp4"));
55         A->examine_and_add_content (c);
56         A->set_encrypted (true);
57         BOOST_CHECK (!wait_for_jobs ());
58
59         A->make_dcp ();
60         BOOST_CHECK (!wait_for_jobs ());
61
62         dcp::DCP A_dcp ("build/test/import_dcp_test/" + A->dcp_name());
63         A_dcp.read ();
64
65         Config::instance()->set_decryption_chain (shared_ptr<dcp::CertificateChain> (new dcp::CertificateChain (openssl_path ())));
66
67         dcp::EncryptedKDM kdm = A->make_kdm (
68                 Config::instance()->decryption_chain()->leaf (),
69                 vector<string>(),
70                 A_dcp.cpls().front()->file().get(),
71                 dcp::LocalTime ("2014-07-21T00:00:00+00:00"),
72                 dcp::LocalTime ("2024-07-21T00:00:00+00:00"),
73                 dcp::MODIFIED_TRANSITIONAL_1,
74                 true, 0
75                 );
76
77         shared_ptr<Film> B = new_test_film ("import_dcp_test2");
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 (false);
82
83         shared_ptr<DCPContent> d (new DCPContent("build/test/import_dcp_test/" + A->dcp_name()));
84         B->examine_and_add_content (d);
85         BOOST_CHECK (!wait_for_jobs ());
86         d->add_kdm (kdm);
87         JobManager::instance()->add (shared_ptr<Job> (new ExamineContentJob (B, d)));
88         BOOST_CHECK (!wait_for_jobs ());
89
90         B->make_dcp ();
91         BOOST_CHECK (!wait_for_jobs ());
92
93         /* Should be 1s red, 1s green, 1s blue */
94         check_dcp ("test/data/import_dcp_test2", "build/test/import_dcp_test2/" + B->dcp_name());
95 }