Format XML sub output nicely with indents and such.
[libdcp.git] / test / read_smpte_subtitle_test.cc
1 /*
2     Copyright (C) 2015 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
20 #include "smpte_subtitle_asset.h"
21 #include "test.h"
22 #include "local_time.h"
23 #include "smpte_load_font_node.h"
24 #include <boost/test/unit_test.hpp>
25 #include <boost/optional.hpp>
26 #include <boost/optional/optional_io.hpp>
27
28 using std::list;
29 using boost::shared_ptr;
30 using boost::dynamic_pointer_cast;
31
32 /** Check reading of a SMPTE subtitle file */
33 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
34 {
35         dcp::SMPTESubtitleAsset sc (
36                 private_test /
37                 "data" /
38                 "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" /
39                 "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf"
40                 );
41
42         BOOST_CHECK_EQUAL (sc.id(), "8b48f6ae-c74b-4b80-b994-a8236bbbad74");
43         BOOST_CHECK_EQUAL (sc.content_title_text(), "Journey to Jah");
44         BOOST_REQUIRE (sc.annotation_text());
45         BOOST_CHECK_EQUAL (sc.annotation_text().get(), "Journey to Jah");
46         BOOST_CHECK_EQUAL (sc.issue_date(), dcp::LocalTime ("2014-02-25T11:22:48.000-00:00"));
47         BOOST_REQUIRE (sc.reel_number());
48         BOOST_CHECK_EQUAL (sc.reel_number().get(), 1);
49         BOOST_REQUIRE (sc.language ());
50         BOOST_CHECK_EQUAL (sc.language().get (), "de");
51         BOOST_CHECK_EQUAL (sc.edit_rate(), dcp::Fraction (25, 1));
52         BOOST_CHECK_EQUAL (sc.time_code_rate(), 25);
53         BOOST_CHECK_EQUAL (sc.start_time(), dcp::Time (0, 0, 0, 0, 25));
54         list<shared_ptr<dcp::LoadFontNode> > lfn = sc.load_font_nodes ();
55         BOOST_REQUIRE_EQUAL (lfn.size(), 1);
56         shared_ptr<dcp::SMPTELoadFontNode> smpte_lfn = dynamic_pointer_cast<dcp::SMPTELoadFontNode> (lfn.front ());
57         BOOST_REQUIRE (smpte_lfn);
58         BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
59         BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
60         BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
61         BOOST_CHECK_EQUAL (sc.subtitles().front().text(), "Noch mal.");
62         BOOST_CHECK_EQUAL (sc.subtitles().front().in(), dcp::Time (0, 0, 25, 12, 25));
63         BOOST_CHECK_EQUAL (sc.subtitles().front().out(), dcp::Time (0, 0, 26, 4, 25));
64         BOOST_CHECK_EQUAL (sc.subtitles().back().text(), "Prochainement");
65         BOOST_CHECK_EQUAL (sc.subtitles().back().in(), dcp::Time (0, 1, 57, 17, 25));
66         BOOST_CHECK_EQUAL (sc.subtitles().back().out(), dcp::Time (0, 1, 58, 12, 25));
67 }
68
69 /** And another one featuring <Font> within <Text> */
70 BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
71 {
72         dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
73
74         BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 6);
75         list<dcp::SubtitleString>::const_iterator i = sc.subtitles().begin();
76         BOOST_CHECK_EQUAL (i->text(), "Testing is ");
77         BOOST_CHECK (!i->italic());
78         ++i;
79         BOOST_CHECK_EQUAL (i->text(), "really");
80         BOOST_CHECK (i->italic());
81         ++i;
82         BOOST_CHECK_EQUAL (i->text(), " fun!");
83         BOOST_CHECK (!i->italic());
84         ++i;
85         BOOST_CHECK_EQUAL (i->text(), "This is the ");
86         BOOST_CHECK (!i->italic());
87         ++i;
88         BOOST_CHECK_EQUAL (i->text(), "second");
89         BOOST_CHECK (i->italic());
90         ++i;
91         BOOST_CHECK_EQUAL (i->text(), " line!");
92         BOOST_CHECK (!i->italic());
93 }