Add some hints for violations of SMPTE Bv2.1 with subtitles and closed
[dcpomatic.git] / test / hints_test.cc
1 /*
2     Copyright (C) 2020 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/content.h"
23 #include "lib/content_factory.h"
24 #include "lib/film.h"
25 #include "lib/hints.h"
26 #include "lib/text_content.h"
27 #include "lib/util.h"
28 #include "test.h"
29 #include <boost/shared_ptr.hpp>
30 #include <boost/test/unit_test.hpp>
31
32
33 using std::string;
34 using std::vector;
35 using boost::shared_ptr;
36
37
38 vector<string> current_hints;
39
40
41 static
42 void
43 collect_hint (string hint)
44 {
45         current_hints.push_back (hint);
46 }
47
48
49 static
50 vector<string>
51 get_hints (shared_ptr<Film> film)
52 {
53         current_hints.clear ();
54         Hints hints (film);
55         hints.Hint.connect (collect_hint);
56         hints.start ();
57         hints.join ();
58         while (signal_manager->ui_idle()) {}
59         return current_hints;
60 }
61
62
63 static
64 void
65 check (TextType type, string name, string expected_hint)
66 {
67         shared_ptr<Film> film = new_test_film2 (name);
68         shared_ptr<Content> content = content_factory("test/data/" + name + ".srt").front();
69         content->text.front()->set_type (type);
70         film->examine_and_add_content (content);
71         BOOST_REQUIRE (!wait_for_jobs());
72         vector<string> hints = get_hints (film);
73
74         BOOST_REQUIRE_EQUAL (hints.size(), 1);
75         BOOST_CHECK_EQUAL (hints[0], expected_hint);
76 }
77
78
79 BOOST_AUTO_TEST_CASE (hint_closed_caption_too_long)
80 {
81         check (
82                 TEXT_CLOSED_CAPTION,
83                 "hint_closed_caption_too_long",
84                 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)
85               );
86 }
87
88
89 BOOST_AUTO_TEST_CASE (hint_many_closed_caption_lines)
90 {
91         check (
92                 TEXT_CLOSED_CAPTION,
93                 "hint_many_closed_caption_lines",
94                 String::compose("Some of your closed captions span more than %1 lines, so they will be truncated.", MAX_CLOSED_CAPTION_LINES)
95               );
96 }
97
98
99 BOOST_AUTO_TEST_CASE (hint_subtitle_too_early)
100 {
101         check (
102                 TEXT_OPEN_SUBTITLE,
103                 "hint_subtitle_too_early",
104                 "It is advisable to put your first subtitle at least 4 seconds after the start of the DCP to make sure it is seen."
105                 );
106 }
107
108
109 BOOST_AUTO_TEST_CASE (hint_short_subtitles)
110 {
111         check (
112                 TEXT_OPEN_SUBTITLE,
113                 "hint_short_subtitles",
114                 "At least one of your subtitles lasts less than 15 frames.  It is advisable to make each subtitle at least 15 frames long."
115                 );
116 }
117
118
119 BOOST_AUTO_TEST_CASE (hint_subtitles_too_close)
120 {
121         check (
122                 TEXT_OPEN_SUBTITLE,
123                 "hint_subtitles_too_close",
124                 "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."
125               );
126 }
127
128
129 BOOST_AUTO_TEST_CASE (hint_many_subtitle_lines)
130 {
131         check (
132                 TEXT_OPEN_SUBTITLE,
133                 "hint_many_subtitle_lines",
134                 "At least one of your subtitles has more than 3 lines.  It is advisable to use no more than 3 lines."
135               );
136 }
137
138
139 BOOST_AUTO_TEST_CASE (hint_subtitle_too_long)
140 {
141         check (
142                 TEXT_OPEN_SUBTITLE,
143                 "hint_subtitle_too_long",
144                 "At least one of your subtitle lines has more than 52 characters.  It is advisable to make each line 52 characters at most in length."
145               );
146 }
147