Add failing test.
[dcpomatic.git] / test / atmos_test.cc
1 /*
2     Copyright (C) 2020-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 #include "lib/config.h"
23 #include "lib/content.h"
24 #include "lib/content_factory.h"
25 #include "lib/dcp_content.h"
26 #include "lib/film.h"
27 #include "test.h"
28 #include <dcp/atmos_asset.h>
29 #include <dcp/cpl.h>
30 #include <dcp/dcp.h>
31 #include <dcp/reel.h>
32 #include <dcp/reel_atmos_asset.h>
33 #include <boost/test/unit_test.hpp>
34
35
36 using std::make_shared;
37 using std::shared_ptr;
38 using std::shared_ptr;
39 using std::string;
40 using std::vector;
41 using boost::optional;
42
43
44 BOOST_AUTO_TEST_CASE (atmos_passthrough_test)
45 {
46         Cleanup cl;
47
48         auto film = new_test_film2 (
49                 "atmos_passthrough_test",
50                 content_factory(TestPaths::private_data() / "atmos_asset.mxf"),
51                 &cl
52                 );
53
54         make_and_verify_dcp (film, {dcp::VerificationNote::Code::MISSING_CPL_METADATA});
55
56         auto ref = TestPaths::private_data() / "atmos_asset.mxf";
57         BOOST_REQUIRE (mxf_atmos_files_same(ref, dcp_file(film, "atmos"), true));
58
59         cl.run ();
60 }
61
62
63 BOOST_AUTO_TEST_CASE (atmos_encrypted_passthrough_test)
64 {
65         Cleanup cl;
66
67         auto ref = TestPaths::private_data() / "atmos_asset.mxf";
68         auto content = content_factory(TestPaths::private_data() / "atmos_asset.mxf");
69         auto film = new_test_film2 ("atmos_encrypted_passthrough_test", content, &cl);
70
71         film->set_encrypted (true);
72         film->_key = dcp::Key ("4fac12927eb122af1c2781aa91f3a4cc");
73         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
74
75         BOOST_REQUIRE (!mxf_atmos_files_same(ref, dcp_file(film, "atmos")));
76
77         auto kdm = film->make_kdm (
78                 Config::instance()->decryption_chain()->leaf(),
79                 vector<string>(),
80                 dcp_file(film, "cpl"),
81                 dcp::LocalTime(),
82                 dcp::LocalTime(),
83                 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
84                 false,
85                 optional<int>()
86                 );
87
88         auto content2 = make_shared<DCPContent>(film->dir(film->dcp_name()));
89         content2->add_kdm (kdm);
90         auto film2 = new_test_film2 ("atmos_encrypted_passthrough_test2", {content2}, &cl);
91         make_and_verify_dcp (film2, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
92
93         BOOST_CHECK (mxf_atmos_files_same(ref, dcp_file(film2, "atmos"), true));
94
95         cl.run ();
96 }
97
98
99 BOOST_AUTO_TEST_CASE (atmos_trim_test)
100 {
101         Cleanup cl;
102
103         auto ref = TestPaths::private_data() / "atmos_asset.mxf";
104         auto content = content_factory(TestPaths::private_data() / "atmos_asset.mxf");
105         auto film = new_test_film2 ("atmos_trim_test", content, &cl);
106
107         content[0]->set_trim_start(film, dcpomatic::ContentTime::from_seconds(1));
108
109         /* Just check that the encode runs; I'm not sure how to test the MXF */
110         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
111 }
112
113
114 BOOST_AUTO_TEST_CASE(atmos_replace_test)
115 {
116         auto const frames = 240;
117
118         auto check = [](shared_ptr<const Film> film, int data) {
119                 dcp::DCP dcp(film->dir(film->dcp_name()));
120                 dcp.read();
121                 BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
122                 BOOST_REQUIRE_EQUAL(dcp.cpls()[0]->reels().size(), 1U);
123                 BOOST_REQUIRE(dcp.cpls()[0]->reels()[0]->atmos());
124                 auto asset = dcp.cpls()[0]->reels()[0]->atmos()->asset();
125                 BOOST_REQUIRE(asset);
126                 auto reader = asset->start_read();
127                 for (int i = 0; i < frames; ++i) {
128                         auto frame = reader->get_frame(i);
129                         BOOST_REQUIRE(frame);
130                         for (int j = 0; j < frame->size(); ++j) {
131                                 BOOST_REQUIRE_EQUAL(frame->data()[j], data);
132                         }
133                 }
134         };
135
136         auto atmos_0 = content_factory("test/data/atmos_0.mxf");
137         auto ov = new_test_film2("atmos_merge_test_ov", atmos_0);
138         make_and_verify_dcp(ov, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
139         // atmos_0.mxf should contain all zeros for its data
140         check(ov, 0);
141
142         auto atmos_1 = content_factory("test/data/atmos_1.mxf");
143         auto ov_content = std::make_shared<DCPContent>(boost::filesystem::path("build/test/atmos_merge_test_ov") / ov->dcp_name());
144         auto vf = new_test_film2("atmos_merge_test_vf", { ov_content, atmos_1.front() });
145         ov_content->set_reference_video(true);
146         atmos_1.front()->set_position(vf, dcpomatic::DCPTime());
147         make_and_verify_dcp(vf, { dcp::VerificationNote::Code::MISSING_CPL_METADATA, dcp::VerificationNote::Code::EXTERNAL_ASSET });
148         // atmos_1.mxf should contain all ones for its data, and it should have replaced atmos_0 in this DCP
149         check(vf, 1);
150 }
151