2 Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 /** @file test/film_metadata_test.cc
23 * @brief Test some basic reading/writing of film metadata.
28 #include "lib/content.h"
29 #include "lib/content_factory.h"
30 #include "lib/dcp_content.h"
31 #include "lib/dcp_content_type.h"
33 #include "lib/ratio.h"
34 #include "lib/text_content.h"
36 #include <boost/date_time.hpp>
37 #include <boost/filesystem.hpp>
38 #include <boost/test/unit_test.hpp>
43 using std::make_shared;
47 BOOST_AUTO_TEST_CASE (film_metadata_test)
49 auto film = new_test_film ("film_metadata_test");
50 auto dir = test_film_dir ("film_metadata_test");
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);
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 ();
67 list<string> ignore = { "Key", "ContextID", "LastWrittenBy" };
68 check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
70 auto g = make_shared<Film>(dir);
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"));
78 check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
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)
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);
92 dcp::VerificationNote::Code::MISSING_CPL_METADATA,
93 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
94 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
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 ();
101 auto test = make_shared<Film>(boost::filesystem::path("build/test/multiple_text_nodes_are_allowed2"));
102 test->read_metadata();
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)
109 namespace fs = boost::filesystem;
110 auto dir = fs::path("build/test/metadata_loads_from_2_14_x_1");
112 auto film = make_shared<Film>(dir);
113 fs::copy_file("test/data/2.14.x.metadata.1.xml", dir / "metadata.xml");
114 auto notes = film->read_metadata(dir / "metadata.xml");
115 BOOST_REQUIRE_EQUAL (notes.size(), 0U);
119 /** Read some more metadata from v2.14.x that fails to open on 2.15.x */
120 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_2)
122 namespace fs = boost::filesystem;
123 auto dir = fs::path("build/test/metadata_loads_from_2_14_x_2");
125 auto film = make_shared<Film>(dir);
126 fs::copy_file("test/data/2.14.x.metadata.2.xml", dir / "metadata.xml");
127 auto notes = film->read_metadata(dir / "metadata.xml");
128 BOOST_REQUIRE_EQUAL (notes.size(), 1U);
129 BOOST_REQUIRE_EQUAL (notes.front(),
130 "A subtitle or closed caption file in this project is marked with the language 'eng', "
131 "which DCP-o-matic does not recognise. The file's language has been cleared."
136 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_3)
138 namespace fs = boost::filesystem;
139 auto dir = fs::path("build/test/metadata_loads_from_2_14_x_3");
141 auto film = make_shared<Film>(dir);
142 fs::copy_file("test/data/2.14.x.metadata.3.xml", dir / "metadata.xml");
143 auto notes = film->read_metadata(dir / "metadata.xml");
145 BOOST_REQUIRE (film->release_territory());
146 BOOST_REQUIRE (film->release_territory()->subtag() == dcp::LanguageTag::RegionSubtag("de").subtag());
148 BOOST_REQUIRE (film->audio_language());
149 BOOST_REQUIRE (*film->audio_language() == dcp::LanguageTag("sv-SE"));
151 BOOST_REQUIRE (film->content_versions() == vector<string>{"3"});
152 BOOST_REQUIRE (film->ratings() == vector<dcp::Rating>{ dcp::Rating("", "214rating") });
153 BOOST_REQUIRE_EQUAL (film->studio().get_value_or(""), "214studio");
154 BOOST_REQUIRE_EQUAL (film->facility().get_value_or(""), "214facility");
155 BOOST_REQUIRE_EQUAL (film->temp_version(), true);
156 BOOST_REQUIRE_EQUAL (film->pre_release(), true);
157 BOOST_REQUIRE_EQUAL (film->red_band(), true);
158 BOOST_REQUIRE_EQUAL (film->two_d_version_of_three_d(), true);
159 BOOST_REQUIRE_EQUAL (film->chain().get_value_or(""), "214chain");
160 BOOST_REQUIRE (film->luminance() == dcp::Luminance(14, dcp::Luminance::Unit::FOOT_LAMBERT));
164 /** Check that an empty <MasteredLuminance> tag results in the film's luminance being unset */
165 BOOST_AUTO_TEST_CASE (metadata_loads_from_2_14_x_4)
167 namespace fs = boost::filesystem;
168 auto dir = fs::path("build/test/metadata_loads_from_2_14_x_4");
170 auto film = make_shared<Film>(dir);
171 fs::copy_file("test/data/2.14.x.metadata.4.xml", dir / "metadata.xml");
172 auto notes = film->read_metadata(dir / "metadata.xml");
174 BOOST_REQUIRE (!film->luminance());