2 Copyright (C) 2017-2021 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 /** @file test/empty_test.cc
23 * @brief Test the creation of Empty objects.
28 #include "lib/audio_content.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/decoder.h"
31 #include "lib/empty_audio.h"
32 #include "lib/empty_video.h"
34 #include "lib/image_content.h"
35 #include "lib/player.h"
36 #include "lib/ratio.h"
37 #include "lib/video_content.h"
39 #include <boost/test/unit_test.hpp>
43 using std::make_shared;
44 using std::shared_ptr;
45 #if BOOST_VERSION >= 106100
46 using namespace boost::placeholders;
48 using namespace dcpomatic;
51 BOOST_AUTO_TEST_CASE (empty_video_test1)
53 auto film = new_test_film2 ("empty_video_test1");
54 film->set_sequence (false);
55 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
56 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
58 film->examine_and_add_content (contentA);
59 film->examine_and_add_content (contentB);
60 BOOST_REQUIRE (!wait_for_jobs());
62 int const vfr = film->video_frame_rate ();
67 contentA->video->set_length (3);
68 contentA->set_position (film, DCPTime::from_frames(2, vfr));
69 contentB->video->set_length (1);
70 contentB->set_position (film, DCPTime::from_frames(7, vfr));
72 EmptyVideo black (film, film->playlist(), film->playlist()->length(film));
73 BOOST_REQUIRE_EQUAL (black._periods.size(), 2U);
74 auto i = black._periods.begin();
75 BOOST_CHECK (i->from == DCPTime::from_frames(0, vfr));
76 BOOST_CHECK (i->to == DCPTime::from_frames(2, vfr));
78 BOOST_CHECK (i->from == DCPTime::from_frames(5, vfr));
79 BOOST_CHECK (i->to == DCPTime::from_frames(7, vfr));
83 BOOST_AUTO_TEST_CASE (empty_audio_test1)
85 auto film = new_test_film2 ("empty_audio_test1");
86 film->set_sequence (false);
87 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
88 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
90 film->examine_and_add_content (contentA);
91 film->examine_and_add_content (contentB);
92 BOOST_REQUIRE (!wait_for_jobs());
94 /* Make this content look like it has audio so we can test the EmptyAudio class */
95 contentA->audio = make_shared<AudioContent>(contentA.get());
96 contentB->audio = make_shared<AudioContent>(contentB.get());
98 int const vfr = film->video_frame_rate ();
103 contentA->video->set_length (3);
104 contentA->set_position (film, DCPTime::from_frames(2, vfr));
105 contentB->video->set_length (1);
106 contentB->set_position (film, DCPTime::from_frames(7, vfr));
108 EmptyAudio silent (film, film->playlist(), film->playlist()->length(film));
109 BOOST_REQUIRE_EQUAL (silent._periods.size(), 2U);
110 auto i = silent._periods.begin();
111 BOOST_CHECK (i->from == DCPTime::from_frames(0, vfr));
112 BOOST_CHECK (i->to == DCPTime::from_frames(2, vfr));
114 BOOST_CHECK (i->from == DCPTime::from_frames(5, vfr));
115 BOOST_CHECK (i->to == DCPTime::from_frames(7, vfr));
119 /** Some tests where the first empty period is not at time 0 */
120 BOOST_AUTO_TEST_CASE (empty_video_test2)
122 auto film = new_test_film2 ("empty_video_test2");
123 film->set_sequence (false);
124 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
125 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
127 film->examine_and_add_content (contentA);
128 film->examine_and_add_content (contentB);
129 BOOST_REQUIRE (!wait_for_jobs());
131 int const vfr = film->video_frame_rate ();
136 contentA->video->set_length (3);
137 contentA->set_position (film, DCPTime(0));
138 contentB->video->set_length (1);
139 contentB->set_position (film, DCPTime::from_frames(7, vfr));
141 EmptyVideo black (film, film->playlist(), film->playlist()->length(film));
142 BOOST_REQUIRE_EQUAL (black._periods.size(), 1U);
143 BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(3, vfr));
144 BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
146 /* position should initially be the start of the first empty period */
147 BOOST_CHECK (black.position() == DCPTime::from_frames(3, vfr));
149 /* check that done() works */
150 BOOST_CHECK (!black.done ());
151 black.set_position (DCPTime::from_frames (4, vfr));
152 BOOST_CHECK (!black.done ());
153 black.set_position (DCPTime::from_frames (7, vfr));
154 BOOST_CHECK (black.done ());
158 /** Some tests where the first empty period is not at time 0 */
159 BOOST_AUTO_TEST_CASE (empty_audio_test2)
161 auto film = new_test_film2 ("empty_audio_test2");
162 film->set_sequence (false);
163 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
164 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
166 film->examine_and_add_content (contentA);
167 film->examine_and_add_content (contentB);
168 BOOST_REQUIRE (!wait_for_jobs());
170 /* Make this content look like it has audio so we can test the EmptyAudio class */
171 contentA->audio = make_shared<AudioContent>(contentA.get());
172 contentB->audio = make_shared<AudioContent>(contentB.get());
174 int const vfr = film->video_frame_rate ();
179 contentA->video->set_length (3);
180 contentA->set_position (film, DCPTime(0));
181 contentB->video->set_length (1);
182 contentB->set_position (film, DCPTime::from_frames(7, vfr));
184 EmptyAudio silent (film, film->playlist(), film->playlist()->length(film));
185 BOOST_REQUIRE_EQUAL (silent._periods.size(), 1U);
186 BOOST_CHECK (silent._periods.front().from == DCPTime::from_frames(3, vfr));
187 BOOST_CHECK (silent._periods.front().to == DCPTime::from_frames(7, vfr));
189 /* position should initially be the start of the first empty period */
190 BOOST_CHECK (silent.position() == DCPTime::from_frames(3, vfr));
192 /* check that done() works */
193 BOOST_CHECK (!silent.done ());
194 silent.set_position (DCPTime::from_frames (4, vfr));
195 BOOST_CHECK (!silent.done ());
196 silent.set_position (DCPTime::from_frames (7, vfr));
197 BOOST_CHECK (silent.done ());
201 /** Test for when the film's playlist is not the same as the one passed into Empty */
202 BOOST_AUTO_TEST_CASE (empty_video_test3)
204 auto film = new_test_film2 ("empty_video_test3");
205 film->set_sequence (false);
206 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
207 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
209 film->examine_and_add_content (contentA);
210 film->examine_and_add_content (contentB);
211 BOOST_REQUIRE (!wait_for_jobs());
213 int const vfr = film->video_frame_rate ();
218 contentA->video->set_length (3);
219 contentA->set_position (film, DCPTime(0));
220 contentB->video->set_length (1);
221 contentB->set_position (film, DCPTime::from_frames(7, vfr));
223 auto playlist = make_shared<Playlist>();
224 playlist->add (film, contentB);
225 EmptyVideo black (film, playlist, playlist->length(film));
226 BOOST_REQUIRE_EQUAL (black._periods.size(), 1U);
227 BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(0, vfr));
228 BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
230 /* position should initially be the start of the first empty period */
231 BOOST_CHECK (black.position() == DCPTime::from_frames(0, vfr));
235 /** Test for when the film's playlist is not the same as the one passed into Empty */
236 BOOST_AUTO_TEST_CASE (empty_audio_test3)
238 auto film = new_test_film2 ("empty_audio_test3");
239 film->set_sequence (false);
240 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
241 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
243 film->examine_and_add_content (contentA);
244 film->examine_and_add_content (contentB);
245 BOOST_REQUIRE (!wait_for_jobs());
247 /* Make this content look like it has audio so we can test the EmptyAudio class */
248 contentA->audio = make_shared<AudioContent>(contentA.get());
249 contentB->audio = make_shared<AudioContent>(contentB.get());
251 int const vfr = film->video_frame_rate ();
256 contentA->video->set_length (3);
257 contentA->set_position (film, DCPTime(0));
258 contentB->video->set_length (1);
259 contentB->set_position (film, DCPTime::from_frames(7, vfr));
261 auto playlist = make_shared<Playlist>();
262 playlist->add (film, contentB);
263 EmptyAudio silent (film, playlist, playlist->length(film));
264 BOOST_REQUIRE_EQUAL (silent._periods.size(), 1U);
265 BOOST_CHECK (silent._periods.front().from == DCPTime::from_frames(0, vfr));
266 BOOST_CHECK (silent._periods.front().to == DCPTime::from_frames(7, vfr));
268 /* position should initially be the start of the first empty period */
269 BOOST_CHECK (silent.position() == DCPTime::from_frames(0, vfr));
273 BOOST_AUTO_TEST_CASE (empty_video_test_with_overlapping_content)
275 auto film = new_test_film2 ("empty_video_test_with_overlapping_content");
276 film->set_sequence (false);
277 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
278 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
280 film->examine_and_add_content (contentA);
281 film->examine_and_add_content (contentB);
282 BOOST_REQUIRE (!wait_for_jobs());
284 int const vfr = film->video_frame_rate ();
286 contentA->video->set_length (vfr * 3);
287 contentA->set_position (film, DCPTime());
288 contentB->video->set_length (vfr * 1);
289 contentB->set_position (film, DCPTime::from_seconds(1));
291 EmptyVideo black(film, film->playlist(), film->playlist()->length(film));
293 BOOST_REQUIRE (black._periods.empty());
297 BOOST_AUTO_TEST_CASE (empty_audio_test_with_overlapping_content)
299 auto film = new_test_film2 ("empty_audio_test_with_overlapping_content");
300 film->set_sequence (false);
301 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
302 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
304 film->examine_and_add_content (contentA);
305 film->examine_and_add_content (contentB);
306 BOOST_REQUIRE (!wait_for_jobs());
308 /* Make this content look like it has audio so we can test the EmptyAudio class */
309 contentA->audio = make_shared<AudioContent>(contentA.get());
310 contentB->audio = make_shared<AudioContent>(contentB.get());
312 int const vfr = film->video_frame_rate ();
314 contentA->video->set_length (vfr * 3);
315 contentA->set_position (film, DCPTime());
316 contentB->video->set_length (vfr * 1);
317 contentB->set_position (film, DCPTime::from_seconds(1));
319 EmptyAudio silent(film, film->playlist(), film->playlist()->length(film));
321 BOOST_REQUIRE (silent._periods.empty());