2 Copyright (C) 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/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 #include "smpte_load_font_node.h"
36 #include "smpte_subtitle_asset.h"
37 #include "subtitle_image.h"
40 #include <boost/optional/optional_io.hpp>
41 #include <boost/test/unit_test.hpp>
45 using boost::dynamic_pointer_cast;
46 using boost::optional;
47 using boost::shared_ptr;
50 BOOST_AUTO_TEST_CASE (smpte_subtitle_id_test)
52 dcp::SMPTESubtitleAsset subs;
54 shared_ptr<dcp::Subtitle> (
55 new dcp::SubtitleString(
61 dcp::Time(0, 1, 2, 3, 24),
62 dcp::Time(0, 2, 2, 3, 24),
71 dcp::Time(0, 0, 0, 0, 24),
72 dcp::Time(0, 0, 0, 0, 24)
76 subs.write("build/test/smpte_subtitle_id_test.mxf");
78 dcp::SMPTESubtitleAsset check("build/test/smpte_subtitle_id_test.mxf");
79 BOOST_CHECK(check.id() != check.xml_id());
83 /** Check reading of a SMPTE subtitle file */
84 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
86 dcp::SMPTESubtitleAsset sc (
89 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
90 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
93 BOOST_CHECK_EQUAL (sc.id(), "8b48f6ae-c74b-4b80-b994-a8236bbbad74");
94 BOOST_CHECK_EQUAL (sc.content_title_text(), "Journey to Jah");
95 BOOST_REQUIRE (sc.annotation_text());
96 BOOST_CHECK_EQUAL (sc.annotation_text().get(), "Journey to Jah");
97 BOOST_CHECK_EQUAL (sc.issue_date(), dcp::LocalTime ("2014-02-25T11:22:48.000-00:00"));
98 BOOST_REQUIRE (sc.reel_number());
99 BOOST_CHECK_EQUAL (sc.reel_number().get(), 1);
100 BOOST_REQUIRE (sc.language ());
101 BOOST_CHECK_EQUAL (sc.language().get (), "de");
102 BOOST_CHECK_EQUAL (sc.edit_rate(), dcp::Fraction (25, 1));
103 BOOST_CHECK_EQUAL (sc.time_code_rate(), 25);
104 BOOST_CHECK_EQUAL (sc.start_time(), dcp::Time (0, 0, 0, 0, 25));
105 auto lfn = sc.load_font_nodes ();
106 BOOST_REQUIRE_EQUAL (lfn.size(), 1);
107 shared_ptr<dcp::SMPTELoadFontNode> smpte_lfn = dynamic_pointer_cast<dcp::SMPTELoadFontNode> (lfn.front ());
108 BOOST_REQUIRE (smpte_lfn);
109 BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
110 BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
111 BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
112 BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front()));
113 BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front())->text(), "Noch mal.");
114 BOOST_CHECK_EQUAL (sc.subtitles().front()->in(), dcp::Time (0, 0, 25, 12, 25));
115 BOOST_CHECK_EQUAL (sc.subtitles().front()->out(), dcp::Time (0, 0, 26, 4, 25));
116 BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back()));
117 BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back())->text(), "Prochainement");
118 BOOST_CHECK_EQUAL (sc.subtitles().back()->in(), dcp::Time (0, 1, 57, 17, 25));
119 BOOST_CHECK_EQUAL (sc.subtitles().back()->out(), dcp::Time (0, 1, 58, 12, 25));
123 /** And another one featuring <Font> within <Text> */
124 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
126 dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
128 auto subs = sc.subtitles();
129 BOOST_REQUIRE_EQUAL (subs.size(), 6);
130 auto i = subs.begin();
131 auto is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
133 BOOST_CHECK_EQUAL (is->text(), "Testing is ");
134 BOOST_CHECK (!is->italic());
136 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
138 BOOST_CHECK_EQUAL (is->text(), "really");
139 BOOST_CHECK (is->italic());
141 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
143 BOOST_CHECK_EQUAL (is->text(), " fun!");
144 BOOST_CHECK (!is->italic());
146 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
148 BOOST_CHECK_EQUAL (is->text(), "This is the ");
149 BOOST_CHECK (!is->italic());
151 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
153 BOOST_CHECK_EQUAL (is->text(), "second");
154 BOOST_CHECK (is->italic());
156 is = dynamic_pointer_cast<const dcp::SubtitleString>(*i);
158 BOOST_CHECK_EQUAL (is->text(), " line!");
159 BOOST_CHECK (!is->italic());
163 /** And another one featuring image subtitles */
164 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
166 dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
168 BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
169 auto si = dynamic_pointer_cast<const dcp::SubtitleImage>(subs.subtitles().front());
171 BOOST_CHECK (si->png_image() == dcp::Data("test/data/sub.png"));