2 Copyright (C) 2020-2022 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic 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 DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/audio_content.h"
23 #include "lib/config.h"
24 #include "lib/content.h"
25 #include "lib/content_factory.h"
26 #include "lib/cross.h"
29 #include "lib/hints.h"
30 #include "lib/text_content.h"
33 #include <boost/test/unit_test.hpp>
36 using std::make_shared;
37 using std::shared_ptr;
40 using boost::optional;
43 vector<string> current_hints;
48 collect_hint (string hint)
50 current_hints.push_back (hint);
56 get_hints (shared_ptr<Film> film)
58 current_hints.clear ();
60 /* None of our tests need the audio analysis, and it is quite time-consuming */
61 hints.disable_audio_analysis ();
62 hints.Hint.connect (collect_hint);
65 while (signal_manager->ui_idle()) {}
73 check (TextType type, string name, optional<string> expected_hint = optional<string>())
75 auto film = new_test_film2 (name);
76 auto content = content_factory("test/data/" + name + ".srt")[0];
77 content->text.front()->set_type (type);
78 content->text.front()->set_language (dcp::LanguageTag("en-US"));
79 film->examine_and_add_content (content);
80 BOOST_REQUIRE (!wait_for_jobs());
81 auto hints = get_hints (film);
84 BOOST_REQUIRE_EQUAL (hints.size(), 1U);
85 BOOST_CHECK_EQUAL (hints[0], *expected_hint);
87 BOOST_CHECK (hints.empty());
92 BOOST_AUTO_TEST_CASE (hint_closed_caption_too_long)
95 TextType::CLOSED_CAPTION,
96 "hint_closed_caption_too_long",
97 String::compose("At least one of your closed caption lines has more than %1 characters. It is advisable to make each line %1 characters at most in length.", MAX_CLOSED_CAPTION_LENGTH, MAX_CLOSED_CAPTION_LENGTH)
102 BOOST_AUTO_TEST_CASE (hint_many_closed_caption_lines)
105 TextType::CLOSED_CAPTION,
106 "hint_many_closed_caption_lines",
107 String::compose("Some of your closed captions span more than %1 lines, so they will be truncated.", MAX_CLOSED_CAPTION_LINES)
112 BOOST_AUTO_TEST_CASE (hint_subtitle_too_early)
115 TextType::OPEN_SUBTITLE,
116 "hint_subtitle_too_early",
117 string("It is advisable to put your first subtitle at least 4 seconds after the start of the DCP to make sure it is seen.")
122 BOOST_AUTO_TEST_CASE (hint_short_subtitles)
125 TextType::OPEN_SUBTITLE,
126 "hint_short_subtitles",
127 string("At least one of your subtitles lasts less than 15 frames. It is advisable to make each subtitle at least 15 frames long.")
132 BOOST_AUTO_TEST_CASE (hint_subtitles_too_close)
135 TextType::OPEN_SUBTITLE,
136 "hint_subtitles_too_close",
137 string("At least one of your subtitles starts less than 2 frames after the previous one. It is advisable to make the gap between subtitles at least 2 frames.")
142 BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
145 TextType::OPEN_SUBTITLE,
146 "hint_many_subtitle_lines",
147 string("At least one of your subtitles has more than 3 lines. It is advisable to use no more than 3 lines.")
152 BOOST_AUTO_TEST_CASE (hint_subtitle_too_long)
155 TextType::OPEN_SUBTITLE,
156 "hint_subtitle_too_long",
157 string("At least one of your subtitle lines has more than 52 characters. It is recommended to make each line 52 characters at most in length.")
162 BOOST_AUTO_TEST_CASE (hint_subtitle_much_too_long)
165 TextType::OPEN_SUBTITLE,
166 "hint_subtitle_much_too_long",
167 string("At least one of your subtitle lines has more than 79 characters. You should make each line 79 characters at most in length.")
172 BOOST_AUTO_TEST_CASE (hint_subtitle_mxf_too_big)
174 string const name = "hint_subtitle_mxf_too_big";
176 dcp::File fake_font("build/test/hint_subtitle_mxf_too_big.ttf", "w");
177 for (int i = 0; i < 4096; ++i) {
178 std::vector<uint8_t> rubbish(65536);
179 fake_font.write(rubbish.data(), 1, rubbish.size());
183 auto film = new_test_film2 (name);
184 auto content = content_factory("test/data/" + name + ".srt")[0];
185 content->text.front()->set_type (TextType::OPEN_SUBTITLE);
186 content->text.front()->set_language (dcp::LanguageTag("en-US"));
187 film->examine_and_add_content (content);
188 BOOST_REQUIRE (!wait_for_jobs());
189 content->text.front()->get_font("")->set_file("build/test/hint_subtitle_mxf_too_big.ttf");
190 auto hints = get_hints (film);
192 BOOST_REQUIRE_EQUAL (hints.size(), 1U);
195 "At least one of your subtitle files is larger than " MAX_TEXT_MXF_SIZE_TEXT " in total. "
196 "You should divide the DCP into shorter reels."
201 BOOST_AUTO_TEST_CASE (hint_closed_caption_xml_too_big)
203 string const name = "hint_closed_caption_xml_too_big";
205 auto film = new_test_film2 (name);
207 dcp::File ccap(String::compose("build/test/%1.srt", name), "w");
208 BOOST_REQUIRE (ccap);
209 for (int i = 0; i < 2048; ++i) {
210 fprintf(ccap.get(), "%d\n", i + 1);
212 int minute = second % 60;
213 fprintf(ccap.get(), "00:%02d:%02d,000 --> 00:%02d:%02d,000\n", minute, second, minute, second + 1);
214 fprintf(ccap.get(), "Here are some closed captions.\n\n");
218 auto content = content_factory("build/test/" + name + ".srt")[0];
219 content->text.front()->set_type (TextType::CLOSED_CAPTION);
220 content->text.front()->set_language (dcp::LanguageTag("en-US"));
221 film->examine_and_add_content (content);
222 BOOST_REQUIRE (!wait_for_jobs());
223 auto hints = get_hints (film);
225 BOOST_REQUIRE_EQUAL (hints.size(), 1U);
228 "At least one of your closed caption files' XML part is larger than " MAX_CLOSED_CAPTION_XML_SIZE_TEXT ". "
229 "You should divide the DCP into shorter reels."
234 BOOST_AUTO_TEST_CASE (hints_destroyed_while_running)
236 auto film = new_test_film2 ("hints_destroyed_while_running");
237 auto content = content_factory(TestPaths::private_data() / "boon_telly.mkv")[0];
238 film->examine_and_add_content (content);
239 BOOST_REQUIRE (!wait_for_jobs());
241 auto hints = make_shared<Hints>(film);
243 dcpomatic_sleep_seconds (1);
245 dcpomatic_sleep_seconds (1);
249 BOOST_AUTO_TEST_CASE (hints_audio_with_no_language)
251 auto content = content_factory("test/data/sine_440.wav")[0];
252 auto film = new_test_film2 ("hints_audio_with_no_language", { content });
253 content->audio->set_gain (-6);
255 auto hints = get_hints (film);
256 BOOST_REQUIRE_EQUAL (hints.size(), 1U);
259 "Some of your content has audio but you have not set the audio language. It is advisable to set the audio language "
260 "in the \"DCP\" tab unless your audio has no spoken parts."
265 BOOST_AUTO_TEST_CASE (hints_certificate_validity)
269 Config::instance()->set_signer_chain(make_shared<dcp::CertificateChain>(openssl_path(), 40 * 365));
271 auto film = new_test_film2 ("hints_certificate_validity");
272 auto hints = get_hints (film);
273 BOOST_REQUIRE_EQUAL (hints.size(), 1U);
276 "The certificate chain that DCP-o-matic uses for signing DCPs and KDMs has a validity period "
277 "that is too long. This will cause problems playing back DCPs on some systems. "
278 "You are advised to re-create the signing certificate chain by clicking the "
279 "\"Re-make certificates and key...\" button in the Keys page of Preferences."