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/dcp_content_type.h"
29 #include "lib/decoder.h"
30 #include "lib/empty.h"
32 #include "lib/image_content.h"
33 #include "lib/player.h"
34 #include "lib/ratio.h"
35 #include "lib/video_content.h"
37 #include <boost/test/unit_test.hpp>
41 using std::make_shared;
42 using std::shared_ptr;
43 #if BOOST_VERSION >= 106100
44 using namespace boost::placeholders;
46 using namespace dcpomatic;
50 has_video (shared_ptr<const Content> content)
52 return static_cast<bool>(content->video);
56 BOOST_AUTO_TEST_CASE (empty_test1)
58 auto film = new_test_film2 ("empty_test1");
59 film->set_sequence (false);
60 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
61 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
63 film->examine_and_add_content (contentA);
64 film->examine_and_add_content (contentB);
65 BOOST_REQUIRE (!wait_for_jobs());
67 int const vfr = film->video_frame_rate ();
72 contentA->video->set_length (3);
73 contentA->set_position (film, DCPTime::from_frames(2, vfr));
74 contentB->video->set_length (1);
75 contentB->set_position (film, DCPTime::from_frames(7, vfr));
77 Empty black (film, film->playlist(), bind(&has_video, _1), film->playlist()->length(film));
78 BOOST_REQUIRE_EQUAL (black._periods.size(), 2U);
79 auto i = black._periods.begin();
80 BOOST_CHECK (i->from == DCPTime::from_frames(0, vfr));
81 BOOST_CHECK (i->to == DCPTime::from_frames(2, vfr));
83 BOOST_CHECK (i->from == DCPTime::from_frames(5, vfr));
84 BOOST_CHECK (i->to == DCPTime::from_frames(7, vfr));
88 /** Some tests where the first empty period is not at time 0 */
89 BOOST_AUTO_TEST_CASE (empty_test2)
91 auto film = new_test_film2 ("empty_test2");
92 film->set_sequence (false);
93 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
94 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
96 film->examine_and_add_content (contentA);
97 film->examine_and_add_content (contentB);
98 BOOST_REQUIRE (!wait_for_jobs());
100 int const vfr = film->video_frame_rate ();
105 contentA->video->set_length (3);
106 contentA->set_position (film, DCPTime(0));
107 contentB->video->set_length (1);
108 contentB->set_position (film, DCPTime::from_frames(7, vfr));
110 Empty black (film, film->playlist(), bind(&has_video, _1), film->playlist()->length(film));
111 BOOST_REQUIRE_EQUAL (black._periods.size(), 1U);
112 BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(3, vfr));
113 BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
115 /* position should initially be the start of the first empty period */
116 BOOST_CHECK (black.position() == DCPTime::from_frames(3, vfr));
118 /* check that done() works */
119 BOOST_CHECK (!black.done ());
120 black.set_position (DCPTime::from_frames (4, vfr));
121 BOOST_CHECK (!black.done ());
122 black.set_position (DCPTime::from_frames (7, vfr));
123 BOOST_CHECK (black.done ());
127 /** Test for when the film's playlist is not the same as the one passed into Empty */
128 BOOST_AUTO_TEST_CASE (empty_test3)
130 auto film = new_test_film2 ("empty_test3");
131 film->set_sequence (false);
132 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
133 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
135 film->examine_and_add_content (contentA);
136 film->examine_and_add_content (contentB);
137 BOOST_REQUIRE (!wait_for_jobs());
139 int const vfr = film->video_frame_rate ();
144 contentA->video->set_length (3);
145 contentA->set_position (film, DCPTime(0));
146 contentB->video->set_length (1);
147 contentB->set_position (film, DCPTime::from_frames(7, vfr));
149 auto playlist = make_shared<Playlist>();
150 playlist->add (film, contentB);
151 Empty black (film, playlist, bind(&has_video, _1), playlist->length(film));
152 BOOST_REQUIRE_EQUAL (black._periods.size(), 1U);
153 BOOST_CHECK (black._periods.front().from == DCPTime::from_frames(0, vfr));
154 BOOST_CHECK (black._periods.front().to == DCPTime::from_frames(7, vfr));
156 /* position should initially be the start of the first empty period */
157 BOOST_CHECK (black.position() == DCPTime::from_frames(0, vfr));
161 BOOST_AUTO_TEST_CASE (empty_test_with_overlapping_content)
163 auto film = new_test_film2 ("empty_test_with_overlapping_content");
164 film->set_sequence (false);
165 auto contentA = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
166 auto contentB = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
168 film->examine_and_add_content (contentA);
169 film->examine_and_add_content (contentB);
170 BOOST_REQUIRE (!wait_for_jobs());
172 int const vfr = film->video_frame_rate ();
174 contentA->video->set_length (vfr * 3);
175 contentA->set_position (film, DCPTime());
176 contentB->video->set_length (vfr * 1);
177 contentB->set_position (film, DCPTime::from_seconds(1));
179 Empty black(film, film->playlist(), bind(&has_video, _1), film->playlist()->length(film));
181 BOOST_REQUIRE (black._periods.empty());