2 Copyright (C) 2015-2019 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.
34 #include "smpte_subtitle_asset.h"
36 #include "local_time.h"
37 #include "smpte_load_font_node.h"
38 #include "subtitle_image.h"
39 #include <boost/test/unit_test.hpp>
40 #include <boost/optional.hpp>
41 #include <boost/optional/optional_io.hpp>
44 using std::shared_ptr;
45 using std::dynamic_pointer_cast;
47 /** Check reading of a SMPTE subtitle file */
48 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
50 dcp::SMPTESubtitleAsset sc (
53 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
54 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
57 BOOST_CHECK_EQUAL (sc.id(), "8b48f6ae-c74b-4b80-b994-a8236bbbad74");
58 BOOST_CHECK_EQUAL (sc.content_title_text(), "Journey to Jah");
59 BOOST_REQUIRE (sc.annotation_text());
60 BOOST_CHECK_EQUAL (sc.annotation_text().get(), "Journey to Jah");
61 BOOST_CHECK_EQUAL (sc.issue_date(), dcp::LocalTime ("2014-02-25T11:22:48.000-00:00"));
62 BOOST_REQUIRE (sc.reel_number());
63 BOOST_CHECK_EQUAL (sc.reel_number().get(), 1);
64 BOOST_REQUIRE (sc.language ());
65 BOOST_CHECK_EQUAL (sc.language().get (), "de");
66 BOOST_CHECK_EQUAL (sc.edit_rate(), dcp::Fraction (25, 1));
67 BOOST_CHECK_EQUAL (sc.time_code_rate(), 25);
68 BOOST_CHECK_EQUAL (sc.start_time(), dcp::Time (0, 0, 0, 0, 25));
69 auto lfn = sc.load_font_nodes ();
70 BOOST_REQUIRE_EQUAL (lfn.size(), 1);
71 shared_ptr<dcp::SMPTELoadFontNode> smpte_lfn = dynamic_pointer_cast<dcp::SMPTELoadFontNode> (lfn.front ());
72 BOOST_REQUIRE (smpte_lfn);
73 BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
74 BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
75 BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
76 BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front()));
77 BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front())->text(), "Noch mal.");
78 BOOST_CHECK_EQUAL (sc.subtitles().front()->in(), dcp::Time (0, 0, 25, 12, 25));
79 BOOST_CHECK_EQUAL (sc.subtitles().front()->out(), dcp::Time (0, 0, 26, 4, 25));
80 BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back()));
81 BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back())->text(), "Prochainement");
82 BOOST_CHECK_EQUAL (sc.subtitles().back()->in(), dcp::Time (0, 1, 57, 17, 25));
83 BOOST_CHECK_EQUAL (sc.subtitles().back()->out(), dcp::Time (0, 1, 58, 12, 25));
86 /** And another one featuring <Font> within <Text> */
87 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
89 dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
91 auto subs = sc.subtitles();
92 BOOST_REQUIRE_EQUAL (subs.size(), 6);
94 auto is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
96 BOOST_CHECK_EQUAL (is->text(), "Testing is ");
97 BOOST_CHECK (!is->italic());
99 is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
101 BOOST_CHECK_EQUAL (is->text(), "really");
102 BOOST_CHECK (is->italic());
104 is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
106 BOOST_CHECK_EQUAL (is->text(), " fun!");
107 BOOST_CHECK (!is->italic());
109 is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
111 BOOST_CHECK_EQUAL (is->text(), "This is the ");
112 BOOST_CHECK (!is->italic());
114 is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
116 BOOST_CHECK_EQUAL (is->text(), "second");
117 BOOST_CHECK (is->italic());
119 is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
121 BOOST_CHECK_EQUAL (is->text(), " line!");
122 BOOST_CHECK (!is->italic());
125 /** And another one featuring image subtitles */
126 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
128 dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
130 BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
131 auto si = dynamic_pointer_cast<const dcp::SubtitleImage>(subs.subtitles()[0]);
133 BOOST_CHECK (si->png_image() == dcp::ArrayData("test/data/sub.png"));