2 Copyright (C) 2014-2021 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/dcp_subtitle_test.cc
23 * @brief Test DCP subtitle content in various ways.
28 #include <boost/test/unit_test.hpp>
30 #include "lib/dcp_subtitle_content.h"
31 #include "lib/dcp_content.h"
32 #include "lib/ratio.h"
33 #include "lib/dcp_decoder.h"
34 #include "lib/dcp_content_type.h"
35 #include "lib/dcp_subtitle_decoder.h"
36 #include "lib/text_content.h"
37 #include "lib/content_text.h"
39 #include "lib/text_decoder.h"
46 using std::make_shared;
47 using std::shared_ptr;
49 using boost::optional;
50 #if BOOST_VERSION >= 106100
51 using namespace boost::placeholders;
53 using namespace dcpomatic;
56 optional<ContentStringText> stored;
60 store (ContentStringText sub)
65 for (auto i: sub.subs) {
66 stored->subs.push_back (i);
72 /** Test pass-through of a very simple DCP subtitle file */
73 BOOST_AUTO_TEST_CASE (dcp_subtitle_test)
75 auto film = new_test_film ("dcp_subtitle_test");
76 film->set_container (Ratio::from_id ("185"));
77 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
78 film->set_name ("frobozz");
79 film->set_interop (false);
80 auto content = make_shared<DCPSubtitleContent>("test/data/dcp_sub.xml");
81 film->examine_and_add_content (content);
82 BOOST_REQUIRE (!wait_for_jobs ());
84 BOOST_CHECK_EQUAL (content->full_length(film).get(), DCPTime::from_seconds(2).get());
86 content->only_text()->set_use (true);
87 content->only_text()->set_burn (false);
91 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
92 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
93 dcp::VerificationNote::Code::MISSING_CPL_METADATA
96 check_dcp ("test/data/dcp_subtitle_test", film->dir(film->dcp_name()));
100 /** Test parsing of a subtitle within an existing DCP */
101 BOOST_AUTO_TEST_CASE (dcp_subtitle_within_dcp_test)
103 auto film = new_test_film ("dcp_subtitle_within_dcp_test");
104 film->set_container (Ratio::from_id ("185"));
105 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
106 film->set_name ("frobozz");
107 auto content = make_shared<DCPContent>(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV");
108 film->examine_and_add_content (content);
109 BOOST_REQUIRE (!wait_for_jobs ());
111 shared_ptr<DCPDecoder> decoder (new DCPDecoder (film, content, false, false, shared_ptr<DCPDecoder>()));
112 decoder->only_text()->PlainStart.connect (bind (store, _1));
114 stored = optional<ContentStringText> ();
115 while (!decoder->pass() && !stored) {}
117 BOOST_REQUIRE (stored);
118 BOOST_REQUIRE_EQUAL (stored->subs.size(), 2U);
119 BOOST_CHECK_EQUAL (stored->subs.front().text(), "Noch mal.");
120 BOOST_CHECK_EQUAL (stored->subs.back().text(), "Encore une fois.");
123 /** Test subtitles whose text includes things like <b> */
124 BOOST_AUTO_TEST_CASE (dcp_subtitle_test2)
126 auto film = new_test_film ("dcp_subtitle_test2");
127 film->set_container (Ratio::from_id ("185"));
128 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
129 film->set_name ("frobozz");
130 auto content = make_shared<DCPSubtitleContent>("test/data/dcp_sub2.xml");
131 film->examine_and_add_content (content);
132 BOOST_REQUIRE (!wait_for_jobs ());
134 auto decoder = make_shared<DCPSubtitleDecoder>(film, content);
135 decoder->only_text()->PlainStart.connect (bind (store, _1));
137 stored = optional<ContentStringText> ();
138 while (!decoder->pass()) {
139 if (stored && stored->from() == ContentTime(0)) {
140 BOOST_CHECK_EQUAL (stored->subs.front().text(), "<b>Hello world!</b>");
146 /** Test a failure case */
147 BOOST_AUTO_TEST_CASE (dcp_subtitle_test3)
149 auto film = new_test_film ("dcp_subtitle_test3");
150 film->set_container (Ratio::from_id ("185"));
151 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
152 film->set_name ("frobozz");
153 film->set_interop (true);
154 auto content = make_shared<DCPSubtitleContent>("test/data/dcp_sub3.xml");
155 film->examine_and_add_content (content);
156 BOOST_REQUIRE (!wait_for_jobs ());
158 make_and_verify_dcp (film, { dcp::VerificationNote::Code::INVALID_STANDARD });
160 auto decoder = make_shared<DCPSubtitleDecoder>(film, content);
161 stored = optional<ContentStringText> ();
162 while (!decoder->pass ()) {
163 decoder->only_text()->PlainStart.connect (bind (store, _1));
164 if (stored && stored->from() == ContentTime::from_seconds(0.08)) {
165 auto s = stored->subs;
167 BOOST_CHECK_EQUAL (i->text(), "This");
169 BOOST_REQUIRE (i != s.end ());
170 BOOST_CHECK_EQUAL (i->text(), " is ");
172 BOOST_REQUIRE (i != s.end ());
173 BOOST_CHECK_EQUAL (i->text(), "wrong.");
175 BOOST_REQUIRE (i == s.end ());
181 /** Check that Interop DCPs aren't made with more than one <LoadFont> (#1273) */
182 BOOST_AUTO_TEST_CASE (dcp_subtitle_test4)
184 auto content = make_shared<DCPSubtitleContent>("test/data/dcp_sub3.xml");
185 auto content2 = make_shared<DCPSubtitleContent>("test/data/dcp_sub3.xml");
186 auto film = new_test_film2 ("dcp_subtitle_test4", {content, content2});
187 film->set_interop (true);
189 content->only_text()->add_font(make_shared<Font>("font1"));
190 content2->only_text()->add_font(make_shared<Font>("font2"));
192 make_and_verify_dcp (film, { dcp::VerificationNote::Code::INVALID_STANDARD });
194 cxml::Document doc ("DCSubtitle");
195 doc.read_file (subtitle_file (film));
196 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1U);
202 check_font_tags (vector<cxml::NodePtr> nodes)
204 for (auto i: nodes) {
205 if (i->name() == "Font") {
206 BOOST_CHECK (!i->optional_string_attribute("Id") || i->string_attribute("Id") != "");
208 check_font_tags (i->node_children());
213 /** Check that imported <LoadFont> tags with empty IDs (or corresponding Font tags with empty IDs)
214 * are not passed through into the DCP.
216 BOOST_AUTO_TEST_CASE (dcp_subtitle_test5)
218 auto content = make_shared<DCPSubtitleContent>("test/data/dcp_sub6.xml");
219 auto film = new_test_film2 ("dcp_subtitle_test5", {content});
220 film->set_interop (true);
222 make_and_verify_dcp (film, { dcp::VerificationNote::Code::INVALID_STANDARD });
224 cxml::Document doc ("DCSubtitle");
225 doc.read_file (subtitle_file(film));
226 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1U);
227 BOOST_CHECK (doc.node_children("LoadFont").front()->string_attribute("Id") != "");
229 check_font_tags (doc.node_children());
233 /** Check that fonts specified in the DoM content are used in the output and not ignored (#2074) */
234 BOOST_AUTO_TEST_CASE (test_font_override)
236 auto content = make_shared<DCPSubtitleContent>("test/data/dcp_sub4.xml");
237 auto film = new_test_film2("test_font_override", {content});
238 film->set_interop(true);
240 BOOST_REQUIRE_EQUAL(content->text.size(), 1U);
241 content->text.front()->get_font("theFontId")->set_file("test/data/Inconsolata-VF.ttf");
243 make_and_verify_dcp (film, { dcp::VerificationNote::Code::INVALID_STANDARD });
244 check_file (subtitle_file(film).parent_path() / "font_0.ttf", "test/data/Inconsolata-VF.ttf");