8fbf02144dad494d5d028d3d132f083d72304e24
[libdcp.git] / test / read_smpte_subtitle_test.cc
1 /*
2     Copyright (C) 2015-2019 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 <boost/test/unit_test.hpp>
40 #include <boost/optional.hpp>
41 #include <boost/optional/optional_io.hpp>
42
43 using std::list;
44 using std::shared_ptr;
45 using std::dynamic_pointer_cast;
46
47 /** Check reading of a SMPTE subtitle file */
48 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
49 {
50         dcp::SMPTESubtitleAsset sc (
51                 private_test /
52                 "data" /
53                 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
54                 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
55                 );
56
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<dcp::SubtitleString>(sc.subtitles().front()));
77         BOOST_CHECK_EQUAL (dynamic_pointer_cast<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<dcp::SubtitleString>(sc.subtitles().back()));
81         BOOST_CHECK_EQUAL (dynamic_pointer_cast<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));
84 }
85
86 /** And another one featuring <Font> within <Text> */
87 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
88 {
89         dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
90
91         BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 6);
92         auto i = sc.subtitles().begin();
93         shared_ptr<dcp::SubtitleString> is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
94         BOOST_REQUIRE (is);
95         BOOST_CHECK_EQUAL (is->text(), "Testing is ");
96         BOOST_CHECK (!is->italic());
97         ++i;
98         is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
99         BOOST_REQUIRE (is);
100         BOOST_CHECK_EQUAL (is->text(), "really");
101         BOOST_CHECK (is->italic());
102         ++i;
103         is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
104         BOOST_REQUIRE (is);
105         BOOST_CHECK_EQUAL (is->text(), " fun!");
106         BOOST_CHECK (!is->italic());
107         ++i;
108         is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
109         BOOST_REQUIRE (is);
110         BOOST_CHECK_EQUAL (is->text(), "This is the ");
111         BOOST_CHECK (!is->italic());
112         ++i;
113         is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
114         BOOST_REQUIRE (is);
115         BOOST_CHECK_EQUAL (is->text(), "second");
116         BOOST_CHECK (is->italic());
117         ++i;
118         is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
119         BOOST_REQUIRE (is);
120         BOOST_CHECK_EQUAL (is->text(), " line!");
121         BOOST_CHECK (!is->italic());
122 }
123
124 /** And another one featuring image subtitles */
125 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
126 {
127         dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
128
129         BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
130         shared_ptr<dcp::SubtitleImage> si = dynamic_pointer_cast<dcp::SubtitleImage>(subs.subtitles().front());
131         BOOST_REQUIRE (si);
132         BOOST_CHECK (si->png_image() == dcp::ArrayData("test/data/sub.png"));
133 }