Clarify some documentation slightly.
[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() == DCPContentType::from_isdcf_name("TST"));
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_video_bit_rate(VideoEncoding::JPEG2000, 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<Glib::ustring> 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         Cleanup cl;
88
89         auto subs = content_factory("test/data/15s.srt")[0];
90         auto caps = content_factory("test/data/15s.srt")[0];
91         auto film = new_test_film("multiple_text_nodes_are_allowed1", { subs, caps }, &cl);
92         caps->only_text()->set_type(TextType::CLOSED_CAPTION);
93         make_and_verify_dcp (
94                 film,
95                 {
96                         dcp::VerificationNote::Code::MISSING_CPL_METADATA,
97                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
98                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
99                 });
100
101         auto reload = make_shared<DCPContent>(film->dir(film->dcp_name()));
102         auto film2 = new_test_film("multiple_text_nodes_are_allowed2", { reload });
103         film2->write_metadata ();
104
105         auto test = make_shared<Film>(boost::filesystem::path("build/test/multiple_text_nodes_are_allowed2"));
106         test->read_metadata();
107
108         cl.run();
109 }
110
111
112 /** Read some metadata from v2.14.x that fails to open on 2.15.x */
113 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_1)
114 {
115         namespace fs = boost::filesystem;
116         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_1");
117         fs::remove_all(dir);
118         auto film = make_shared<Film>(dir);
119         fs::copy_file("test/data/2.14.x.metadata.1.xml", dir / "metadata.xml");
120         auto notes = film->read_metadata(dir / "metadata.xml");
121         BOOST_REQUIRE_EQUAL (notes.size(), 0U);
122 }
123
124
125 /** Read some more metadata from v2.14.x that fails to open on 2.15.x */
126 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_2)
127 {
128         namespace fs = boost::filesystem;
129         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_2");
130         fs::remove_all(dir);
131         auto film = make_shared<Film>(dir);
132         fs::copy_file("test/data/2.14.x.metadata.2.xml", dir / "metadata.xml");
133         auto notes = film->read_metadata(dir / "metadata.xml");
134         BOOST_REQUIRE_EQUAL (notes.size(), 1U);
135         BOOST_REQUIRE_EQUAL (notes.front(),
136                        "A subtitle or closed caption file in this project is marked with the language 'eng', "
137                        "which DCP-o-matic does not recognise.  The file's language has been cleared."
138                        );
139 }
140
141
142 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_3)
143 {
144         namespace fs = boost::filesystem;
145         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_3");
146         fs::remove_all(dir);
147         auto film = make_shared<Film>(dir);
148         fs::copy_file("test/data/2.14.x.metadata.3.xml", dir / "metadata.xml");
149         auto notes = film->read_metadata(dir / "metadata.xml");
150
151         BOOST_REQUIRE (film->release_territory());
152         BOOST_REQUIRE (film->release_territory()->subtag() == dcp::LanguageTag::RegionSubtag("de").subtag());
153
154         BOOST_REQUIRE (film->audio_language());
155         BOOST_REQUIRE (*film->audio_language() == dcp::LanguageTag("sv-SE"));
156
157         BOOST_REQUIRE (film->content_versions() == vector<string>{"3"});
158         BOOST_REQUIRE (film->ratings() == vector<dcp::Rating>{ dcp::Rating("", "214rating") });
159         BOOST_REQUIRE_EQUAL (film->studio().get_value_or(""), "214studio");
160         BOOST_REQUIRE_EQUAL (film->facility().get_value_or(""), "214facility");
161         BOOST_REQUIRE_EQUAL (film->temp_version(), true);
162         BOOST_REQUIRE_EQUAL (film->pre_release(), true);
163         BOOST_REQUIRE_EQUAL (film->red_band(), true);
164         BOOST_REQUIRE_EQUAL (film->two_d_version_of_three_d(), true);
165         BOOST_REQUIRE_EQUAL (film->chain().get_value_or(""), "214chain");
166         BOOST_REQUIRE (film->luminance() == dcp::Luminance(14, dcp::Luminance::Unit::FOOT_LAMBERT));
167 }
168
169
170 /** Check that an empty <MasteredLuminance> tag results in the film's luminance being unset */
171 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_4)
172 {
173         namespace fs = boost::filesystem;
174         auto dir = fs::path("build/test/metadata_loads_from_2_14_x_4");
175         fs::remove_all(dir);
176         auto film = make_shared<Film>(dir);
177         fs::copy_file("test/data/2.14.x.metadata.4.xml", dir / "metadata.xml");
178         auto notes = film->read_metadata(dir / "metadata.xml");
179
180         BOOST_REQUIRE (!film->luminance());
181 }
182
183
184 BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_dcp)
185 {
186         namespace fs = boost::filesystem;
187         auto film = make_shared<Film>(fs::path("test/data/214x_dcp"));
188         film->read_metadata();
189
190         BOOST_REQUIRE_EQUAL(film->content().size(), 1U);
191         BOOST_REQUIRE(film->content()[0]->video);
192         BOOST_CHECK(film->content()[0]->video->range() == VideoRange::FULL);
193 }
194
195
196 BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_mp4_with_unknown_range)
197 {
198         namespace fs = boost::filesystem;
199         auto film = make_shared<Film>(fs::path("test/data/214x_mp4"));
200         film->read_metadata();
201
202         BOOST_REQUIRE_EQUAL(film->content().size(), 1U);
203         BOOST_REQUIRE(film->content()[0]->video);
204         BOOST_CHECK(film->content()[0]->video->range() == VideoRange::VIDEO);
205 }
206
207
208 BOOST_AUTO_TEST_CASE (metadata_video_range_guessed_for_png)
209 {
210         namespace fs = boost::filesystem;
211         auto film = make_shared<Film>(fs::path("test/data/214x_png"));
212         film->read_metadata();
213
214         BOOST_REQUIRE_EQUAL(film->content().size(), 1U);
215         BOOST_REQUIRE(film->content()[0]->video);
216         BOOST_CHECK(film->content()[0]->video->range() == VideoRange::FULL);
217 }
218
219
220 /* Bug #2581 */
221 BOOST_AUTO_TEST_CASE(effect_node_not_inserted_incorrectly)
222 {
223         auto sub = content_factory("test/data/15s.srt");
224         auto film = new_test_film("effect_node_not_inserted_incorrectly", sub);
225         film->write_metadata();
226
227         namespace fs = boost::filesystem;
228         auto film2 = make_shared<Film>(fs::path("build/test/effect_node_not_inserted_incorrectly"));
229         film2->read_metadata();
230         film2->write_metadata();
231
232         cxml::Document doc("Metadata");
233         doc.read_file("build/test/effect_node_not_inserted_incorrectly/metadata.xml");
234
235         /* There should be no <Effect> node in the text, since we don't want to force the effect to "none" */
236         BOOST_CHECK(!doc.node_child("Playlist")->node_child("Content")->node_child("Text")->optional_node_child("Effect"));
237 }
238