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 std::shared_ptr;
45 using boost::optional;
46 #if BOOST_VERSION >= 106100
47 using namespace boost::placeholders;
49 using namespace dcpomatic;
51 optional<ContentStringText> stored;
54 store (ContentStringText sub)
59 for (auto i: sub.subs) {
60 stored->subs.push_back (i);
65 /** Test pass-through of a very simple DCP subtitle file */
66 BOOST_AUTO_TEST_CASE (dcp_subtitle_test)
68 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test");
69 film->set_container (Ratio::from_id ("185"));
70 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
71 film->set_name ("frobozz");
72 film->set_interop (false);
73 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub.xml"));
74 film->examine_and_add_content (content);
75 BOOST_REQUIRE (!wait_for_jobs ());
77 BOOST_CHECK_EQUAL (content->full_length(film).get(), DCPTime::from_seconds(2).get());
79 content->only_text()->set_use (true);
80 content->only_text()->set_burn (false);
82 BOOST_REQUIRE (!wait_for_jobs ());
84 check_dcp ("test/data/dcp_subtitle_test", film->dir (film->dcp_name ()));
87 /** Test parsing of a subtitle within an existing DCP */
88 BOOST_AUTO_TEST_CASE (dcp_subtitle_within_dcp_test)
90 shared_ptr<Film> film = new_test_film ("dcp_subtitle_within_dcp_test");
91 film->set_container (Ratio::from_id ("185"));
92 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
93 film->set_name ("frobozz");
94 shared_ptr<DCPContent> content (new DCPContent(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV"));
95 film->examine_and_add_content (content);
96 BOOST_REQUIRE (!wait_for_jobs ());
98 shared_ptr<DCPDecoder> decoder (new DCPDecoder (film, content, false, false, shared_ptr<DCPDecoder>()));
99 decoder->only_text()->PlainStart.connect (bind (store, _1));
101 stored = optional<ContentStringText> ();
102 while (!decoder->pass() && !stored) {}
104 BOOST_REQUIRE (stored);
105 BOOST_REQUIRE_EQUAL (stored->subs.size(), 2U);
106 BOOST_CHECK_EQUAL (stored->subs.front().text(), "Noch mal.");
107 BOOST_CHECK_EQUAL (stored->subs.back().text(), "Encore une fois.");
110 /** Test subtitles whose text includes things like <b> */
111 BOOST_AUTO_TEST_CASE (dcp_subtitle_test2)
113 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test2");
114 film->set_container (Ratio::from_id ("185"));
115 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
116 film->set_name ("frobozz");
117 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent("test/data/dcp_sub2.xml"));
118 film->examine_and_add_content (content);
119 BOOST_REQUIRE (!wait_for_jobs ());
121 shared_ptr<DCPSubtitleDecoder> decoder (new DCPSubtitleDecoder(film, content));
122 decoder->only_text()->PlainStart.connect (bind (store, _1));
124 stored = optional<ContentStringText> ();
125 while (!decoder->pass()) {
126 if (stored && stored->from() == ContentTime(0)) {
127 BOOST_CHECK_EQUAL (stored->subs.front().text(), "<b>Hello world!</b>");
132 /** Test a failure case */
133 BOOST_AUTO_TEST_CASE (dcp_subtitle_test3)
135 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test3");
136 film->set_container (Ratio::from_id ("185"));
137 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
138 film->set_name ("frobozz");
139 film->set_interop (true);
140 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
141 film->examine_and_add_content (content);
142 BOOST_REQUIRE (!wait_for_jobs ());
145 BOOST_REQUIRE (!wait_for_jobs ());
147 shared_ptr<DCPSubtitleDecoder> decoder (new DCPSubtitleDecoder (film, content));
148 stored = optional<ContentStringText> ();
149 while (!decoder->pass ()) {
150 decoder->only_text()->PlainStart.connect (bind (store, _1));
151 if (stored && stored->from() == ContentTime::from_seconds(0.08)) {
152 list<dcp::SubtitleString> s = stored->subs;
153 list<dcp::SubtitleString>::const_iterator i = s.begin ();
154 BOOST_CHECK_EQUAL (i->text(), "This");
156 BOOST_REQUIRE (i != s.end ());
157 BOOST_CHECK_EQUAL (i->text(), " is ");
159 BOOST_REQUIRE (i != s.end ());
160 BOOST_CHECK_EQUAL (i->text(), "wrong.");
162 BOOST_REQUIRE (i == s.end ());
167 /** Check that Interop DCPs aren't made with more than one <LoadFont> (#1273) */
168 BOOST_AUTO_TEST_CASE (dcp_subtitle_test4)
170 shared_ptr<Film> film = new_test_film2 ("dcp_subtitle_test4");
171 film->set_interop (true);
173 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
174 film->examine_and_add_content (content);
175 shared_ptr<DCPSubtitleContent> content2 (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
176 film->examine_and_add_content (content2);
177 BOOST_REQUIRE (!wait_for_jobs ());
179 content->only_text()->add_font (shared_ptr<Font> (new Font ("font1")));
180 content2->only_text()->add_font (shared_ptr<Font> (new Font ("font2")));
183 BOOST_REQUIRE (!wait_for_jobs ());
185 cxml::Document doc ("DCSubtitle");
186 doc.read_file (subtitle_file (film));
187 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1U);
192 check_font_tags (vector<cxml::NodePtr> nodes)
194 for (auto i: nodes) {
195 if (i->name() == "Font") {
196 BOOST_CHECK (!i->optional_string_attribute("Id") || i->string_attribute("Id") != "");
198 check_font_tags (i->node_children());
202 /** Check that imported <LoadFont> tags with empty IDs (or corresponding Font tags with empty IDs)
203 * are not passed through into the DCP.
205 BOOST_AUTO_TEST_CASE (dcp_subtitle_test5)
207 shared_ptr<Film> film = new_test_film2 ("dcp_subtitle_test5");
208 film->set_interop (true);
210 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent("test/data/dcp_sub6.xml"));
211 film->examine_and_add_content (content);
212 BOOST_REQUIRE (!wait_for_jobs());
215 BOOST_REQUIRE (!wait_for_jobs());
216 film->write_metadata ();
218 cxml::Document doc ("DCSubtitle");
219 doc.read_file (subtitle_file(film));
220 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1U);
221 BOOST_CHECK (doc.node_children("LoadFont").front()->string_attribute("Id") != "");
223 check_font_tags (doc.node_children());