Improve test checking.
[dcpomatic.git] / test / vf_test.cc
1 /*
2     Copyright (C) 2015-2016 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 #include "lib/film.h"
22 #include "lib/dcp_content.h"
23 #include "lib/ffmpeg_content.h"
24 #include "lib/content_factory.h"
25 #include "lib/dcp_content_type.h"
26 #include "lib/video_content.h"
27 #include "test.h"
28 #include <dcp/cpl.h>
29 #include <dcp/reel.h>
30 #include <dcp/reel_picture_asset.h>
31 #include <dcp/reel_sound_asset.h>
32 #include <boost/test/unit_test.hpp>
33 #include <boost/foreach.hpp>
34
35 using std::list;
36 using std::string;
37 using boost::shared_ptr;
38 using boost::dynamic_pointer_cast;
39
40 /** Test the logic which decides whether a DCP can be referenced or not */
41 BOOST_AUTO_TEST_CASE (vf_test1)
42 {
43         shared_ptr<Film> film = new_test_film ("vf_test1");
44         shared_ptr<DCPContent> dcp (new DCPContent (film, "test/data/reels_test2"));
45         film->examine_and_add_content (dcp);
46         wait_for_jobs ();
47
48         /* Multi-reel DCP can't be referenced if we are using a single reel for the project */
49         film->set_reel_type (REELTYPE_SINGLE);
50         list<string> why_not;
51         BOOST_CHECK (!dcp->can_reference_video(why_not));
52         BOOST_CHECK (!dcp->can_reference_audio(why_not));
53         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
54
55         /* Multi-reel DCP can be referenced if we are using by-video-content */
56         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
57         BOOST_CHECK (dcp->can_reference_video(why_not));
58         BOOST_CHECK (dcp->can_reference_audio(why_not));
59         /* (but reels_test2 has no subtitles to reference) */
60         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
61
62         shared_ptr<FFmpegContent> other (new FFmpegContent (film, "test/data/test.mp4"));
63         film->examine_and_add_content (other);
64         wait_for_jobs ();
65
66         /* Not possible if there is overlap */
67         other->set_position (DCPTime (0));
68         BOOST_CHECK (!dcp->can_reference_video(why_not));
69         BOOST_CHECK (!dcp->can_reference_audio(why_not));
70         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
71
72         /* This should not be considered an overlap */
73         other->set_position (dcp->end ());
74         BOOST_CHECK (dcp->can_reference_video(why_not));
75         BOOST_CHECK (dcp->can_reference_audio(why_not));
76         /* (reels_test2 has no subtitles to reference) */
77         BOOST_CHECK (!dcp->can_reference_subtitle(why_not));
78 }
79
80 /** Make a OV with video and audio and a VF referencing the OV and adding subs */
81 BOOST_AUTO_TEST_CASE (vf_test2)
82 {
83         /* Make the OV */
84         shared_ptr<Film> ov = new_test_film ("vf_test2_ov");
85         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
86         ov->set_name ("vf_test2_ov");
87         shared_ptr<Content> video = content_factory (ov, "test/data/flat_red.png");
88         ov->examine_and_add_content (video);
89         wait_for_jobs ();
90         video->video->set_length (24 * 5);
91         shared_ptr<Content> audio = content_factory (ov, "test/data/white.wav");
92         ov->examine_and_add_content (audio);
93         wait_for_jobs ();
94         ov->make_dcp ();
95         wait_for_jobs ();
96
97         /* Make the VF */
98         shared_ptr<Film> vf = new_test_film ("vf_test2_vf");
99         vf->set_name ("vf_test2_vf");
100         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
101         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
102         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content_factory (vf, ov->dir (ov->dcp_name ())));
103         BOOST_REQUIRE (dcp);
104         vf->examine_and_add_content (dcp);
105         wait_for_jobs ();
106         dcp->set_reference_video (true);
107         dcp->set_reference_audio (true);
108         shared_ptr<Content> sub = content_factory (vf, "test/data/subrip4.srt");
109         vf->examine_and_add_content (sub);
110         vf->make_dcp ();
111         wait_for_jobs ();
112         vf->write_metadata ();
113
114         dcp::DCP ov_c (ov->dir (ov->dcp_name ()));
115         ov_c.read ();
116         BOOST_REQUIRE_EQUAL (ov_c.cpls().size(), 1);
117         BOOST_REQUIRE_EQUAL (ov_c.cpls().front()->reels().size(), 1);
118         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_picture());
119         string const pic_id = ov_c.cpls().front()->reels().front()->main_picture()->id();
120         BOOST_REQUIRE (ov_c.cpls().front()->reels().front()->main_sound());
121         string const sound_id = ov_c.cpls().front()->reels().front()->main_sound()->id();
122         BOOST_REQUIRE (!ov_c.cpls().front()->reels().front()->main_subtitle());
123
124         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
125         vf_c.read ();
126         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
127         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
128         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
129         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->id(), pic_id);
130         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
131         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->id(), sound_id);
132         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_subtitle());
133 }
134
135 /** Test creation of a VF using a trimmed OV; the output should have entry point /
136  *  duration altered to effect the trimming.
137  */
138 BOOST_AUTO_TEST_CASE (vf_test3)
139 {
140         /* Make the OV */
141         shared_ptr<Film> ov = new_test_film ("vf_test3_ov");
142         ov->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
143         ov->set_name ("vf_test3_ov");
144         shared_ptr<Content> video = content_factory (ov, "test/data/flat_red.png");
145         ov->examine_and_add_content (video);
146         wait_for_jobs ();
147         video->video->set_length (24 * 5);
148         shared_ptr<Content> audio = content_factory (ov, "test/data/white.wav");
149         ov->examine_and_add_content (audio);
150         wait_for_jobs ();
151         ov->make_dcp ();
152         wait_for_jobs ();
153
154         /* Make the VF */
155         shared_ptr<Film> vf = new_test_film ("vf_test3_vf");
156         vf->set_name ("vf_test3_vf");
157         vf->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
158         vf->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
159         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content_factory (vf, ov->dir (ov->dcp_name ())));
160         BOOST_REQUIRE (dcp);
161         dcp->set_trim_start (ContentTime::from_seconds (1));
162         dcp->set_trim_end (ContentTime::from_seconds (1));
163         vf->examine_and_add_content (dcp);
164         wait_for_jobs ();
165         dcp->set_reference_video (true);
166         dcp->set_reference_audio (true);
167         vf->make_dcp ();
168         wait_for_jobs ();
169         vf->write_metadata ();
170
171         dcp::DCP vf_c (vf->dir (vf->dcp_name ()));
172         vf_c.read ();
173         BOOST_REQUIRE_EQUAL (vf_c.cpls().size(), 1);
174         BOOST_REQUIRE_EQUAL (vf_c.cpls().front()->reels().size(), 1);
175         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_picture());
176         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->entry_point(), 24);
177         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_picture()->duration(), 72);
178         BOOST_REQUIRE (vf_c.cpls().front()->reels().front()->main_sound());
179         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->entry_point(), 24);
180         BOOST_CHECK_EQUAL (vf_c.cpls().front()->reels().front()->main_sound()->duration(), 72);
181 }