Make pause/resume work properly in the batch converter.
[dcpomatic.git] / test / subtitle_font_id_test.cc
1 /*
2     Copyright (C) 2022 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/content_factory.h"
23 #include "lib/dcp_content.h"
24 #include "lib/film.h"
25 #include "lib/font.h"
26 #include "lib/text_content.h"
27 #include "lib/util.h"
28 #include <dcp/cpl.h>
29 #include <dcp/dcp.h>
30 #include <dcp/reel.h>
31 #include <dcp/reel_subtitle_asset.h>
32 #include <dcp/smpte_subtitle_asset.h>
33 #include "test.h"
34 #include <boost/test/unit_test.hpp>
35
36
37 using std::make_shared;
38 using std::shared_ptr;
39
40
41 BOOST_AUTO_TEST_CASE(full_dcp_subtitle_font_id_test)
42 {
43         auto dcp = make_shared<DCPContent>(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV");
44         auto film = new_test_film2("full_dcp_subtitle_font_id_test", { dcp });
45
46         auto content = film->content();
47         BOOST_REQUIRE_EQUAL(content.size(), 1U);
48         auto text = content[0]->only_text();
49         BOOST_REQUIRE(text);
50
51         BOOST_REQUIRE_EQUAL(text->fonts().size(), 1U);
52         auto font = text->fonts().front();
53         BOOST_CHECK_EQUAL(font->id(), "0_theFontId");
54         BOOST_REQUIRE(font->data());
55         BOOST_CHECK_EQUAL(font->data()->size(), 367112);
56 }
57
58
59 BOOST_AUTO_TEST_CASE(dcp_subtitle_font_id_test)
60 {
61         auto subs = content_factory(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV" / "8b48f6ae-c74b-4b80-b994-a8236bbbad74_sub.mxf");
62         auto film = new_test_film2("dcp_subtitle_font_id_test", subs);
63
64         auto content = film->content();
65         BOOST_REQUIRE_EQUAL(content.size(), 1U);
66         auto text = content[0]->only_text();
67         BOOST_REQUIRE(text);
68
69         BOOST_REQUIRE_EQUAL(text->fonts().size(), 1U);
70         auto font = text->fonts().front();
71         BOOST_CHECK_EQUAL(font->id(), "theFontId");
72         BOOST_REQUIRE(font->data());
73         BOOST_CHECK_EQUAL(font->data()->size(), 367112);
74 }
75
76
77 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_interop_dcp)
78 {
79         auto dcp = make_shared<DCPContent>("test/data/Iopsubs_FTR-1_F_XX-XX_MOS_2K_20220710_IOP_OV");
80         auto film = new_test_film2("make_dcp_with_subs_from_interop_dcp", { dcp });
81         dcp->text.front()->set_use(true);
82         make_and_verify_dcp(
83                 film,
84                 {
85                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
86                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME
87                 }
88         );
89 }
90
91
92 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_smpte_dcp)
93 {
94         auto dcp = make_shared<DCPContent>(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV");
95         auto film = new_test_film2("make_dcp_with_subs_from_smpte_dcp", { dcp });
96         dcp->text.front()->set_use(true);
97         make_and_verify_dcp(film);
98 }
99
100
101 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_mkv)
102 {
103         auto subs = content_factory(TestPaths::private_data() / "clapperboard_with_subs.mkv");
104         auto film = new_test_film2("make_dcp_with_subs_from_mkv", subs);
105         subs[0]->text.front()->set_use(true);
106         subs[0]->text.front()->set_language(dcp::LanguageTag("en-US"));
107         make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K });
108 }
109
110
111 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_without_font_tag)
112 {
113         auto subs = content_factory("test/data/no_font.xml");
114         auto film = new_test_film2("make_dcp_with_subs_without_font_tag", { subs });
115         subs[0]->text.front()->set_use(true);
116         make_and_verify_dcp(
117                 film,
118                 {
119                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
120                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
121                         dcp::VerificationNote::Code::MISSING_CPL_METADATA
122                 });
123
124         auto check_file = subtitle_file(film);
125         dcp::SMPTESubtitleAsset check_asset(check_file);
126         BOOST_CHECK_EQUAL(check_asset.load_font_nodes().size(), 1U);
127         auto check_font_data = check_asset.font_data();
128         BOOST_CHECK_EQUAL(check_font_data.size(), 1U);
129         BOOST_CHECK(check_font_data.begin()->second == dcp::ArrayData(default_font_file()));
130 }
131
132
133 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_in_dcp_without_font_tag)
134 {
135         /* Make a DCP with some subs in */
136         auto source_subs = content_factory("test/data/short.srt");
137         auto source = new_test_film2("make_dcp_with_subs_in_dcp_without_font_tag_source", { source_subs });
138         source->set_interop(true);
139         make_and_verify_dcp(
140                 source,
141                 {
142                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
143                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
144                         dcp::VerificationNote::Code::MISSING_CPL_METADATA,
145                         dcp::VerificationNote::Code::INVALID_STANDARD
146                 });
147
148         /* Find the ID of the subs */
149         dcp::DCP source_dcp(source->dir(source->dcp_name()));
150         source_dcp.read();
151         BOOST_REQUIRE(!source_dcp.cpls().empty());
152         BOOST_REQUIRE(!source_dcp.cpls()[0]->reels().empty());
153         BOOST_REQUIRE(source_dcp.cpls()[0]->reels()[0]->main_subtitle());
154         auto const id = source_dcp.cpls()[0]->reels()[0]->main_subtitle()->asset()->id();
155
156         /* Graft in some bad subs with no <Font> tag */
157         auto source_subtitle_file = subtitle_file(source);
158 #if BOOST_VERSION >= 107400
159         boost::filesystem::copy_file("test/data/no_font.xml", source_subtitle_file, boost::filesystem::copy_options::overwrite_existing);
160 #else
161         boost::filesystem::copy_file("test/data/no_font.xml", source_subtitle_file, boost::filesystem::copy_option::overwrite_if_exists);
162 #endif
163
164         /* Fix the <Id> tag */
165         {
166                 Editor editor(source_subtitle_file);
167                 editor.replace("4dd8ee05-5986-4c67-a6f8-bbeac62e21db", id);
168         }
169
170         /* Now make a project which imports that DCP and makes another DCP from it */
171         auto dcp_content = make_shared<DCPContent>(source->dir(source->dcp_name()));
172         auto film = new_test_film2("make_dcp_with_subs_without_font_tag", { dcp_content });
173         BOOST_REQUIRE(!dcp_content->text.empty());
174         dcp_content->text.front()->set_use(true);
175         make_and_verify_dcp(
176                 film,
177                 {
178                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
179                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
180                         dcp::VerificationNote::Code::MISSING_CPL_METADATA
181                 });
182
183         auto check_file = subtitle_file(film);
184         dcp::SMPTESubtitleAsset check_asset(check_file);
185         BOOST_CHECK_EQUAL(check_asset.load_font_nodes().size(), 1U);
186         auto check_font_data = check_asset.font_data();
187         BOOST_CHECK_EQUAL(check_font_data.size(), 1U);
188         BOOST_CHECK(check_font_data.begin()->second == dcp::ArrayData(default_font_file()));
189 }
190