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);
82 make_and_verify_dcp (film);
83 auto cpls = film->cpls ();
84 BOOST_REQUIRE(cpls.size() == 1);
86 dcp::LocalTime from (cert.not_before());
88 dcp::LocalTime until (cert.not_after());
89 until.add_months (-2);
91 string const from_string = from.date() + " " + from.time_of_day(true, false);
92 string const until_string = until.date() + " " + until.time_of_day(true, false);
94 auto cpl = cpls.front().cpl_file;
95 auto kdm = kdm_for_screen (
97 cpls.front().cpl_file,
99 boost::posix_time::time_from_string(from_string),
100 boost::posix_time::time_from_string(until_string),
101 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
108 boost::filesystem::path("build/test/single_kdm_naming_test"),
109 dcp::NameFormat("KDM %c - %s - %f - %b - %e"),
113 string from_time = from.time_of_day (true, false);
114 boost::algorithm::replace_all (from_time, ":", "-");
115 string until_time = until.time_of_day (true, false);
116 boost::algorithm::replace_all (until_time, ":", "-");
118 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);
119 BOOST_CHECK_MESSAGE (boost::filesystem::exists("build/test/single_kdm_naming_test/" + ref), "File " << ref << " not found");
123 BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on("single_kdm_naming_test"))
125 using boost::filesystem::path;
127 dcp::Certificate cert = Config::instance()->decryption_chain()->leaf();
130 boost::filesystem::remove_all ("build/test/directory_kdm_naming_test");
131 auto film = new_test_film2 (
132 "directory_kdm_naming_test",
133 { content_factory("test/data/flat_black.png").front() }
136 film->set_name ("my_great_film");
137 film->set_encrypted (true);
138 make_and_verify_dcp (film);
139 auto cpls = film->cpls ();
140 BOOST_REQUIRE(cpls.size() == 1);
142 dcp::LocalTime from (cert.not_before());
144 dcp::LocalTime until (cert.not_after());
145 until.add_months (-2);
147 string const from_string = from.date() + " " + from.time_of_day(true, false);
148 string const until_string = until.date() + " " + until.time_of_day(true, false);
150 list<shared_ptr<dcpomatic::Screen>> screens = {
151 cinema_a_screen_2, cinema_b_screen_x, cinema_a_screen_1, (cinema_b_screen_z)
154 auto const cpl = cpls.front().cpl_file;
155 auto const cpl_id = cpls.front().cpl_id;
157 list<KDMWithMetadataPtr> kdms;
158 for (auto i: screens) {
159 auto kdm = kdm_for_screen (
161 cpls.front().cpl_file,
163 boost::posix_time::time_from_string(from_string),
164 boost::posix_time::time_from_string(until_string),
165 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
170 kdms.push_back (kdm);
175 path("build/test/directory_kdm_naming_test"),
176 dcp::NameFormat("%c - %s - %f - %b - %e"),
177 #ifdef DCPOMATIC_WINDOWS
178 /* With %i in the format the path is too long for Windows */
179 dcp::NameFormat("KDM %c - %s - %f - %b - %e"),
181 dcp::NameFormat("KDM %c - %s - %f - %b - %e - %i"),
186 auto from_time = from.time_of_day (true, false);
187 boost::algorithm::replace_all (from_time, ":", "-");
188 auto until_time = until.time_of_day (true, false);
189 boost::algorithm::replace_all (until_time, ":", "-");
191 path const base = "build/test/directory_kdm_naming_test";
193 path dir_a = String::compose("Cinema_A_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
194 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a), "Directory " << dir_a << " not found");
195 path dir_b = String::compose("Cinema_B_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
196 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b), "Directory " << dir_b << " not found");
198 #ifdef DCPOMATIC_WINDOWS
199 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);
201 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);
203 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
205 #ifdef DCPOMATIC_WINDOWS
206 ref = String::compose("KDM_Cinema_B_-_Screen_X_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
208 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);
210 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");
212 #ifdef DCPOMATIC_WINDOWS
213 ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
215 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);
217 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
219 #ifdef DCPOMATIC_WINDOWS
220 ref = String::compose("KDM_Cinema_B_-_Screen_Z_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
222 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);
224 BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");