Add -x32/-x64 suffix to boost libraries when building for Windows.
[dcpomatic.git] / test / hints_test.cc
1 /*
2     Copyright (C) 2020-2022 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
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"
27 #include "lib/film.h"
28 #include "lib/font.h"
29 #include "lib/hints.h"
30 #include "lib/text_content.h"
31 #include "lib/util.h"
32 #include "test.h"
33 #include <boost/test/unit_test.hpp>
34
35
36 using std::make_shared;
37 using std::shared_ptr;
38 using std::string;
39 using std::vector;
40 using boost::optional;
41
42
43 vector<string> current_hints;
44
45
46 static
47 void
48 collect_hint (string hint)
49 {
50         current_hints.push_back (hint);
51 }
52
53
54 static
55 vector<string>
56 get_hints (shared_ptr<Film> film)
57 {
58         current_hints.clear ();
59         Hints hints (film);
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);
63         hints.start ();
64         hints.join ();
65         while (signal_manager->ui_idle()) {}
66         return current_hints;
67 }
68
69
70 static
71 void
72 check (TextType type, string name, optional<string> expected_hint = optional<string>())
73 {
74         auto film = new_test_film2 (name);
75         auto content = content_factory("test/data/" + name + ".srt").front();
76         content->text.front()->set_type (type);
77         content->text.front()->set_language (dcp::LanguageTag("en-US"));
78         film->examine_and_add_content (content);
79         BOOST_REQUIRE (!wait_for_jobs());
80         auto hints = get_hints (film);
81
82         if (expected_hint) {
83                 BOOST_REQUIRE_EQUAL (hints.size(), 1U);
84                 BOOST_CHECK_EQUAL (hints[0], *expected_hint);
85         } else {
86                 BOOST_CHECK (hints.empty());
87         }
88 }
89
90
91 BOOST_AUTO_TEST_CASE (hint_closed_caption_too_long)
92 {
93         check (
94                 TextType::CLOSED_CAPTION,
95                 "hint_closed_caption_too_long",
96                 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)
97               );
98 }
99
100
101 BOOST_AUTO_TEST_CASE (hint_many_closed_caption_lines)
102 {
103         check (
104                 TextType::CLOSED_CAPTION,
105                 "hint_many_closed_caption_lines",
106                 String::compose("Some of your closed captions span more than %1 lines, so they will be truncated.", MAX_CLOSED_CAPTION_LINES)
107               );
108 }
109
110
111 BOOST_AUTO_TEST_CASE (hint_subtitle_too_early)
112 {
113         check (
114                 TextType::OPEN_SUBTITLE,
115                 "hint_subtitle_too_early",
116                 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.")
117                 );
118 }
119
120
121 BOOST_AUTO_TEST_CASE (hint_short_subtitles)
122 {
123         check (
124                 TextType::OPEN_SUBTITLE,
125                 "hint_short_subtitles",
126                 string("At least one of your subtitles lasts less than 15 frames.  It is advisable to make each subtitle at least 15 frames long.")
127                 );
128 }
129
130
131 BOOST_AUTO_TEST_CASE (hint_subtitles_too_close)
132 {
133         check (
134                 TextType::OPEN_SUBTITLE,
135                 "hint_subtitles_too_close",
136                 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.")
137               );
138 }
139
140
141 BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
142 {
143         check (
144                 TextType::OPEN_SUBTITLE,
145                 "hint_many_subtitle_lines",
146                 string("At least one of your subtitles has more than 3 lines.  It is advisable to use no more than 3 lines.")
147               );
148 }
149
150
151 BOOST_AUTO_TEST_CASE (hint_subtitle_too_long)
152 {
153         check (
154                 TextType::OPEN_SUBTITLE,
155                 "hint_subtitle_too_long",
156                 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.")
157               );
158 }
159
160
161 BOOST_AUTO_TEST_CASE (hint_subtitle_much_too_long)
162 {
163         check (
164                 TextType::OPEN_SUBTITLE,
165                 "hint_subtitle_much_too_long",
166                 string("At least one of your subtitle lines has more than 79 characters.  You should make each line 79 characters at most in length.")
167               );
168 }
169
170
171 BOOST_AUTO_TEST_CASE (hint_subtitle_mxf_too_big)
172 {
173         string const name = "hint_subtitle_mxf_too_big";
174
175         auto film = new_test_film2 (name);
176         auto content = content_factory("test/data/" + name + ".srt").front();
177         content->text.front()->set_type (TextType::OPEN_SUBTITLE);
178         content->text.front()->set_language (dcp::LanguageTag("en-US"));
179         for (int i = 1; i < 512; ++i) {
180                 auto font = make_shared<dcpomatic::Font>(String::compose("font_%1", i));
181                 font->set_file ("test/data/LiberationSans-Regular.ttf");
182                 content->text.front()->add_font(font);
183         }
184         film->examine_and_add_content (content);
185         BOOST_REQUIRE (!wait_for_jobs());
186         auto hints = get_hints (film);
187
188         BOOST_REQUIRE_EQUAL (hints.size(), 1U);
189         BOOST_CHECK_EQUAL (
190                 hints[0],
191                 "At least one of your subtitle files is larger than " MAX_TEXT_MXF_SIZE_TEXT " in total.  "
192                 "You should divide the DCP into shorter reels."
193                 );
194 }
195
196
197 BOOST_AUTO_TEST_CASE (hint_closed_caption_xml_too_big)
198 {
199         string const name = "hint_closed_caption_xml_too_big";
200
201         auto film = new_test_film2 (name);
202
203         auto ccap = fopen_boost (String::compose("build/test/%1.srt", name), "w");
204         BOOST_REQUIRE (ccap);
205         for (int i = 0; i < 2048; ++i) {
206                 fprintf(ccap, "%d\n", i + 1);
207                 int second = i * 2;
208                 int minute = second % 60;
209                 fprintf(ccap, "00:%02d:%02d,000 --> 00:%02d:%02d,000\n", minute, second, minute, second + 1);
210                 fprintf(ccap, "Here are some closed captions.\n\n");
211         }
212         fclose (ccap);
213
214         auto content = content_factory("build/test/" + name + ".srt").front();
215         content->text.front()->set_type (TextType::CLOSED_CAPTION);
216         content->text.front()->set_language (dcp::LanguageTag("en-US"));
217         film->examine_and_add_content (content);
218         BOOST_REQUIRE (!wait_for_jobs());
219         auto hints = get_hints (film);
220
221         BOOST_REQUIRE_EQUAL (hints.size(), 1U);
222         BOOST_CHECK_EQUAL (
223                 hints[0],
224                 "At least one of your closed caption files' XML part is larger than " MAX_CLOSED_CAPTION_XML_SIZE_TEXT ".  "
225                 "You should divide the DCP into shorter reels."
226                 );
227 }
228
229
230 BOOST_AUTO_TEST_CASE (hints_destroyed_while_running)
231 {
232         auto film = new_test_film2 ("hints_destroyed_while_running");
233         auto content = content_factory(TestPaths::private_data() / "boon_telly.mkv").front();
234         film->examine_and_add_content (content);
235         BOOST_REQUIRE (!wait_for_jobs());
236
237         auto hints = make_shared<Hints>(film);
238         hints->start ();
239         dcpomatic_sleep_seconds (1);
240         hints.reset ();
241         dcpomatic_sleep_seconds (1);
242 }
243
244
245 BOOST_AUTO_TEST_CASE (hints_audio_with_no_language)
246 {
247         auto content = content_factory("test/data/sine_440.wav").front();
248         auto film = new_test_film2 ("hints_audio_with_no_language", { content });
249         content->audio->set_gain (-6);
250
251         auto hints = get_hints (film);
252         BOOST_REQUIRE_EQUAL (hints.size(), 1U);
253         BOOST_CHECK_EQUAL (
254                 hints[0],
255                 "Some of your content has audio but you have not set the audio language.  It is advisable to set the audio language "
256                 "in the \"DCP\" tab unless your audio has no spoken parts."
257                 );
258 }
259
260
261 BOOST_AUTO_TEST_CASE (hints_certificate_validity)
262 {
263         ConfigRestorer cr;
264
265         Config::instance()->set_signer_chain(make_shared<dcp::CertificateChain>(openssl_path(), 40 * 365));
266
267         auto film = new_test_film2 ("hints_certificate_validity");
268         auto hints = get_hints (film);
269         BOOST_REQUIRE_EQUAL (hints.size(), 1U);
270         BOOST_CHECK_EQUAL (
271                 hints[0],
272                 "The certificate chain that DCP-o-matic uses for signing DCPs and KDMs has a validity period "
273                 "that is too long.  This will cause problems playing back DCPs on some systems. "
274                 "You are advised to re-create the signing certificate chain by clicking the "
275                 "\"Re-make certificates and key...\" button in the Keys page of Preferences."
276                 );
277 }
278