Update for change to default Rec. 601/709 gamma.
[dcpomatic.git] / test / srt_subtitle_test.cc
1 /*
2     Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  test/subtitle_write_test.cc
21  *  @brief Test writing DCPs with XML subtitles.
22  */
23
24 #include "lib/film.h"
25 #include "lib/subrip_content.h"
26 #include "lib/dcp_content_type.h"
27 #include "lib/font.h"
28 #include "test.h"
29 #include <boost/test/unit_test.hpp>
30 #include <boost/algorithm/string.hpp>
31 #include <list>
32
33 using std::string;
34 using std::list;
35 using boost::shared_ptr;
36
37 /** Make a very short DCP with a single subtitle from .srt with no specified fonts */
38 BOOST_AUTO_TEST_CASE (srt_subtitle_test)
39 {
40         shared_ptr<Film> film = new_test_film ("srt_subtitle_test");
41         film->set_container (Ratio::from_id ("185"));
42         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
43         film->set_name ("frobozz");
44         shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip2.srt"));
45         film->examine_and_add_content (content);
46         wait_for_jobs ();
47
48         content->set_use_subtitles (true);
49         content->set_burn_subtitles (false);
50         film->make_dcp ();
51         wait_for_jobs ();
52
53         /* Should be blank video with a subtitle MXF */
54         check_dcp ("test/data/srt_subtitle_test", film->dir (film->dcp_name ()));
55 }
56
57 /** Same again but with a `font' specified */
58 BOOST_AUTO_TEST_CASE (srt_subtitle_test2)
59 {
60         shared_ptr<Film> film = new_test_film ("srt_subtitle_test2");
61         film->set_container (Ratio::from_id ("185"));
62         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
63         film->set_name ("frobozz");
64         shared_ptr<SubRipContent> content (new SubRipContent (film, "test/data/subrip2.srt"));
65         film->examine_and_add_content (content);
66         wait_for_jobs ();
67
68         content->set_use_subtitles (true);
69         content->set_burn_subtitles (false);
70         /* Use test/data/subrip2.srt as if it were a font file  */
71         content->fonts().front()->set_file ("test/data/subrip2.srt");
72
73         film->make_dcp ();
74         wait_for_jobs ();
75
76         /* Should be blank video with a subtitle MXF */
77         check_dcp ("test/data/srt_subtitle_test2", film->dir (film->dcp_name ()));
78 }
79
80 /** Make another DCP with a longer .srt file */
81 BOOST_AUTO_TEST_CASE (srt_subtitle_test3)
82 {
83         shared_ptr<Film> film = new_test_film ("srt_subtitle_test3");
84
85         film->set_container (Ratio::from_id ("185"));
86         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
87         film->set_name ("frobozz");
88         film->set_interop (true);
89         shared_ptr<SubRipContent> content (new SubRipContent (film, private_data / "Ankoemmling.srt"));
90         film->examine_and_add_content (content);
91         wait_for_jobs ();
92
93         content->set_use_subtitles (true);
94         content->set_burn_subtitles (false);
95
96         film->make_dcp ();
97         wait_for_jobs ();
98
99         /* Find the subtitle file and check it */
100         for (
101                 boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->directory() / film->dcp_name (false));
102                 i != boost::filesystem::directory_iterator ();
103                 ++i) {
104
105                 if (boost::filesystem::is_directory (i->path ())) {
106                         for (
107                                 boost::filesystem::directory_iterator j = boost::filesystem::directory_iterator (i->path ());
108                                 j != boost::filesystem::directory_iterator ();
109                                 ++j) {
110
111                                 if (boost::algorithm::starts_with (j->path().leaf().string(), "sub_")) {
112                                         list<string> ignore;
113                                         ignore.push_back ("SubtitleID");
114                                         check_xml (*j, private_data / "Ankoemmling.xml", ignore);
115                                 }
116                         }
117                 }
118         }
119 }