Supporters update.
[dcpomatic.git] / test / closed_caption_test.cc
1 /*
2     Copyright (C) 2018-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/film.h"
23 #include "lib/string_text_file_content.h"
24 #include "lib/text_content.h"
25 #include "test.h"
26 #include <dcp/cpl.h>
27 #include <dcp/dcp.h>
28 #include <dcp/reel.h>
29 #include <dcp/reel_closed_caption_asset.h>
30 #include <boost/test/unit_test.hpp>
31
32
33 using std::list;
34 using std::make_shared;
35
36
37 /** Basic test that Interop closed captions are written */
38 BOOST_AUTO_TEST_CASE (closed_caption_test1)
39 {
40         Cleanup cl;
41
42         auto content = make_shared<StringTextFileContent>("test/data/subrip.srt");
43         auto film = new_test_film2 ("closed_caption_test1", { content }, &cl);
44
45         content->only_text()->set_type (TextType::CLOSED_CAPTION);
46
47         make_and_verify_dcp (
48                 film,
49                 {
50                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
51                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
52                         dcp::VerificationNote::Code::INVALID_CLOSED_CAPTION_LINE_LENGTH,
53                         dcp::VerificationNote::Code::MISSING_CPL_METADATA
54                 });
55
56         /* Just check to see that there's a CCAP in the CPL: this
57            check could be better!
58         */
59
60         dcp::DCP check (film->dir(film->dcp_name()));
61         check.read ();
62
63         BOOST_REQUIRE_EQUAL (check.cpls().size(), 1U);
64         BOOST_REQUIRE_EQUAL (check.cpls().front()->reels().size(), 1U);
65         BOOST_REQUIRE (!check.cpls().front()->reels().front()->closed_captions().empty());
66
67         cl.run ();
68 }
69
70 /** Test multiple closed captions */
71 BOOST_AUTO_TEST_CASE (closed_caption_test2)
72 {
73         Cleanup cl;
74         auto content1 = make_shared<StringTextFileContent>("test/data/subrip.srt");
75         auto content2 = make_shared<StringTextFileContent>("test/data/subrip2.srt");
76         auto content3 = make_shared<StringTextFileContent>("test/data/subrip3.srt");
77         auto film = new_test_film2 ("closed_caption_test2", { content1, content2, content3 }, &cl);
78
79         content1->only_text()->set_type (TextType::CLOSED_CAPTION);
80         content1->only_text()->set_dcp_track (DCPTextTrack("First track", dcp::LanguageTag("fr-FR")));
81         content2->only_text()->set_type (TextType::CLOSED_CAPTION);
82         content2->only_text()->set_dcp_track (DCPTextTrack("Second track", dcp::LanguageTag("de-DE")));
83         content3->only_text()->set_type (TextType::CLOSED_CAPTION);
84         content3->only_text()->set_dcp_track (DCPTextTrack("Third track", dcp::LanguageTag("it-IT")));
85
86         make_and_verify_dcp (
87                 film,
88                 {
89                         dcp::VerificationNote::Code::INVALID_SUBTITLE_DURATION,
90                         dcp::VerificationNote::Code::INVALID_CLOSED_CAPTION_LINE_LENGTH,
91                         dcp::VerificationNote::Code::MISSING_CPL_METADATA,
92                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
93                 },
94                 true,
95                 /* Clairmeta gives an error about having duplicate ClosedCaption entries,
96                  * which seems wrong.
97                  */
98                 false
99                 );
100
101         dcp::DCP check (film->dir(film->dcp_name()));
102         check.read ();
103
104         BOOST_REQUIRE_EQUAL (check.cpls().size(), 1U);
105         BOOST_REQUIRE_EQUAL (check.cpls().front()->reels().size(), 1U);
106         auto ccaps = check.cpls().front()->reels().front()->closed_captions();
107         BOOST_REQUIRE_EQUAL (ccaps.size(), 3U);
108
109         auto i = ccaps.begin ();
110         BOOST_CHECK_EQUAL ((*i)->annotation_text().get_value_or(""), "First track");
111         BOOST_REQUIRE (static_cast<bool>((*i)->language()));
112         BOOST_CHECK_EQUAL ((*i)->language().get(), "fr-FR");
113         ++i;
114         BOOST_CHECK_EQUAL ((*i)->annotation_text().get_value_or(""), "Second track");
115         BOOST_REQUIRE (static_cast<bool>((*i)->language()));
116         BOOST_CHECK_EQUAL ((*i)->language().get(), "de-DE");
117         ++i;
118         BOOST_CHECK_EQUAL ((*i)->annotation_text().get_value_or(""), "Third track");
119         BOOST_REQUIRE (static_cast<bool>((*i)->language()));
120         BOOST_CHECK_EQUAL ((*i)->language().get(), "it-IT");
121
122         cl.run ();
123 }