Supporters update.
[dcpomatic.git] / test / subtitle_language_test.cc
1 /*
2     Copyright (C) 2020-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 /** @file  test/subtitle_language_test.cc
23  *  @brief Test that subtitle language information is correctly written to DCPs.
24  */
25
26
27 #include "lib/content.h"
28 #include "lib/content_factory.h"
29 #include "lib/film.h"
30 #include "lib/text_content.h"
31 #include "test.h"
32 #include <dcp/language_tag.h>
33 #include <boost/test/unit_test.hpp>
34 #include <vector>
35
36
37 using std::string;
38 using std::vector;
39
40
41 BOOST_AUTO_TEST_CASE (subtitle_language_interop_test)
42 {
43         string const name = "subtitle_language_interop_test";
44         auto fr = content_factory("test/data/frames.srt");
45         auto film = new_test_film2 (name, fr);
46
47         fr[0]->only_text()->set_language(dcp::LanguageTag("fr"));
48         film->set_interop (true);
49         film->set_audio_channels(6);
50
51         make_and_verify_dcp (
52                 film,
53                 {
54                         dcp::VerificationNote::Code::INVALID_STANDARD,
55                         dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
56                         dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION
57                 },
58                 false,
59                 /* clairmeta raises errors about subtitle spacing/duration */
60                 false
61                 );
62
63         check_dcp(String::compose("test/data/%1", name), String::compose("build/test/%1/%2", name, film->dcp_name()));
64 }
65
66
67 BOOST_AUTO_TEST_CASE (subtitle_language_smpte_test)
68 {
69         string const name = "subtitle_language_smpte_test";
70         auto fr = content_factory("test/data/frames.srt");
71         auto film = new_test_film2 (name, fr);
72
73         fr[0]->only_text()->set_language(dcp::LanguageTag("fr"));
74         film->set_interop (false);
75
76         make_and_verify_dcp (
77                 film,
78                 {
79                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
80                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
81                         dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION,
82                         dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING,
83                         dcp::VerificationNote::Code::MISSING_CPL_METADATA
84                 });
85
86         /* This test is concerned with the subtitles, so we'll ignore any
87          * differences in sound between the DCP and the reference to avoid test
88          * failures for unrelated reasons.
89          */
90         check_dcp(String::compose("test/data/%1", name), String::compose("build/test/%1/%2", name, film->dcp_name()), true);
91 }
92
93
94 BOOST_AUTO_TEST_CASE(subtitle_language_in_cpl_test)
95 {
96         auto subs = content_factory("test/data/frames.srt")[0];
97         auto video1 = content_factory("test/data/flat_red.png")[0];
98         auto video2 = content_factory("test/data/flat_red.png")[0];
99         auto film = new_test_film2(boost::unit_test::framework::current_test_unit().full_name(), { subs, video1, video2 });
100         video2->set_position(film, dcpomatic::DCPTime::from_seconds(5));
101         film->set_reel_type(ReelType::BY_VIDEO_CONTENT);
102         subs->only_text()->set_language(dcp::LanguageTag("fr"));
103
104         make_and_verify_dcp(
105                 film,
106                 {
107                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
108                         dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION,
109                         dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING
110                 });
111
112         cxml::Document cpl("CompositionPlaylist");
113         cpl.read_file(find_file(film->dir(film->dcp_name()), "cpl_"));
114
115         for (auto reel: cpl.node_child("ReelList")->node_children("Reel")) {
116                 auto subtitle = reel->node_child("AssetList")->node_child("MainSubtitle");
117                 BOOST_REQUIRE(subtitle);
118                 BOOST_CHECK(subtitle->optional_node_child("Language"));
119         }
120 }
121