2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 #include "lib/cinema.h"
22 #include "lib/screen.h"
23 #include "lib/config.h"
24 #include "lib/content_factory.h"
26 #include "lib/kdm_with_metadata.h"
28 #include <boost/test/unit_test.hpp>
34 using std::shared_ptr;
35 using boost::optional;
36 using std::dynamic_pointer_cast;
40 confirm_overwrite (boost::filesystem::path)
45 static shared_ptr<dcpomatic::Screen> cinema_a_screen_1;
46 static shared_ptr<dcpomatic::Screen> cinema_a_screen_2;
47 static shared_ptr<dcpomatic::Screen> cinema_b_screen_x;
48 static shared_ptr<dcpomatic::Screen> cinema_b_screen_y;
49 static shared_ptr<dcpomatic::Screen> cinema_b_screen_z;
51 BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
53 Config* c = Config::instance();
55 dcp::Certificate cert = c->decryption_chain()->leaf();
57 /* Cinema A: UTC +4:30 */
58 shared_ptr<Cinema> cinema_a (new Cinema("Cinema A", list<string>(), "", 4, 30));
59 cinema_a_screen_1.reset(new dcpomatic::Screen("Screen 1", "", cert, vector<TrustedDevice>()));
60 cinema_a->add_screen (cinema_a_screen_1);
61 cinema_a_screen_2.reset(new dcpomatic::Screen("Screen 2", "", cert, vector<TrustedDevice>()));
62 cinema_a->add_screen (cinema_a_screen_2);
63 c->add_cinema (cinema_a);
65 /* Cinema B: UTC -1:00 */
66 shared_ptr<Cinema> cinema_b (new Cinema("Cinema B", list<string>(), "", -1, 0));
67 cinema_b_screen_x.reset(new dcpomatic::Screen("Screen X", "", cert, vector<TrustedDevice>()));
68 cinema_b->add_screen (cinema_b_screen_x);
69 cinema_b_screen_y.reset(new dcpomatic::Screen("Screen Y", "", cert, vector<TrustedDevice>()));
70 cinema_b->add_screen (cinema_b_screen_y);
71 cinema_b_screen_z.reset(new dcpomatic::Screen("Screen Z", "", cert, vector<TrustedDevice>()));
72 cinema_b->add_screen (cinema_b_screen_z);
73 c->add_cinema (cinema_a);
76 boost::filesystem::remove_all ("build/test/single_kdm_naming_test");
77 shared_ptr<Film> film = new_test_film2 ("single_kdm_naming_test");
78 film->set_name ("my_great_film");
79 film->examine_and_add_content (content_factory("test/data/flat_black.png").front());
80 BOOST_REQUIRE (!wait_for_jobs());
81 film->set_encrypted (true);
83 BOOST_REQUIRE (!wait_for_jobs());
84 film->write_metadata ();
85 vector<CPLSummary> cpls = film->cpls ();
86 BOOST_REQUIRE(cpls.size() == 1);
88 dcp::LocalTime from (cert.not_before());
90 dcp::LocalTime until (cert.not_after());
91 until.add_months (-2);
93 string const from_string = from.date() + " " + from.time_of_day(true, false);
94 string const until_string = until.date() + " " + until.time_of_day(true, false);
96 boost::filesystem::path cpl = cpls.front().cpl_file;
97 KDMWithMetadataPtr kdm = kdm_for_screen (
99 cpls.front().cpl_file,
101 boost::posix_time::time_from_string(from_string),
102 boost::posix_time::time_from_string(until_string),
103 dcp::MODIFIED_TRANSITIONAL_1,
108 list<KDMWithMetadataPtr> kdms;
109 kdms.push_back (kdm);
113 boost::filesystem::path("build/test/single_kdm_naming_test"),
114 dcp::NameFormat("KDM %c - %s - %f - %b - %e"),
118 string from_time = from.time_of_day (true, false);
119 boost::algorithm::replace_all (from_time, ":", "-");
120 string until_time = until.time_of_day (true, false);
121 boost::algorithm::replace_all (until_time, ":", "-");
123 string const ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
124 BOOST_CHECK_MESSAGE (boost::filesystem::exists("build/test/single_kdm_naming_test/" + ref), "File " << ref << " not found");
128 BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on("single_kdm_naming_test"))
130 using boost::filesystem::path;
132 dcp::Certificate cert = Config::instance()->decryption_chain()->leaf();
135 boost::filesystem::remove_all ("build/test/directory_kdm_naming_test");
136 shared_ptr<Film> film = new_test_film2 ("directory_kdm_naming_test");
137 film->set_name ("my_great_film");
138 film->examine_and_add_content (content_factory("test/data/flat_black.png").front());
139 BOOST_REQUIRE (!wait_for_jobs());
140 film->set_encrypted (true);
142 BOOST_REQUIRE (!wait_for_jobs());
143 film->write_metadata ();
144 vector<CPLSummary> cpls = film->cpls ();
145 BOOST_REQUIRE(cpls.size() == 1);
147 dcp::LocalTime from (cert.not_before());
149 dcp::LocalTime until (cert.not_after());
150 until.add_months (-2);
152 string const from_string = from.date() + " " + from.time_of_day(true, false);
153 string const until_string = until.date() + " " + until.time_of_day(true, false);
155 list<shared_ptr<dcpomatic::Screen> > screens;
156 screens.push_back (cinema_a_screen_2);
157 screens.push_back (cinema_b_screen_x);
158 screens.push_back (cinema_a_screen_1);
159 screens.push_back (cinema_b_screen_z);
161 path const cpl = cpls.front().cpl_file;
162 string const cpl_id = cpls.front().cpl_id;
164 list<KDMWithMetadataPtr> kdms;
165 BOOST_FOREACH (shared_ptr<dcpomatic::Screen> i, screens) {
166 KDMWithMetadataPtr kdm = kdm_for_screen (
168 cpls.front().cpl_file,
170 boost::posix_time::time_from_string(from_string),
171 boost::posix_time::time_from_string(until_string),
172 dcp::MODIFIED_TRANSITIONAL_1,
177 kdms.push_back (kdm);
182 path("build/test/directory_kdm_naming_test"),
183 dcp::NameFormat("%c - %s - %f - %b - %e"),
184 #ifdef DCPOMATIC_WINDOWS
185 /* With %i in the format the path is too long for Windows */
186 dcp::NameFormat("KDM %c - %s - %f - %b - %e"),
188 dcp::NameFormat("KDM %c - %s - %f - %b - %e - %i"),
193 string from_time = from.time_of_day (true, false);
194 boost::algorithm::replace_all (from_time, ":", "-");
195 string until_time = until.time_of_day (true, false);
196 boost::algorithm::replace_all (until_time, ":", "-");
198 path const base = "build/test/directory_kdm_naming_test";
200 path dir_a = String::compose("Cinema_A_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
201 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a), "Directory " << dir_a << " not found");
202 path dir_b = String::compose("Cinema_B_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
203 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b), "Directory " << dir_b << " not found");
205 #ifdef DCPOMATIC_WINDOWS
206 path ref = String::compose("KDM_Cinema_A_-_Screen_2_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
208 path ref = String::compose("KDM_Cinema_A_-_Screen_2_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
210 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
212 #ifdef DCPOMATIC_WINDOWS
213 ref = String::compose("KDM_Cinema_B_-_Screen_X_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
215 ref = String::compose("KDM_Cinema_B_-_Screen_X_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
217 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");
219 #ifdef DCPOMATIC_WINDOWS
220 ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
222 ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
224 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
226 #ifdef DCPOMATIC_WINDOWS
227 ref = String::compose("KDM_Cinema_B_-_Screen_Z_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
229 ref = String::compose("KDM_Cinema_B_-_Screen_Z_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
231 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");