Whitespace.
[libdcp.git] / test / read_smpte_subtitle_test.cc
1 /*
2     Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
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.
10
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.
15
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/>.
18
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
23     including the two.
24
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.
32 */
33
34 #include "smpte_subtitle_asset.h"
35 #include "test.h"
36 #include "local_time.h"
37 #include "smpte_load_font_node.h"
38 #include "subtitle_image.h"
39 #include "stream_operators.h"
40 #include <boost/test/unit_test.hpp>
41 #include <boost/optional.hpp>
42 #include <boost/optional/optional_io.hpp>
43
44 using std::list;
45 using std::shared_ptr;
46 using std::dynamic_pointer_cast;
47
48 /** Check reading of a SMPTE subtitle file */
49 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
50 {
51         dcp::SMPTESubtitleAsset sc (
52                 private_test /
53                 "data" /
54                 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
55                 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
56                 );
57
58         BOOST_CHECK_EQUAL (sc.id(), "8b48f6ae-c74b-4b80-b994-a8236bbbad74");
59         BOOST_CHECK_EQUAL (sc.content_title_text(), "Journey to Jah");
60         BOOST_REQUIRE (sc.annotation_text());
61         BOOST_CHECK_EQUAL (sc.annotation_text().get(), "Journey to Jah");
62         BOOST_CHECK_EQUAL (sc.issue_date(), dcp::LocalTime ("2014-02-25T11:22:48.000-00:00"));
63         BOOST_REQUIRE (sc.reel_number());
64         BOOST_CHECK_EQUAL (sc.reel_number().get(), 1);
65         BOOST_REQUIRE (sc.language ());
66         BOOST_CHECK_EQUAL (sc.language().get (), "de");
67         BOOST_CHECK_EQUAL (sc.edit_rate(), dcp::Fraction (25, 1));
68         BOOST_CHECK_EQUAL (sc.time_code_rate(), 25);
69         BOOST_CHECK_EQUAL (sc.start_time(), dcp::Time (0, 0, 0, 0, 25));
70         auto lfn = sc.load_font_nodes ();
71         BOOST_REQUIRE_EQUAL (lfn.size(), 1);
72         shared_ptr<dcp::SMPTELoadFontNode> smpte_lfn = dynamic_pointer_cast<dcp::SMPTELoadFontNode> (lfn.front ());
73         BOOST_REQUIRE (smpte_lfn);
74         BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
75         BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
76         BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
77         BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front()));
78         BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().front())->text(), "Noch mal.");
79         BOOST_CHECK_EQUAL (sc.subtitles().front()->in(), dcp::Time (0, 0, 25, 12, 25));
80         BOOST_CHECK_EQUAL (sc.subtitles().front()->out(), dcp::Time (0, 0, 26, 4, 25));
81         BOOST_REQUIRE (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back()));
82         BOOST_CHECK_EQUAL (dynamic_pointer_cast<const dcp::SubtitleString>(sc.subtitles().back())->text(), "Prochainement");
83         BOOST_CHECK_EQUAL (sc.subtitles().back()->in(), dcp::Time (0, 1, 57, 17, 25));
84         BOOST_CHECK_EQUAL (sc.subtitles().back()->out(), dcp::Time (0, 1, 58, 12, 25));
85 }
86
87 /** And another one featuring <Font> within <Text> */
88 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
89 {
90         dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
91
92         auto subs = sc.subtitles();
93         BOOST_REQUIRE_EQUAL (subs.size(), 6);
94         auto i = 0;
95         auto is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
96         BOOST_REQUIRE (is);
97         BOOST_CHECK_EQUAL (is->text(), "Testing is ");
98         BOOST_CHECK (!is->italic());
99         ++i;
100         is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
101         BOOST_REQUIRE (is);
102         BOOST_CHECK_EQUAL (is->text(), "really");
103         BOOST_CHECK (is->italic());
104         ++i;
105         is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
106         BOOST_REQUIRE (is);
107         BOOST_CHECK_EQUAL (is->text(), " fun!");
108         BOOST_CHECK (!is->italic());
109         ++i;
110         is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
111         BOOST_REQUIRE (is);
112         BOOST_CHECK_EQUAL (is->text(), "This is the ");
113         BOOST_CHECK (!is->italic());
114         ++i;
115         is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
116         BOOST_REQUIRE (is);
117         BOOST_CHECK_EQUAL (is->text(), "second");
118         BOOST_CHECK (is->italic());
119         ++i;
120         is = dynamic_pointer_cast<const dcp::SubtitleString>(subs[i]);
121         BOOST_REQUIRE (is);
122         BOOST_CHECK_EQUAL (is->text(), " line!");
123         BOOST_CHECK (!is->italic());
124 }
125
126 /** And another one featuring image subtitles */
127 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
128 {
129         dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
130
131         BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
132         auto si = dynamic_pointer_cast<const dcp::SubtitleImage>(subs.subtitles()[0]);
133         BOOST_REQUIRE (si);
134         BOOST_CHECK (si->png_image() == dcp::ArrayData("test/data/sub.png"));
135 }