Fix font_id_map errors when importing DCP subtitles that have no
[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 <dcp/smpte_subtitle_asset.h>
28 #include "test.h"
29 #include <boost/test/unit_test.hpp>
30
31
32 using std::make_shared;
33
34
35 BOOST_AUTO_TEST_CASE(full_dcp_subtitle_font_id_test)
36 {
37         auto dcp = make_shared<DCPContent>(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV");
38         auto film = new_test_film2("full_dcp_subtitle_font_id_test", { dcp });
39
40         auto content = film->content();
41         BOOST_REQUIRE_EQUAL(content.size(), 1U);
42         auto text = content[0]->only_text();
43         BOOST_REQUIRE(text);
44
45         BOOST_REQUIRE_EQUAL(text->fonts().size(), 1U);
46         auto font = text->fonts().front();
47         BOOST_CHECK_EQUAL(font->id(), "0_theFontId");
48         BOOST_REQUIRE(font->data());
49         BOOST_CHECK_EQUAL(font->data()->size(), 367112);
50 }
51
52
53 BOOST_AUTO_TEST_CASE(dcp_subtitle_font_id_test)
54 {
55         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");
56         auto film = new_test_film2("dcp_subtitle_font_id_test", subs);
57
58         auto content = film->content();
59         BOOST_REQUIRE_EQUAL(content.size(), 1U);
60         auto text = content[0]->only_text();
61         BOOST_REQUIRE(text);
62
63         BOOST_REQUIRE_EQUAL(text->fonts().size(), 1U);
64         auto font = text->fonts().front();
65         BOOST_CHECK_EQUAL(font->id(), "theFontId");
66         BOOST_REQUIRE(font->data());
67         BOOST_CHECK_EQUAL(font->data()->size(), 367112);
68 }
69
70
71 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_interop_dcp)
72 {
73         auto dcp = make_shared<DCPContent>("test/data/Iopsubs_FTR-1_F_XX-XX_MOS_2K_20220710_IOP_OV");
74         auto film = new_test_film2("make_dcp_with_subs_from_interop_dcp", { dcp });
75         dcp->text.front()->set_use(true);
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                 }
82         );
83 }
84
85
86 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_smpte_dcp)
87 {
88         auto dcp = make_shared<DCPContent>(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV");
89         auto film = new_test_film2("make_dcp_with_subs_from_smpte_dcp", { dcp });
90         dcp->text.front()->set_use(true);
91         make_and_verify_dcp(film);
92 }
93
94
95 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_from_mkv)
96 {
97         auto subs = content_factory(TestPaths::private_data() / "clapperboard_with_subs.mkv");
98         auto film = new_test_film2("make_dcp_with_subs_from_mkv", subs);
99         subs[0]->text.front()->set_use(true);
100         subs[0]->text.front()->set_language(dcp::LanguageTag("en-US"));
101         make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K });
102 }
103
104
105 BOOST_AUTO_TEST_CASE(make_dcp_with_subs_without_font_tag)
106 {
107         auto subs = content_factory("test/data/no_font.xml");
108         auto film = new_test_film2("make_dcp_with_subs_without_font_tag", { subs });
109         subs[0]->text.front()->set_use(true);
110         make_and_verify_dcp(
111                 film,
112                 {
113                         dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
114                         dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
115                         dcp::VerificationNote::Code::MISSING_CPL_METADATA
116                 });
117
118         auto check_file = subtitle_file(film);
119         dcp::SMPTESubtitleAsset check_asset(check_file);
120         BOOST_CHECK_EQUAL(check_asset.load_font_nodes().size(), 1U);
121         auto check_font_data = check_asset.font_data();
122         BOOST_CHECK_EQUAL(check_font_data.size(), 1U);
123         BOOST_CHECK(check_font_data.begin()->second == dcp::ArrayData(default_font_file()));
124 }
125