Run all tests with lots of encoding threads.
[dcpomatic.git] / test / subtitle_reel_test.cc
1 /*
2     Copyright (C) 2019 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/image_content.h"
23 #include "lib/dcp_subtitle_content.h"
24 #include "lib/video_content.h"
25 #include "test.h"
26 #include <dcp/dcp.h>
27 #include <dcp/cpl.h>
28 #include <dcp/reel.h>
29 #include <dcp/interop_subtitle_asset.h>
30 #include <dcp/reel_subtitle_asset.h>
31 #include <boost/test/unit_test.hpp>
32
33 using std::list;
34 using boost::shared_ptr;
35
36 /* Check that timings are done correctly for multi-reel DCPs with PNG subs */
37 BOOST_AUTO_TEST_CASE (subtitle_reel_test)
38 {
39         shared_ptr<Film> film = new_test_film2 ("subtitle_reel_test");
40         film->set_interop (true);
41         shared_ptr<ImageContent> red_a (new ImageContent("test/data/flat_red.png"));
42         shared_ptr<ImageContent> red_b (new ImageContent("test/data/flat_red.png"));
43         shared_ptr<DCPSubtitleContent> sub_a (new DCPSubtitleContent("test/data/png_subs/subs.xml"));
44         shared_ptr<DCPSubtitleContent> sub_b (new DCPSubtitleContent("test/data/png_subs/subs.xml"));
45
46         film->examine_and_add_content (red_a);
47         film->examine_and_add_content (red_b);
48         film->examine_and_add_content (sub_a);
49         film->examine_and_add_content (sub_b);
50
51         BOOST_REQUIRE (!wait_for_jobs());
52
53         red_a->set_position (film, dcpomatic::DCPTime());
54         red_a->video->set_length (240);
55         sub_a->set_position (film, dcpomatic::DCPTime());
56         red_b->set_position (film, dcpomatic::DCPTime::from_seconds(10));
57         red_b->video->set_length (240);
58         sub_b->set_position (film, dcpomatic::DCPTime::from_seconds(10));
59
60         film->set_reel_type (REELTYPE_BY_VIDEO_CONTENT);
61
62         film->make_dcp ();
63         BOOST_REQUIRE (!wait_for_jobs());
64
65         dcp::DCP dcp ("build/test/subtitle_reel_test/" + film->dcp_name());
66         dcp.read ();
67         BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1);
68         shared_ptr<dcp::CPL> cpl = dcp.cpls().front();
69
70         list<shared_ptr<dcp::Reel> > reels = cpl->reels ();
71         BOOST_REQUIRE_EQUAL (reels.size(), 2);
72         list<shared_ptr<dcp::Reel> >::const_iterator i = reels.begin ();
73         BOOST_REQUIRE ((*i)->main_subtitle());
74         BOOST_REQUIRE ((*i)->main_subtitle()->asset());
75         shared_ptr<dcp::InteropSubtitleAsset> A = boost::dynamic_pointer_cast<dcp::InteropSubtitleAsset>((*i)->main_subtitle()->asset());
76         BOOST_REQUIRE (A);
77         ++i;
78         BOOST_REQUIRE ((*i)->main_subtitle());
79         BOOST_REQUIRE ((*i)->main_subtitle()->asset());
80         shared_ptr<dcp::InteropSubtitleAsset> B = boost::dynamic_pointer_cast<dcp::InteropSubtitleAsset>((*i)->main_subtitle()->asset());
81         BOOST_REQUIRE (B);
82
83         BOOST_REQUIRE_EQUAL (A->subtitles().size(), 1);
84         BOOST_REQUIRE_EQUAL (B->subtitles().size(), 1);
85
86         /* These times should be the same as they are should be offset from the start of the reel */
87         BOOST_CHECK (A->subtitles().front()->in() == B->subtitles().front()->in());
88 }