2 Copyright (C) 2014-2018 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 using namespace dcpomatic;
47 optional<ContentStringText> stored;
50 store (ContentStringText sub)
55 BOOST_FOREACH (dcp::SubtitleString i, sub.subs) {
56 stored->subs.push_back (i);
61 /** Test pass-through of a very simple DCP subtitle file */
62 BOOST_AUTO_TEST_CASE (dcp_subtitle_test)
64 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test");
65 film->set_container (Ratio::from_id ("185"));
66 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
67 film->set_name ("frobozz");
68 film->set_interop (false);
69 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub.xml"));
70 film->examine_and_add_content (content);
71 BOOST_REQUIRE (!wait_for_jobs ());
73 BOOST_CHECK_EQUAL (content->full_length(film).get(), DCPTime::from_seconds(2).get());
75 content->only_text()->set_use (true);
76 content->only_text()->set_burn (false);
78 BOOST_REQUIRE (!wait_for_jobs ());
80 check_dcp ("test/data/dcp_subtitle_test", film->dir (film->dcp_name ()));
83 /** Test parsing of a subtitle within an existing DCP */
84 BOOST_AUTO_TEST_CASE (dcp_subtitle_within_dcp_test)
86 shared_ptr<Film> film = new_test_film ("dcp_subtitle_within_dcp_test");
87 film->set_container (Ratio::from_id ("185"));
88 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
89 film->set_name ("frobozz");
90 shared_ptr<DCPContent> content (new DCPContent(private_data / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV"));
91 film->examine_and_add_content (content);
92 BOOST_REQUIRE (!wait_for_jobs ());
94 shared_ptr<DCPDecoder> decoder (new DCPDecoder (film, content, false, false, shared_ptr<DCPDecoder>()));
95 decoder->only_text()->PlainStart.connect (bind (store, _1));
97 stored = optional<ContentStringText> ();
98 while (!decoder->pass() && !stored) {}
100 BOOST_REQUIRE (stored);
101 BOOST_REQUIRE_EQUAL (stored->subs.size(), 2);
102 BOOST_CHECK_EQUAL (stored->subs.front().text(), "Noch mal.");
103 BOOST_CHECK_EQUAL (stored->subs.back().text(), "Encore une fois.");
106 /** Test subtitles whose text includes things like <b> */
107 BOOST_AUTO_TEST_CASE (dcp_subtitle_test2)
109 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test2");
110 film->set_container (Ratio::from_id ("185"));
111 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
112 film->set_name ("frobozz");
113 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent("test/data/dcp_sub2.xml"));
114 film->examine_and_add_content (content);
115 BOOST_REQUIRE (!wait_for_jobs ());
117 shared_ptr<DCPSubtitleDecoder> decoder (new DCPSubtitleDecoder(film, content));
118 decoder->only_text()->PlainStart.connect (bind (store, _1));
120 stored = optional<ContentStringText> ();
121 while (!decoder->pass()) {
122 if (stored && stored->from() == ContentTime(0)) {
123 BOOST_CHECK_EQUAL (stored->subs.front().text(), "<b>Hello world!</b>");
128 /** Test a failure case */
129 BOOST_AUTO_TEST_CASE (dcp_subtitle_test3)
131 shared_ptr<Film> film = new_test_film ("dcp_subtitle_test3");
132 film->set_container (Ratio::from_id ("185"));
133 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
134 film->set_name ("frobozz");
135 film->set_interop (true);
136 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
137 film->examine_and_add_content (content);
138 BOOST_REQUIRE (!wait_for_jobs ());
141 BOOST_REQUIRE (!wait_for_jobs ());
143 shared_ptr<DCPSubtitleDecoder> decoder (new DCPSubtitleDecoder (film, content));
144 stored = optional<ContentStringText> ();
145 while (!decoder->pass ()) {
146 decoder->only_text()->PlainStart.connect (bind (store, _1));
147 if (stored && stored->from() == ContentTime::from_seconds(0.08)) {
148 list<dcp::SubtitleString> s = stored->subs;
149 list<dcp::SubtitleString>::const_iterator i = s.begin ();
150 BOOST_CHECK_EQUAL (i->text(), "This");
152 BOOST_REQUIRE (i != s.end ());
153 BOOST_CHECK_EQUAL (i->text(), " is ");
155 BOOST_REQUIRE (i != s.end ());
156 BOOST_CHECK_EQUAL (i->text(), "wrong.");
158 BOOST_REQUIRE (i == s.end ());
163 /** Check that Interop DCPs aren't made with more than one <LoadFont> (#1273) */
164 BOOST_AUTO_TEST_CASE (dcp_subtitle_test4)
166 shared_ptr<Film> film = new_test_film2 ("dcp_subtitle_test4");
167 film->set_interop (true);
169 shared_ptr<DCPSubtitleContent> content (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
170 film->examine_and_add_content (content);
171 shared_ptr<DCPSubtitleContent> content2 (new DCPSubtitleContent ("test/data/dcp_sub3.xml"));
172 film->examine_and_add_content (content2);
173 BOOST_REQUIRE (!wait_for_jobs ());
175 content->only_text()->add_font (shared_ptr<Font> (new Font ("font1")));
176 content2->only_text()->add_font (shared_ptr<Font> (new Font ("font2")));
179 BOOST_REQUIRE (!wait_for_jobs ());
181 cxml::Document doc ("DCSubtitle");
182 doc.read_file (subtitle_file (film));
183 BOOST_REQUIRE_EQUAL (doc.node_children("LoadFont").size(), 1);