2 Copyright (C) 2015-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
20 #include "interop_subtitle_asset.h"
21 #include "smpte_subtitle_asset.h"
22 #include "subtitle_string.h"
23 #include "subtitle_asset_internal.h"
25 #include <boost/test/unit_test.hpp>
29 using boost::shared_ptr;
31 /** Test dcp::order::Font::take_intersection */
32 BOOST_AUTO_TEST_CASE (take_intersection_test)
35 A._values["foo"] = "bar";
36 A._values["fred"] = "jim";
39 B._values["foo"] = "bar";
40 B._values["sheila"] = "baz";
42 A.take_intersection (B);
43 BOOST_REQUIRE_EQUAL (A._values.size(), 1);
44 BOOST_CHECK_EQUAL (A._values["foo"], "bar");
49 A._values["foo"] = "bar";
50 A._values["fred"] = "jim";
52 B._values["foo"] = "hello";
53 B._values["sheila"] = "baz";
55 A.take_intersection (B);
56 BOOST_CHECK_EQUAL (A._values.size(), 0);
59 /** Test dcp::order::Font::take_difference */
60 BOOST_AUTO_TEST_CASE (take_difference_test)
63 A._values["foo"] = "bar";
64 A._values["fred"] = "jim";
67 B._values["foo"] = "bar";
68 B._values["sheila"] = "baz";
70 A.take_difference (B);
71 BOOST_REQUIRE_EQUAL (A._values.size(), 1);
72 BOOST_CHECK_EQUAL (A._values["fred"], "jim");
75 /** Test dcp::order::Subtitle::pull_fonts */
76 BOOST_AUTO_TEST_CASE (pull_fonts_test1)
78 shared_ptr<dcp::order::Part> root (new dcp::order::Part (shared_ptr<dcp::order::Part> ()));
79 shared_ptr<dcp::order::Subtitle> sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time()));
80 root->children.push_back (sub1);
81 shared_ptr<dcp::order::Text> text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
82 sub1->children.push_back (text1);
83 text1->font._values["font"] = "Inconsolata";
84 text1->font._values["size"] = "42";
86 dcp::SubtitleAsset::pull_fonts (root);
88 BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2);
89 BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
90 BOOST_CHECK_EQUAL (sub1->font._values["size"], "42");
91 BOOST_CHECK_EQUAL (text1->font._values.size(), 0);
94 /** Test dcp::order::Subtitle::pull_fonts */
95 BOOST_AUTO_TEST_CASE (pull_fonts_test2)
97 shared_ptr<dcp::order::Part> root (new dcp::order::Part (shared_ptr<dcp::order::Part> ()));
98 shared_ptr<dcp::order::Subtitle> sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time()));
99 root->children.push_back (sub1);
100 shared_ptr<dcp::order::Text> text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
101 sub1->children.push_back (text1);
102 text1->font._values["font"] = "Inconsolata";
103 text1->font._values["size"] = "42";
104 shared_ptr<dcp::order::Text> text2 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
105 sub1->children.push_back (text2);
106 text2->font._values["font"] = "Inconsolata";
107 text2->font._values["size"] = "48";
109 dcp::SubtitleAsset::pull_fonts (root);
111 BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 1);
112 BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
113 BOOST_REQUIRE_EQUAL (text1->font._values.size(), 1);
114 BOOST_CHECK_EQUAL (text1->font._values["size"], "42");
115 BOOST_REQUIRE_EQUAL (text2->font._values.size(), 1);
116 BOOST_CHECK_EQUAL (text2->font._values["size"], "48");
119 /** Test dcp::order::Subtitle::pull_fonts */
120 BOOST_AUTO_TEST_CASE (pull_fonts_test3)
122 shared_ptr<dcp::order::Part> root (new dcp::order::Part (shared_ptr<dcp::order::Part> ()));
123 shared_ptr<dcp::order::Subtitle> sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time()));
124 root->children.push_back (sub1);
125 shared_ptr<dcp::order::Text> text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR));
126 sub1->children.push_back (text1);
127 dcp::order::Font font;
128 font._values["font"] = "Inconsolata";
129 font._values["size"] = "42";
130 shared_ptr<dcp::order::String> string1 (new dcp::order::String (text1, font, "Hello world"));
131 text1->children.push_back (string1);
133 dcp::SubtitleAsset::pull_fonts (root);
135 BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2);
136 BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
137 BOOST_CHECK_EQUAL (sub1->font._values["size"], "42");
140 /** Write some subtitle content as Interop XML and check that it is right */
141 BOOST_AUTO_TEST_CASE (write_interop_subtitle_test)
143 dcp::InteropSubtitleAsset c;
144 c.set_reel_number ("1");
145 c.set_language ("EN");
146 c.set_movie_title ("Test");
149 dcp::SubtitleString (
154 dcp::Colour (255, 255, 255),
157 dcp::Time (0, 4, 9, 22, 24),
158 dcp::Time (0, 4, 11, 22, 24),
166 dcp::Colour (0, 0, 0),
167 dcp::Time (0, 0, 0, 0, 24),
168 dcp::Time (0, 0, 0, 0, 24)
173 dcp::SubtitleString (
174 boost::optional<string> (),
178 dcp::Colour (128, 0, 64),
181 dcp::Time (5, 41, 0, 21, 24),
182 dcp::Time (6, 12, 15, 21, 24),
190 dcp::Colour (1, 2, 3),
191 dcp::Time (1, 2, 3, 4, 24),
192 dcp::Time (5, 6, 7, 8, 24)
196 c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
200 "<DCSubtitle Version=\"1.0\">"
201 "<SubtitleID>a6c58cff-3e1e-4b38-acec-a42224475ef6</SubtitleID>"
202 "<MovieTitle>Test</MovieTitle>"
203 "<ReelNumber>1</ReelNumber>"
204 "<Language>EN</Language>"
205 "<Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" Id=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underlined=\"no\" Weight=\"normal\">"
206 "<Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:229\" TimeOut=\"00:04:11:229\" FadeUpTime=\"0\" FadeDownTime=\"0\">"
207 "<Text VAlign=\"top\" VPosition=\"80\">Hello world</Text>"
210 "<Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underlined=\"yes\" Weight=\"bold\">"
211 "<Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:218\" TimeOut=\"06:12:15:218\" FadeUpTime=\"930792\" FadeDownTime=\"4591834\">"
212 "<Text VAlign=\"bottom\" VPosition=\"40\">What's going on</Text>"
220 /* Write some subtitle content as SMPTE XML and check that it is right */
221 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test)
223 dcp::SMPTESubtitleAsset c;
224 c.set_reel_number (1);
225 c.set_language ("EN");
226 c.set_content_title_text ("Test");
227 c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
230 dcp::SubtitleString (
235 dcp::Colour (255, 255, 255),
238 dcp::Time (0, 4, 9, 22, 24),
239 dcp::Time (0, 4, 11, 22, 24),
247 dcp::Colour (0, 0, 0),
248 dcp::Time (0, 0, 0, 0, 24),
249 dcp::Time (0, 0, 0, 0, 24)
254 dcp::SubtitleString (
255 boost::optional<string> (),
259 dcp::Colour (128, 0, 64),
262 dcp::Time (5, 41, 0, 21, 24),
263 dcp::Time (6, 12, 15, 21, 24),
271 dcp::Colour (1, 2, 3),
272 dcp::Time (1, 2, 3, 4, 24),
273 dcp::Time (5, 6, 7, 8, 24)
277 c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
281 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
282 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
283 "<dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>"
284 "<dcst:ContentTitleText>Test</dcst:ContentTitleText>"
285 "<dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>"
286 "<dcst:ReelNumber>1</dcst:ReelNumber>"
287 "<dcst:Language>EN</dcst:Language>"
288 "<dcst:EditRate>24 1</dcst:EditRate>"
289 "<dcst:TimeCodeRate>24</dcst:TimeCodeRate>"
290 "<dcst:SubtitleList>"
291 "<dcst:Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" ID=\"Frutiger\" Italic=\"no\" Script=\"normal\" Size=\"48\" Underline=\"no\" Weight=\"normal\">"
292 "<dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:04:09:22\" TimeOut=\"00:04:11:22\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">"
293 "<dcst:Text Valign=\"top\" Vposition=\"80\">Hello world</dcst:Text>"
296 "<dcst:Font AspectAdjust=\"1.0\" Color=\"FF800040\" Effect=\"border\" EffectColor=\"FF010203\" Italic=\"yes\" Script=\"normal\" Size=\"91\" Underline=\"yes\" Weight=\"bold\">"
297 "<dcst:Subtitle SpotNumber=\"2\" TimeIn=\"05:41:00:21\" TimeOut=\"06:12:15:21\" FadeUpTime=\"01:02:03:04\" FadeDownTime=\"05:06:07:08\">"
298 "<dcst:Text Valign=\"bottom\" Vposition=\"40\" Direction=\"rtl\">What's going on</dcst:Text>"
301 "</dcst:SubtitleList>"
302 "</dcst:SubtitleReel>",
307 /* Write some subtitle content as SMPTE XML and check that it is right.
308 This includes in-line font changes.
310 BOOST_AUTO_TEST_CASE (write_smpte_subtitle_test2)
312 dcp::SMPTESubtitleAsset c;
313 c.set_reel_number (1);
314 c.set_language ("EN");
315 c.set_content_title_text ("Test");
316 c.set_issue_date (dcp::LocalTime ("2016-04-01T03:52:00+00:00"));
319 dcp::SubtitleString (
324 dcp::Colour (255, 255, 255),
327 dcp::Time (0, 0, 1, 0, 24),
328 dcp::Time (0, 0, 9, 0, 24),
336 dcp::Colour (0, 0, 0),
337 dcp::Time (0, 0, 0, 0, 24),
338 dcp::Time (0, 0, 0, 0, 24)
343 dcp::SubtitleString (
348 dcp::Colour (255, 255, 255),
351 dcp::Time (0, 0, 1, 0, 24),
352 dcp::Time (0, 0, 9, 0, 24),
360 dcp::Colour (0, 0, 0),
361 dcp::Time (0, 0, 0, 0, 24),
362 dcp::Time (0, 0, 0, 0, 24)
367 dcp::SubtitleString (
372 dcp::Colour (255, 255, 255),
375 dcp::Time (0, 0, 1, 0, 24),
376 dcp::Time (0, 0, 9, 0, 24),
384 dcp::Colour (0, 0, 0),
385 dcp::Time (0, 0, 0, 0, 24),
386 dcp::Time (0, 0, 0, 0, 24)
391 dcp::SubtitleString (
396 dcp::Colour (255, 255, 255),
399 dcp::Time (0, 0, 1, 0, 24),
400 dcp::Time (0, 0, 9, 0, 24),
408 dcp::Colour (0, 0, 0),
409 dcp::Time (0, 0, 0, 0, 24),
410 dcp::Time (0, 0, 0, 0, 24)
415 dcp::SubtitleString (
420 dcp::Colour (255, 255, 255),
423 dcp::Time (0, 0, 1, 0, 24),
424 dcp::Time (0, 0, 9, 0, 24),
432 dcp::Colour (0, 0, 0),
433 dcp::Time (0, 0, 0, 0, 24),
434 dcp::Time (0, 0, 0, 0, 24)
439 dcp::SubtitleString (
444 dcp::Colour (255, 255, 255),
447 dcp::Time (0, 0, 1, 0, 24),
448 dcp::Time (0, 0, 9, 0, 24),
456 dcp::Colour (0, 0, 0),
457 dcp::Time (0, 0, 0, 0, 24),
458 dcp::Time (0, 0, 0, 0, 24)
462 c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
466 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
467 "<dcst:SubtitleReel xmlns:dcst=\"http://www.smpte-ra.org/schemas/428-7/2010/DCST\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
468 "<dcst:Id>urn:uuid:a6c58cff-3e1e-4b38-acec-a42224475ef6</dcst:Id>"
469 "<dcst:ContentTitleText>Test</dcst:ContentTitleText>"
470 "<dcst:IssueDate>2016-04-01T03:52:00.000+00:00</dcst:IssueDate>"
471 "<dcst:ReelNumber>1</dcst:ReelNumber>"
472 "<dcst:Language>EN</dcst:Language>"
473 "<dcst:EditRate>24 1</dcst:EditRate>"
474 "<dcst:TimeCodeRate>24</dcst:TimeCodeRate>"
475 "<dcst:SubtitleList>"
476 "<dcst:Font AspectAdjust=\"1.0\" Color=\"FFFFFFFF\" Effect=\"none\" EffectColor=\"FF000000\" ID=\"Arial\" Script=\"normal\" Size=\"48\" Underline=\"no\" Weight=\"normal\">"
477 "<dcst:Subtitle SpotNumber=\"1\" TimeIn=\"00:00:01:00\" TimeOut=\"00:00:09:00\" FadeUpTime=\"00:00:00:00\" FadeDownTime=\"00:00:00:00\">"
478 "<dcst:Text Valign=\"top\" Vposition=\"80\">"
479 "<dcst:Font Italic=\"no\">Testing is </dcst:Font>"
480 "<dcst:Font Italic=\"yes\">really</dcst:Font>"
481 "<dcst:Font Italic=\"no\"> fun</dcst:Font>"
483 "<dcst:Text Valign=\"top\" Vposition=\"90\">"
484 "<dcst:Font Italic=\"no\">This is the </dcst:Font>"
485 "<dcst:Font Italic=\"yes\">second</dcst:Font>"
486 "<dcst:Font Italic=\"no\"> line</dcst:Font>"
490 "</dcst:SubtitleList>"
491 "</dcst:SubtitleReel>",