caff70778700391631a466d42e259ffd215e2fa0
[dcpomatic.git] / test / subtitle_reel_number_test.cc
1 /*
2     Copyright (C) 2017-2021 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/string_text_file_content.h"
23 #include "lib/film.h"
24 #include "lib/ratio.h"
25 #include "lib/text_content.h"
26 #include "lib/dcp_content_type.h"
27 #include "test.h"
28 #include <dcp/cpl.h>
29 #include <dcp/dcp.h>
30 #include <dcp/reel.h>
31 #include <dcp/interop_subtitle_asset.h>
32 #include <dcp/reel_subtitle_asset.h>
33 #include <dcp/raw_convert.h>
34 #include <boost/test/unit_test.hpp>
35
36
37 using std::dynamic_pointer_cast;
38 using std::make_shared;
39 using std::string;
40
41
42 /* Check that ReelNumber is setup correctly when making multi-reel subtitled DCPs */
43 BOOST_AUTO_TEST_CASE (subtitle_reel_number_test)
44 {
45         Cleanup cl;
46
47         auto content = make_shared<StringTextFileContent>("test/data/subrip5.srt");
48         auto film = new_test_film("subtitle_reel_number_test", { content }, &cl);
49         content->only_text()->set_use (true);
50         content->only_text()->set_burn (false);
51         content->only_text()->set_language(dcp::LanguageTag("de"));
52         film->set_reel_type (ReelType::BY_LENGTH);
53         film->set_interop (true);
54         film->set_reel_length (1024 * 1024 * 512);
55         make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_STANDARD});
56
57         dcp::DCP dcp ("build/test/subtitle_reel_number_test/" + film->dcp_name());
58         dcp.read ();
59         BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
60         auto cpl = dcp.cpls()[0];
61         BOOST_REQUIRE_EQUAL (cpl->reels().size(), 6U);
62
63         int n = 1;
64         for (auto i: cpl->reels()) {
65                 if (i->main_subtitle()) {
66                         auto ass = dynamic_pointer_cast<dcp::InteropSubtitleAsset>(i->main_subtitle()->asset());
67                         BOOST_REQUIRE (ass);
68                         BOOST_CHECK_EQUAL (ass->reel_number(), dcp::raw_convert<string>(n));
69                         ++n;
70                 }
71         }
72
73         cl.run();
74 }