summaryrefslogtreecommitdiff
path: root/test/hints_test.cc
blob: 827427222d7bf5bef99d560b61523a37ebb450c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
    Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#include "lib/audio_content.h"
#include "lib/content.h"
#include "lib/content_factory.h"
#include "lib/cross.h"
#include "lib/film.h"
#include "lib/font.h"
#include "lib/hints.h"
#include "lib/text_content.h"
#include "lib/util.h"
#include "test.h"
#include <boost/test/unit_test.hpp>


using std::make_shared;
using std::shared_ptr;
using std::string;
using std::vector;
using boost::optional;


vector<string> current_hints;


static
void
collect_hint (string hint)
{
	current_hints.push_back (hint);
}


static
vector<string>
get_hints (shared_ptr<Film> film)
{
	current_hints.clear ();
	Hints hints (film);
	hints.Hint.connect (collect_hint);
	hints.start ();
	hints.join ();
	while (signal_manager->ui_idle()) {}
	return current_hints;
}


static
void
check (TextType type, string name, optional<string> expected_hint = optional<string>())
{
	auto film = new_test_film2 (name);
	auto content = content_factory("test/data/" + name + ".srt").front();
	content->text.front()->set_type (type);
	content->text.front()->set_language (dcp::LanguageTag("en-US"));
	film->examine_and_add_content (content);
	BOOST_REQUIRE (!wait_for_jobs());
	auto hints = get_hints (film);

	if (expected_hint) {
		BOOST_REQUIRE_EQUAL (hints.size(), 1U);
		BOOST_CHECK_EQUAL (hints[0], *expected_hint);
	} else {
		BOOST_CHECK (hints.empty());
	}
}


BOOST_AUTO_TEST_CASE (hint_closed_caption_too_long)
{
	check (
		TextType::CLOSED_CAPTION,
		"hint_closed_caption_too_long",
		dcp::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)
	      );
}


BOOST_AUTO_TEST_CASE (hint_many_closed_caption_lines)
{
	check (
		TextType::CLOSED_CAPTION,
		"hint_many_closed_caption_lines",
		dcp::compose("Some of your closed captions span more than %1 lines, so they will be truncated.", MAX_CLOSED_CAPTION_LINES)
	      );
}


BOOST_AUTO_TEST_CASE (hint_subtitle_too_early)
{
	check (
		TextType::OPEN_SUBTITLE,
		"hint_subtitle_too_early",
		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.")
		);
}


BOOST_AUTO_TEST_CASE (hint_short_subtitles)
{
	check (
		TextType::OPEN_SUBTITLE,
		"hint_short_subtitles",
		string("At least one of your subtitles lasts less than 15 frames.  It is advisable to make each subtitle at least 15 frames long.")
		);
}


BOOST_AUTO_TEST_CASE (hint_subtitles_too_close)
{
	check (
		TextType::OPEN_SUBTITLE,
		"hint_subtitles_too_close",
		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.")
	      );
}


BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
{
	check (
		TextType::OPEN_SUBTITLE,
		"hint_many_subtitle_lines",
		string("At least one of your subtitles has more than 3 lines.  It is advisable to use no more than 3 lines.")
	      );
}


BOOST_AUTO_TEST_CASE (hint_subtitle_too_long)
{
	check (
		TextType::OPEN_SUBTITLE,
		"hint_subtitle_too_long",
		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.")
	      );
}


BOOST_AUTO_TEST_CASE (hint_subtitle_much_too_long)
{
	check (
		TextType::OPEN_SUBTITLE,
		"hint_subtitle_much_too_long",
		string("At least one of your subtitle lines has more than 79 characters.  You should make each line 79 characters at most in length.")
	      );
}


BOOST_AUTO_TEST_CASE (hint_subtitle_mxf_too_big)
{
	string const name = "hint_subtitle_mxf_too_big";

	auto film = new_test_film2 (name);
	auto content = content_factory("test/data/" + name + ".srt").front();
	content->text.front()->set_type (TextType::OPEN_SUBTITLE);
	content->text.front()->set_language (dcp::LanguageTag("en-US"));
	for (int i = 1; i < 512; ++i) {
		auto font = make_shared<dcpomatic::Font>(dcp::compose("font_%1", i));
		font->set_file ("test/data/LiberationSans-Regular.ttf");
		content->text.front()->add_font(font);
	}
	film->examine_and_add_content (content);
	BOOST_REQUIRE (!wait_for_jobs());
	auto hints = get_hints (film);

	BOOST_REQUIRE_EQUAL (hints.size(), 1U);
	BOOST_CHECK_EQUAL (
		hints[0],
		"At least one of your subtitle files is larger than " MAX_TEXT_MXF_SIZE_TEXT " in total.  "
		"You should divide the DCP into shorter reels."
		);
}


BOOST_AUTO_TEST_CASE (hint_closed_caption_xml_too_big)
{
	string const name = "hint_closed_caption_xml_too_big";

	auto film = new_test_film2 (name);

	auto ccap = fopen_boost (dcp::compose("build/test/%1.srt", name), "w");
	BOOST_REQUIRE (ccap);
	for (int i = 0; i < 2048; ++i) {
		fprintf(ccap, "%d\n", i + 1);
		int second = i * 2;
		int minute = second % 60;
		fprintf(ccap, "00:%02d:%02d,000 --> 00:%02d:%02d,000\n", minute, second, minute, second + 1);
		fprintf(ccap, "Here are some closed captions.\n\n");
	}
	fclose (ccap);

	auto content = content_factory("build/test/" + name + ".srt").front();
	content->text.front()->set_type (TextType::CLOSED_CAPTION);
	content->text.front()->set_language (dcp::LanguageTag("en-US"));
	film->examine_and_add_content (content);
	BOOST_REQUIRE (!wait_for_jobs());
	auto hints = get_hints (film);

	BOOST_REQUIRE_EQUAL (hints.size(), 1U);
	BOOST_CHECK_EQUAL (
		hints[0],
		"At least one of your closed caption files' XML part is larger than " MAX_CLOSED_CAPTION_XML_SIZE_TEXT ".  "
		"You should divide the DCP into shorter reels."
		);
}


BOOST_AUTO_TEST_CASE (hints_destroyed_while_running)
{
	auto film = new_test_film2 ("hints_destroyed_while_running");
	auto content = content_factory(TestPaths::private_data() / "boon_telly.mkv").front();
	film->examine_and_add_content (content);
	BOOST_REQUIRE (!wait_for_jobs());

	auto hints = make_shared<Hints>(film);
	hints->start ();
	dcpomatic_sleep_seconds (1);
	hints.reset ();
	dcpomatic_sleep_seconds (1);
}


BOOST_AUTO_TEST_CASE (hints_audio_with_no_language)
{
	auto content = content_factory("test/data/sine_440.wav").front();
	auto film = new_test_film2 ("hints_audio_with_no_language", { content });
	content->audio->set_gain (-6);

	auto hints = get_hints (film);
	BOOST_REQUIRE_EQUAL (hints.size(), 1U);
	BOOST_CHECK_EQUAL (
		hints[0],
		"Some of your content has audio but you have not set the audio language.  It is advisable to set the audio language "
		"in the \"DCP\" tab unless your audio has no spoken parts."
		);

}