2 Copyright (C) 2014-2019 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/>.
21 /** @file test/dcp_subtitle_test.cc
22 * @brief Test DCP subtitle content in various ways.
26 #include <boost/test/unit_test.hpp>
28 #include "lib/dcp_subtitle_content.h"
29 #include "lib/dcp_content.h"
30 #include "lib/ratio.h"
31 #include "lib/dcp_decoder.h"
32 #include "lib/dcp_content_type.h"
33 #include "lib/dcp_subtitle_decoder.h"
34 #include "lib/text_content.h"
35 #include "lib/content_text.h"
37 #include "lib/text_decoder.h"
43 using boost::shared_ptr;
44 using boost::optional;
45 #if BOOST_VERSION >= 106100
46 using namespace boost::placeholders;
48 using namespace dcpomatic;
50 optional<ContentStringText> stored;
53 store (ContentStringText sub)
58 BOOST_FOREACH (dcp::SubtitleString i, sub.subs) {
59 stored->subs.push_back (i);
64 /** Test pass-through of a very simple DCP subtitle file */
65 BOOST_AUTO_TEST_CASE (dcp_subtitle_test)
67 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test");
68 film->set_container (Ratio::from_id ("185"));
69 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
70 film->set_name ("frobozz");
71 film->set_interop (false);
72 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub.xml"));
73 film->examine_and_add_content (content);
74 BOOST_REQUIRE (!wait_for_jobs ());
76 BOOST_CHECK_EQUAL (content->full_length(film).get(), DCPTime::from_seconds(2).get());
78 content->only_text()->set_use (true);
79 content->only_text()->set_burn (false);
81 BOOST_REQUIRE (!wait_for_jobs ());
83 check_dcp ("test/data/dcp_subtitle_test", film->dir (film->dcp_name ()));
86 /** Test parsing of a subtitle within an existing DCP */
87 BOOST_AUTO_TEST_CASE (dcp_subtitle_within_dcp_test)
89 shared_ptr<Film> film = new_test_film ("dcp_subtitle_within_dcp_test");
90 film->set_container (Ratio::from_id ("185"));
91 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
92 film->set_name ("frobozz");
93 shared_ptr<DCPContent> content (new DCPContent(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV"));
94 film->examine_and_add_content (content);
95 BOOST_REQUIRE (!wait_for_jobs ());
97 shared_ptr<DCPDecoder> decoder (new DCPDecoder (film, content, false, false, shared_ptr<DCPDecoder>()));
98 decoder->only_text()->PlainStart.connect (bind (store, _1));
100 stored = optional<ContentStringText> ();
101 while (!decoder->pass() && !stored) {}
103 BOOST_REQUIRE (stored);
104 BOOST_REQUIRE_EQUAL (stored->subs.size(), 2U);
105 BOOST_CHECK_EQUAL (stored->subs.front().text(), "Noch mal.");
106 BOOST_CHECK_EQUAL (stored->subs.back().text(), "Encore une fois.");
109 /** Test subtitles whose text includes things like <b> */
110 BOOST_AUTO_TEST_CASE (dcp_subtitle_test2)
112 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test2");
113 film->set_container (Ratio::from_id ("185"));
114 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
115 film->set_name ("frobozz");
116 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent("test/data/dcp_sub2.xml"));
117 film->examine_and_add_content (content);
118 BOOST_REQUIRE (!wait_for_jobs ());
120 shared_ptr<DCPSubtitleDecoder> decoder (new DCPSubtitleDecoder(film, content));
121 decoder->only_text()->PlainStart.connect (bind (store, _1));
123 stored = optional<ContentStringText> ();
124 while (!decoder->pass()) {
125 if (stored && stored->from() == ContentTime(0)) {
126 BOOST_CHECK_EQUAL (stored->subs.front().text(), "<b>Hello world!</b>");
131 /** Test a failure case */
132 BOOST_AUTO_TEST_CASE (dcp_subtitle_test3)
134 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test3");
135 film->set_container (Ratio::from_id ("185"));
136 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
137 film->set_name ("frobozz");
138 film->set_interop (true);
139 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
140 film->examine_and_add_content (content);
141 BOOST_REQUIRE (!wait_for_jobs ());
144 BOOST_REQUIRE (!wait_for_jobs ());
146 shared_ptr<DCPSubtitleDecoder> decoder (new DCPSubtitleDecoder (film, content));
147 stored = optional<ContentStringText> ();
148 while (!decoder->pass ()) {
149 decoder->only_text()->PlainStart.connect (bind (store, _1));
150 if (stored && stored->from() == ContentTime::from_seconds(0.08)) {
151 list<dcp::SubtitleString> s = stored->subs;
152 list<dcp::SubtitleString>::const_iterator i = s.begin ();
153 BOOST_CHECK_EQUAL (i->text(), "This");
155 BOOST_REQUIRE (i != s.end ());
156 BOOST_CHECK_EQUAL (i->text(), " is ");
158 BOOST_REQUIRE (i != s.end ());
159 BOOST_CHECK_EQUAL (i->text(), "wrong.");
161 BOOST_REQUIRE (i == s.end ());
166 /** Check that Interop DCPs aren't made with more than one <LoadFont> (#1273) */
167 BOOST_AUTO_TEST_CASE (dcp_subtitle_test4)
169 shared_ptr<Film> film = new_test_film2 ("dcp_subtitle_test4");
170 film->set_interop (true);
172 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
173 film->examine_and_add_content (content);
174 shared_ptr<DCPSubtitleContent> content2 (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
175 film->examine_and_add_content (content2);
176 BOOST_REQUIRE (!wait_for_jobs ());
178 content->only_text()->add_font (shared_ptr<Font> (new Font ("font1")));
179 content2->only_text()->add_font (shared_ptr<Font> (new Font ("font2")));
182 BOOST_REQUIRE (!wait_for_jobs ());
184 cxml::Document doc ("DCSubtitle");
185 doc.read_file (subtitle_file (film));
186 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1U);
191 check_font_tags (list<cxml::NodePtr> nodes)
193 BOOST_FOREACH (cxml::NodePtr i, nodes) {
194 if (i->name() == "Font") {
195 BOOST_CHECK (!i->optional_string_attribute("Id") || i->string_attribute("Id") != "");
197 check_font_tags (i->node_children());
201 /** Check that imported <LoadFont> tags with empty IDs (or corresponding Font tags with empty IDs)
202 * are not passed through into the DCP.
204 BOOST_AUTO_TEST_CASE (dcp_subtitle_test5)
206 shared_ptr<Film> film = new_test_film2 ("dcp_subtitle_test5");
207 film->set_interop (true);
209 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent("test/data/dcp_sub6.xml"));
210 film->examine_and_add_content (content);
211 BOOST_REQUIRE (!wait_for_jobs());
214 BOOST_REQUIRE (!wait_for_jobs());
215 film->write_metadata ();
217 cxml::Document doc ("DCSubtitle");
218 doc.read_file (subtitle_file(film));
219 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1U);
220 BOOST_CHECK (doc.node_children("LoadFont").front()->string_attribute("Id") != "");
222 check_font_tags (doc.node_children());