878dc650668bd30d152aaea709fcb1b1f873b477
[dcpomatic.git] / test / subtitle_font_id_change_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 /** @file  test/subtitle_font_id_change_test.cc
23  *  @brief Check that old projects can still be used after the changes in 5a820bb8fae34591be5ac6d19a73461b9dab532a
24  */
25
26
27 #include "lib/check_content_job.h"
28 #include "lib/content.h"
29 #include "lib/film.h"
30 #include "lib/font.h"
31 #include "lib/text_content.h"
32 #include "test.h"
33 #include <dcp/verify.h>
34 #include <boost/filesystem.hpp>
35 #include <boost/test/unit_test.hpp>
36
37
38 using std::string;
39
40
41 BOOST_AUTO_TEST_CASE(subtitle_font_id_change_test1)
42 {
43         auto film = new_test_film2("subtitle_font_id_change_test1");
44         boost::filesystem::remove(film->file("metadata.xml"));
45         boost::filesystem::copy_file("test/data/subtitle_font_id_change_test1.xml", film->file("metadata.xml"));
46         film->read_metadata();
47
48         auto content = film->content();
49         BOOST_REQUIRE_EQUAL(content.size(), 1U);
50         BOOST_REQUIRE_EQUAL(content[0]->text.size(), 1U);
51
52         content[0]->set_paths({"test/data/short.srt"});
53
54         CheckContentJob check(film);
55         check.run();
56         BOOST_REQUIRE (!wait_for_jobs());
57
58         make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_STANDARD });
59 }
60
61
62 BOOST_AUTO_TEST_CASE(subtitle_font_id_change_test2)
63 {
64         auto film = new_test_film2("subtitle_font_id_change_test2");
65         boost::filesystem::remove(film->file("metadata.xml"));
66         boost::filesystem::copy_file("test/data/subtitle_font_id_change_test2.xml", film->file("metadata.xml"));
67         {
68                 Editor editor(film->file("metadata.xml"));
69                 editor.replace("/usr/share/fonts/truetype/inconsolata/Inconsolata.otf", "test/data/Inconsolata-VF.ttf");
70         }
71         film->read_metadata();
72
73         auto content = film->content();
74         BOOST_REQUIRE_EQUAL(content.size(), 1U);
75         BOOST_REQUIRE_EQUAL(content[0]->text.size(), 1U);
76
77         content[0]->set_paths({"test/data/short.srt"});
78         /* Make sure the content doesn't look like it's changed, otherwise it will be re-examined
79          * which obscures the point of this test.
80          */
81         content[0]->_last_write_times[0] = boost::filesystem::last_write_time("test/data/short.srt");
82
83         CheckContentJob check(film);
84         check.run();
85         BOOST_REQUIRE (!wait_for_jobs());
86
87         auto font = content[0]->text.front()->get_font("");
88         BOOST_REQUIRE(font->file());
89         BOOST_CHECK_EQUAL(*font->file(), "test/data/Inconsolata-VF.ttf");
90
91         make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_STANDARD });
92 }
93
94
95 BOOST_AUTO_TEST_CASE(subtitle_font_id_change_test3)
96 {
97         auto film = new_test_film2("subtitle_font_id_change_test3");
98         boost::filesystem::remove(film->file("metadata.xml"));
99         boost::filesystem::copy_file("test/data/subtitle_font_id_change_test3.xml", film->file("metadata.xml"));
100         {
101                 Editor editor(film->file("metadata.xml"));
102                 editor.replace("/usr/share/fonts/truetype/inconsolata/Inconsolata.otf", "test/data/Inconsolata-VF.ttf");
103         }
104         film->read_metadata();
105
106         auto content = film->content();
107         BOOST_REQUIRE_EQUAL(content.size(), 1U);
108         BOOST_REQUIRE_EQUAL(content[0]->text.size(), 1U);
109
110         content[0]->set_paths({"test/data/fonts.ass"});
111
112         CheckContentJob check(film);
113         check.run();
114         BOOST_REQUIRE (!wait_for_jobs());
115
116         auto font = content[0]->text.front()->get_font("Arial Black");
117         BOOST_REQUIRE(font->file());
118         BOOST_CHECK_EQUAL(*font->file(), "test/data/Inconsolata-VF.ttf");
119
120         font = content[0]->text.front()->get_font("Helvetica Neue");
121         BOOST_REQUIRE(font->file());
122         BOOST_CHECK_EQUAL(*font->file(), "test/data/Inconsolata-VF.ttf");
123
124         make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_STANDARD });
125 }
126
127
128 BOOST_AUTO_TEST_CASE(subtitle_font_id_change_test4)
129 {
130         auto film = new_test_film2("subtitle_font_id_change_test4");
131         boost::filesystem::remove(film->file("metadata.xml"));
132         boost::filesystem::copy_file("test/data/subtitle_font_id_change_test4.xml", film->file("metadata.xml"));
133
134         {
135                 Editor editor(film->file("metadata.xml"));
136                 editor.replace("dcpomatic-test-private", TestPaths::private_data().string());
137         }
138
139         film->read_metadata();
140
141         auto content = film->content();
142         BOOST_REQUIRE_EQUAL(content.size(), 1U);
143         BOOST_REQUIRE_EQUAL(content[0]->text.size(), 1U);
144
145         CheckContentJob check(film);
146         check.run();
147         BOOST_REQUIRE(!wait_for_jobs());
148
149         make_and_verify_dcp(film, { dcp::VerificationNote::Code::INVALID_STANDARD });
150 }
151