cc2dca930e8457ab9eb2efd07f5a4f9e3492b65f
[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 #include "lib/film.h"
22 #include "lib/text_content.h"
23 #include "lib/string_text_file_content.h"
24 #include "test.h"
25 #include <dcp/dcp.h>
26 #include <dcp/cpl.h>
27 #include <dcp/reel.h>
28 #include <dcp/reel_closed_caption_asset.h>
29 #include <boost/test/unit_test.hpp>
30
31 using std::list;
32 using std::make_shared;
33 using std::shared_ptr;
34
35 /** Basic test that Interop closed captions are written */
36 BOOST_AUTO_TEST_CASE (closed_caption_test1)
37 {
38         Cleanup cl;
39
40         auto film = new_test_film2 ("closed_caption_test1", &cl);
41         auto content = make_shared<StringTextFileContent>("test/data/subrip.srt");
42         film->examine_and_add_content (content);
43         BOOST_REQUIRE (!wait_for_jobs ());
44
45         content->only_text()->set_type (TextType::CLOSED_CAPTION);
46
47         film->make_dcp ();
48         BOOST_REQUIRE (!wait_for_jobs ());
49
50         /* Just check to see that there's a CCAP in the CPL: this
51            check could be better!
52         */
53
54         dcp::DCP check (film->dir(film->dcp_name()));
55         check.read ();
56
57         BOOST_REQUIRE_EQUAL (check.cpls().size(), 1U);
58         BOOST_REQUIRE_EQUAL (check.cpls().front()->reels().size(), 1U);
59         BOOST_REQUIRE (!check.cpls().front()->reels().front()->closed_captions().empty());
60
61         cl.run ();
62 }
63
64 /** Test multiple closed captions */
65 BOOST_AUTO_TEST_CASE (closed_caption_test2)
66 {
67         Cleanup cl;
68
69         auto film = new_test_film2 ("closed_caption_test2", &cl);
70         auto content1 = make_shared<StringTextFileContent>("test/data/subrip.srt");
71         film->examine_and_add_content (content1);
72         auto content2 = make_shared<StringTextFileContent>("test/data/subrip2.srt");
73         film->examine_and_add_content (content2);
74         auto content3 = make_shared<StringTextFileContent>("test/data/subrip3.srt");
75         film->examine_and_add_content (content3);
76         BOOST_REQUIRE (!wait_for_jobs ());
77
78         content1->only_text()->set_type (TextType::CLOSED_CAPTION);
79         content1->only_text()->set_dcp_track (DCPTextTrack("First track", "fr-FR"));
80         content2->only_text()->set_type (TextType::CLOSED_CAPTION);
81         content2->only_text()->set_dcp_track (DCPTextTrack("Second track", "de-DE"));
82         content3->only_text()->set_type (TextType::CLOSED_CAPTION);
83         content3->only_text()->set_dcp_track (DCPTextTrack("Third track", "it-IT"));
84
85         film->make_dcp ();
86         BOOST_REQUIRE (!wait_for_jobs ());
87
88         dcp::DCP check (film->dir(film->dcp_name()));
89         check.read ();
90
91         BOOST_REQUIRE_EQUAL (check.cpls().size(), 1U);
92         BOOST_REQUIRE_EQUAL (check.cpls().front()->reels().size(), 1U);
93         auto ccaps = check.cpls().front()->reels().front()->closed_captions();
94         BOOST_REQUIRE_EQUAL (ccaps.size(), 3U);
95
96         auto i = ccaps.begin ();
97         BOOST_CHECK_EQUAL ((*i)->annotation_text(), "First track");
98         BOOST_REQUIRE (static_cast<bool>((*i)->language()));
99         BOOST_CHECK_EQUAL ((*i)->language().get(), "fr-FR");
100         ++i;
101         BOOST_CHECK_EQUAL ((*i)->annotation_text(), "Second track");
102         BOOST_REQUIRE (static_cast<bool>((*i)->language()));
103         BOOST_CHECK_EQUAL ((*i)->language().get(), "de-DE");
104         ++i;
105         BOOST_CHECK_EQUAL ((*i)->annotation_text(), "Third track");
106         BOOST_REQUIRE (static_cast<bool>((*i)->language()));
107         BOOST_CHECK_EQUAL ((*i)->language().get(), "it-IT");
108
109         cl.run ();
110 }