2 Copyright (C) 2015-2021 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 "interop_subtitle_asset.h"
35 #include "smpte_subtitle_asset.h"
36 #include "subtitle_string.h"
37 #include "subtitle_image.h"
38 #include "subtitle_asset_internal.h"
39 #include "reel_interop_subtitle_asset.h"
45 #include <boost/test/unit_test.hpp>
48 using std::shared_ptr;
50 using std::make_shared;
51 using boost::optional;
53 /** Test dcp::order::Font::take_intersection */
54 BOOST_AUTO_TEST_CASE (take_intersection_test)
57 A._values["foo"] = "bar";
58 A._values["fred"] = "jim";
61 B._values["foo"] = "bar";
62 B._values["sheila"] = "baz";
64 A.take_intersection (B);
65 BOOST_REQUIRE_EQUAL (A._values.size(), 1);
66 BOOST_CHECK_EQUAL (A._values["foo"], "bar");
71 A._values["foo"] = "bar";
72 A._values["fred"] = "jim";
74 B._values["foo"] = "hello";
75 B._values["sheila"] = "baz";
77 A.take_intersection (B);
78 BOOST_CHECK_EQUAL (A._values.size(), 0);
81 /** Test dcp::order::Font::take_difference */
82 BOOST_AUTO_TEST_CASE (take_difference_test)
85 A._values["foo"] = "bar";
86 A._values["fred"] = "jim";
89 B._values["foo"] = "bar";
90 B._values["sheila"] = "baz";
92 A.take_difference (B);
93 BOOST_REQUIRE_EQUAL (A._values.size(), 1);
94 BOOST_CHECK_EQUAL (A._values["fred"], "jim");
97 /** Test dcp::order::Subtitle::pull_fonts */
98 BOOST_AUTO_TEST_CASE (pull_fonts_test1)
100 auto root = make_shared<dcp::order::Part>(shared_ptr<dcp::order::Part>());
101 auto sub1 = make_shared<dcp::order::Subtitle>(root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time());
102 root->children.push_back (sub1);
103 auto text1 = make_shared<dcp::order::Text>(sub1, dcp::HAlign::CENTER, 0, dcp::VAlign::TOP, 0, dcp::Direction::LTR);
104 sub1->children.push_back (text1);
105 text1->font._values["font"] = "Inconsolata";
106 text1->font._values["size"] = "42";
108 dcp::SubtitleAsset::pull_fonts (root);
110 BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2);
111 BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
112 BOOST_CHECK_EQUAL (sub1->font._values["size"], "42");
113 BOOST_CHECK_EQUAL (text1->font._values.size(), 0);
116 /** Test dcp::order::Subtitle::pull_fonts */
117 BOOST_AUTO_TEST_CASE (pull_fonts_test2)
119 auto root = make_shared<dcp::order::Part>(shared_ptr<dcp::order::Part> ());
120 auto sub1 = make_shared<dcp::order::Subtitle>(root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time());
121 root->children.push_back (sub1);
122 auto text1 = make_shared<dcp::order::Text>(sub1, dcp::HAlign::CENTER, 0, dcp::VAlign::TOP, 0, dcp::Direction::LTR);
123 sub1->children.push_back (text1);
124 text1->font._values["font"] = "Inconsolata";
125 text1->font._values["size"] = "42";
126 auto text2 = make_shared<dcp::order::Text>(sub1, dcp::HAlign::CENTER, 0, dcp::VAlign::TOP, 0, dcp::Direction::LTR);
127 sub1->children.push_back (text2);
128 text2->font._values["font"] = "Inconsolata";
129 text2->font._values["size"] = "48";
131 dcp::SubtitleAsset::pull_fonts (root);
133 BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 1);
134 BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
135 BOOST_REQUIRE_EQUAL (text1->font._values.size(), 1);
136 BOOST_CHECK_EQUAL (text1->font._values["size"], "42");
137 BOOST_REQUIRE_EQUAL (text2->font._values.size(), 1);
138 BOOST_CHECK_EQUAL (text2->font._values["size"], "48");
141 /** Test dcp::order::Subtitle::pull_fonts */
142 BOOST_AUTO_TEST_CASE (pull_fonts_test3)
144 auto root = make_shared<dcp::order::Part>(shared_ptr<dcp::order::Part> ());
145 auto sub1 = make_shared<dcp::order::Subtitle>(root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time());
146 root->children.push_back (sub1);
147 auto text1 = make_shared<dcp::order::Text>(sub1, dcp::HAlign::CENTER, 0, dcp::VAlign::TOP, 0, dcp::Direction::LTR);
148 sub1->children.push_back (text1);
149 dcp::order::Font font;
150 font._values["font"] = "Inconsolata";
151 font._values["size"] = "42";
152 auto string1 = make_shared<dcp::order::String>(text1, font, "Hello world");
153 text1->children.push_back (string1);
155 dcp::SubtitleAsset::pull_fonts (root);
157 BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2);
158 BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata");
159 BOOST_CHECK_EQUAL (sub1->font._values["size"], "42");