Supporters update.
[dcpomatic.git] / test / film_metadata_test.cc
1 /*
2     Copyright (C) 2013-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
22 /** @file  test/film_metadata_test.cc
23  *  @brief Test some basic reading/writing of film metadata.
24  *  @ingroup feature
25  */
26
27
28 #include "lib/content.h"
29 #include "lib/content_factory.h"
30 #include "lib/dcp_content.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/film.h"
33 #include "lib/ratio.h"
34 #include "lib/text_content.h"
35 #include "lib/video_content.h"
36 #include "test.h"
37 #include <boost/date_time.hpp>
38 #include <boost/filesystem.hpp>
39 #include <boost/test/unit_test.hpp>
40
41
42 using std::string;
43 using std::list;
44 using std::make_shared;
45 using std::vector;
46
47
48 BOOST_AUTO_TEST_CASE (film_metadata_test)
49 {
50         auto film = new_test_film ("film_metadata_test");
51         auto dir = test_film_dir ("film_metadata_test");
52
53         film->_isdcf_date = boost::gregorian::from_undelimited_string ("20130211");
54         BOOST_CHECK (film->container() == Ratio::from_id ("185"));
55         BOOST_CHECK (film->dcp_content_type() == nullptr);
56
57         film->set_name ("fred");
58         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("SHR"));
59         film->set_container (Ratio::from_id ("185"));
60         film->set_j2k_bandwidth (200000000);
61         film->set_interop (false);
62         film->set_chain (string(""));
63         film->set_distributor (string(""));
64         film->set_facility (string(""));
65         film->set_release_territory (dcp::LanguageTag::RegionSubtag("US"));
66         film->set_audio_channels(6);
67         film->write_metadata ();
68
69         list<string> ignore = { "Key", "ContextID", "LastWrittenBy" };
70         check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
71
72         auto g = make_shared<Film>(dir);
73         g->read_metadata ();
74
75         BOOST_CHECK_EQUAL (g->name(), "fred");
76         BOOST_CHECK_EQUAL (g->dcp_content_type(), DCPContentType::from_isdcf_name ("SHR"));
77         BOOST_CHECK_EQUAL (g->container(), Ratio::from_id ("185"));
78
79         g->write_metadata ();
80         check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
81 }
82
83
84 /** Check a bug where <Content> tags with multiple <Text>s would fail to load */
85 BOOST_AUTO_TEST_CASE (multiple_text_nodes_are_allowed)
86 {
87         auto subs = content_factory("test/data/15s.srt")[0];
88         auto caps = content_factory("test/data/15s.srt")[0];
89         auto film = new_test_film2("multiple_text_nodes_are_allowed1", { subs, caps });
90         caps->only_text()->set_type(TextType::CLOSED_CAPTION);
91         make_and_verify_dcp (
92                 film,
93                 {
94                         dcp::VerificationNote::Code::MISSING_CPL_METADATA,
95                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
96                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
97                 });
98
99         auto reload = make_shared<DCPContent>(film->dir(film->dcp_name()));
100         auto film2 = new_test_film2("multiple_text_nodes_are_allowed2", { reload });
101         film2->write_metadata ();
102
103         auto test = make_shared<Film>(boost::filesystem::path("build/test/multiple_text_nodes_are_allowed2"));
104         test->read_metadata();
105 }
106
107
108 /** Read some metadata from v2.14.x that fails to open on 2.15.x */
109 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_1)
110 {
111         namespace fs = boost::filesystem;
112         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_1");
113         fs::remove_all(dir);
114         auto film = make_shared<Film>(dir);
115         fs::copy_file("test/data/2.14.x.metadata.1.xml", dir / "metadata.xml");
116         auto notes = film->read_metadata(dir / "metadata.xml");
117         BOOST_REQUIRE_EQUAL (notes.size(), 0U);
118 }
119
120
121 /** Read some more metadata from v2.14.x that fails to open on 2.15.x */
122 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_2)
123 {
124         namespace fs = boost::filesystem;
125         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_2");
126         fs::remove_all(dir);
127         auto film = make_shared<Film>(dir);
128         fs::copy_file("test/data/2.14.x.metadata.2.xml", dir / "metadata.xml");
129         auto notes = film->read_metadata(dir / "metadata.xml");
130         BOOST_REQUIRE_EQUAL (notes.size(), 1U);
131         BOOST_REQUIRE_EQUAL (notes.front(),
132                        "A subtitle or closed caption file in this project is marked with the language 'eng', "
133                        "which DCP-o-matic does not recognise.  The file's language has been cleared."
134                        );
135 }
136
137
138 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_3)
139 {
140         namespace fs = boost::filesystem;
141         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_3");
142         fs::remove_all(dir);
143         auto film = make_shared<Film>(dir);
144         fs::copy_file("test/data/2.14.x.metadata.3.xml", dir / "metadata.xml");
145         auto notes = film->read_metadata(dir / "metadata.xml");
146
147         BOOST_REQUIRE (film->release_territory());
148         BOOST_REQUIRE (film->release_territory()->subtag() == dcp::LanguageTag::RegionSubtag("de").subtag());
149
150         BOOST_REQUIRE (film->audio_language());
151         BOOST_REQUIRE (*film->audio_language() == dcp::LanguageTag("sv-SE"));
152
153         BOOST_REQUIRE (film->content_versions() == vector<string>{"3"});
154         BOOST_REQUIRE (film->ratings() == vector<dcp::Rating>{ dcp::Rating("", "214rating") });
155         BOOST_REQUIRE_EQUAL (film->studio().get_value_or(""), "214studio");
156         BOOST_REQUIRE_EQUAL (film->facility().get_value_or(""), "214facility");
157         BOOST_REQUIRE_EQUAL (film->temp_version(), true);
158         BOOST_REQUIRE_EQUAL (film->pre_release(), true);
159         BOOST_REQUIRE_EQUAL (film->red_band(), true);
160         BOOST_REQUIRE_EQUAL (film->two_d_version_of_three_d(), true);
161         BOOST_REQUIRE_EQUAL (film->chain().get_value_or(""), "214chain");
162         BOOST_REQUIRE (film->luminance() == dcp::Luminance(14, dcp::Luminance::Unit::FOOT_LAMBERT));
163 }
164
165
166 /** Check that an empty <MasteredLuminance> tag results in the film's luminance being unset */
167 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_4)
168 {
169         namespace fs = boost::filesystem;
170         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_4");
171         fs::remove_all(dir);
172         auto film = make_shared<Film>(dir);
173         fs::copy_file("test/data/2.14.x.metadata.4.xml", dir / "metadata.xml");
174         auto notes = film->read_metadata(dir / "metadata.xml");
175
176         BOOST_REQUIRE (!film->luminance());
177 }
178
179
180 BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_dcp)
181 {
182         namespace fs = boost::filesystem;
183         auto film = make_shared<Film>(fs::path("test/data/214x_dcp"));
184         film->read_metadata();
185
186         BOOST_REQUIRE_EQUAL(film->content().size(), 1U);
187         BOOST_REQUIRE(film->content()[0]->video);
188         BOOST_CHECK(film->content()[0]->video->range() == VideoRange::FULL);
189 }
190
191
192 BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_mp4_with_unknown_range)
193 {
194         namespace fs = boost::filesystem;
195         auto film = make_shared<Film>(fs::path("test/data/214x_mp4"));
196         film->read_metadata();
197
198         BOOST_REQUIRE_EQUAL(film->content().size(), 1U);
199         BOOST_REQUIRE(film->content()[0]->video);
200         BOOST_CHECK(film->content()[0]->video->range() == VideoRange::VIDEO);
201 }
202
203
204 BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_png)
205 {
206         namespace fs = boost::filesystem;
207         auto film = make_shared<Film>(fs::path("test/data/214x_png"));
208         film->read_metadata();
209
210         BOOST_REQUIRE_EQUAL(film->content().size(), 1U);
211         BOOST_REQUIRE(film->content()[0]->video);
212         BOOST_CHECK(film->content()[0]->video->range() == VideoRange::FULL);
213 }
214
215
216 /* Bug #2581 */
217 BOOST_AUTO_TEST_CASE(effect_node_not_inserted_incorrectly)
218 {
219         auto sub = content_factory("test/data/15s.srt");
220         auto film = new_test_film2("effect_node_not_inserted_incorrectly", sub);
221         film->write_metadata();
222
223         namespace fs = boost::filesystem;
224         auto film2 = make_shared<Film>(fs::path("build/test/effect_node_not_inserted_incorrectly"));
225         film2->read_metadata();
226         film2->write_metadata();
227
228         cxml::Document doc("Metadata");
229         doc.read_file("build/test/effect_node_not_inserted_incorrectly/metadata.xml");
230
231         /* There should be no <Effect> node in the text, since we don't want to force the effect to "none" */
232         BOOST_CHECK(!doc.node_child("Playlist")->node_child("Content")->node_child("Text")->optional_node_child("Effect"));
233 }
234