2 Copyright (C) 2015-2018 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 "smpte_subtitle_asset.h"
22 #include "local_time.h"
23 #include "smpte_load_font_node.h"
24 #include "subtitle_image.h"
25 #include <boost/test/unit_test.hpp>
26 #include <boost/optional.hpp>
27 #include <boost/optional/optional_io.hpp>
30 using boost::shared_ptr;
31 using boost::dynamic_pointer_cast;
33 /** Check reading of a SMPTE subtitle file */
34 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
36 dcp::SMPTESubtitleAsset sc (
39 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
40 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
43 BOOST_CHECK_EQUAL (sc.id(), "8b48f6ae-c74b-4b80-b994-a8236bbbad74");
44 BOOST_CHECK_EQUAL (sc.content_title_text(), "Journey to Jah");
45 BOOST_REQUIRE (sc.annotation_text());
46 BOOST_CHECK_EQUAL (sc.annotation_text().get(), "Journey to Jah");
47 BOOST_CHECK_EQUAL (sc.issue_date(), dcp::LocalTime ("2014-02-25T11:22:48.000-00:00"));
48 BOOST_REQUIRE (sc.reel_number());
49 BOOST_CHECK_EQUAL (sc.reel_number().get(), 1);
50 BOOST_REQUIRE (sc.language ());
51 BOOST_CHECK_EQUAL (sc.language().get (), "de");
52 BOOST_CHECK_EQUAL (sc.edit_rate(), dcp::Fraction (25, 1));
53 BOOST_CHECK_EQUAL (sc.time_code_rate(), 25);
54 BOOST_CHECK_EQUAL (sc.start_time(), dcp::Time (0, 0, 0, 0, 25));
55 list<shared_ptr<dcp::LoadFontNode> > lfn = sc.load_font_nodes ();
56 BOOST_REQUIRE_EQUAL (lfn.size(), 1);
57 shared_ptr<dcp::SMPTELoadFontNode> smpte_lfn = dynamic_pointer_cast<dcp::SMPTELoadFontNode> (lfn.front ());
58 BOOST_REQUIRE (smpte_lfn);
59 BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
60 BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
61 BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
62 BOOST_REQUIRE (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().front()));
63 BOOST_CHECK_EQUAL (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().front())->text(), "Noch mal.");
64 BOOST_CHECK_EQUAL (sc.subtitles().front()->in(), dcp::Time (0, 0, 25, 12, 25));
65 BOOST_CHECK_EQUAL (sc.subtitles().front()->out(), dcp::Time (0, 0, 26, 4, 25));
66 BOOST_REQUIRE (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().back()));
67 BOOST_CHECK_EQUAL (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().back())->text(), "Prochainement");
68 BOOST_CHECK_EQUAL (sc.subtitles().back()->in(), dcp::Time (0, 1, 57, 17, 25));
69 BOOST_CHECK_EQUAL (sc.subtitles().back()->out(), dcp::Time (0, 1, 58, 12, 25));
72 /** And another one featuring <Font> within <Text> */
73 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
75 dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
77 BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 6);
78 list<shared_ptr<dcp::Subtitle> >::const_iterator i = sc.subtitles().begin();
79 shared_ptr<dcp::SubtitleString> is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
81 BOOST_CHECK_EQUAL (is->text(), "Testing is ");
82 BOOST_CHECK (!is->italic());
84 is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
86 BOOST_CHECK_EQUAL (is->text(), "really");
87 BOOST_CHECK (is->italic());
89 is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
91 BOOST_CHECK_EQUAL (is->text(), " fun!");
92 BOOST_CHECK (!is->italic());
94 is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
96 BOOST_CHECK_EQUAL (is->text(), "This is the ");
97 BOOST_CHECK (!is->italic());
99 is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
101 BOOST_CHECK_EQUAL (is->text(), "second");
102 BOOST_CHECK (is->italic());
104 is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
106 BOOST_CHECK_EQUAL (is->text(), " line!");
107 BOOST_CHECK (!is->italic());
110 /** And another one featuring image subtitles */
111 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
113 dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
115 BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
116 shared_ptr<dcp::SubtitleImage> si = dynamic_pointer_cast<dcp::SubtitleImage>(subs.subtitles().front());
118 BOOST_CHECK (si->png_image() == dcp::Data("test/data/sub.png"));