Fix position of content outline (#2108).
[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 "test.h"
36 #include <boost/date_time.hpp>
37 #include <boost/filesystem.hpp>
38 #include <boost/test/unit_test.hpp>
39
40
41 using std::string;
42 using std::list;
43 using std::make_shared;
44 using std::vector;
45
46
47 BOOST_AUTO_TEST_CASE (film_metadata_test)
48 {
49         auto film = new_test_film ("film_metadata_test");
50         auto dir = test_film_dir ("film_metadata_test");
51
52         film->_isdcf_date = boost::gregorian::from_undelimited_string ("20130211");
53         BOOST_CHECK (film->container() == Ratio::from_id ("185"));
54         BOOST_CHECK (film->dcp_content_type() == nullptr);
55
56         film->set_name ("fred");
57         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("SHR"));
58         film->set_container (Ratio::from_id ("185"));
59         film->set_j2k_bandwidth (200000000);
60         film->set_interop (false);
61         film->set_chain (string(""));
62         film->set_distributor (string(""));
63         film->set_facility (string(""));
64         film->set_release_territory (dcp::LanguageTag::RegionSubtag("US"));
65         film->write_metadata ();
66
67         list<string> ignore = { "Key", "ContextID", "LastWrittenBy" };
68         check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
69
70         auto g = make_shared<Film>(dir);
71         g->read_metadata ();
72
73         BOOST_CHECK_EQUAL (g->name(), "fred");
74         BOOST_CHECK_EQUAL (g->dcp_content_type(), DCPContentType::from_isdcf_name ("SHR"));
75         BOOST_CHECK_EQUAL (g->container(), Ratio::from_id ("185"));
76
77         g->write_metadata ();
78         check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
79 }
80
81
82 /** Check a bug where <Content> tags with multiple <Text>s would fail to load */
83 BOOST_AUTO_TEST_CASE (multiple_text_nodes_are_allowed)
84 {
85         auto subs = content_factory("test/data/15s.srt").front();
86         auto caps = content_factory("test/data/15s.srt").front();
87         auto film = new_test_film2("multiple_text_nodes_are_allowed1", { subs, caps });
88         caps->only_text()->set_type(TextType::CLOSED_CAPTION);
89         make_and_verify_dcp (
90                 film,
91                 {
92                         dcp::VerificationNote::Code::MISSING_CPL_METADATA,
93                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
94                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
95                 });
96
97         auto reload = make_shared<DCPContent>(film->dir(film->dcp_name()));
98         auto film2 = new_test_film2("multiple_text_nodes_are_allowed2", { reload });
99         film2->write_metadata ();
100
101         auto test = make_shared<Film>(boost::filesystem::path("build/test/multiple_text_nodes_are_allowed2"));
102         test->read_metadata();
103 }
104
105
106 /** Read some metadata from v2.14.x that fails to open on 2.15.x */
107 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_1)
108 {
109         namespace fs = boost::filesystem;
110         auto film = make_shared<Film>(fs::path("build/test/metadata_loads_from_2_14_x_1"));
111         auto notes = film->read_metadata(fs::path("test/data/2.14.x.metadata.1.xml"));
112         BOOST_REQUIRE_EQUAL (notes.size(), 0U);
113 }
114
115
116 /** Read some more metadata from v2.14.x that fails to open on 2.15.x */
117 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_2)
118 {
119         namespace fs = boost::filesystem;
120         auto film = make_shared<Film>(fs::path("build/test/metadata_loads_from_2_14_x_2"));
121         auto notes = film->read_metadata(fs::path("test/data/2.14.x.metadata.2.xml"));
122         BOOST_REQUIRE_EQUAL (notes.size(), 1U);
123         BOOST_REQUIRE_EQUAL (notes.front(),
124                        "A subtitle or closed caption file in this project is marked with the language 'eng', "
125                        "which DCP-o-matic does not recognise.  The file's language has been cleared."
126                        );
127 }
128
129
130 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_3)
131 {
132         namespace fs = boost::filesystem;
133         auto film = make_shared<Film>(fs::path("build/test/metadata_loads_from_2_14_x_3"));
134         auto notes = film->read_metadata(fs::path("test/data/2.14.x.metadata.3.xml"));
135
136         BOOST_REQUIRE (film->release_territory());
137         BOOST_REQUIRE (film->release_territory()->subtag() == dcp::LanguageTag::RegionSubtag("de").subtag());
138
139         BOOST_REQUIRE (film->audio_language());
140         BOOST_REQUIRE (*film->audio_language() == dcp::LanguageTag("sv-SE"));
141
142         BOOST_REQUIRE (film->content_versions() == vector<string>{"3"});
143         BOOST_REQUIRE (film->ratings() == vector<dcp::Rating>{ dcp::Rating("", "214rating") });
144         BOOST_REQUIRE_EQUAL (film->studio().get_value_or(""), "214studio");
145         BOOST_REQUIRE_EQUAL (film->facility().get_value_or(""), "214facility");
146         BOOST_REQUIRE_EQUAL (film->temp_version(), true);
147         BOOST_REQUIRE_EQUAL (film->pre_release(), true);
148         BOOST_REQUIRE_EQUAL (film->red_band(), true);
149         BOOST_REQUIRE_EQUAL (film->two_d_version_of_three_d(), true);
150         BOOST_REQUIRE_EQUAL (film->chain().get_value_or(""), "214chain");
151         BOOST_REQUIRE (film->luminance() == dcp::Luminance(14, dcp::Luminance::Unit::FOOT_LAMBERT));
152 }
153