2 Copyright (C) 2022 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/>.
22 #include "lib/cinema.h"
23 #include "lib/config.h"
24 #include "lib/content_factory.h"
26 #include "lib/kdm_cli.h"
27 #include "lib/screen.h"
28 #include "lib/trusted_device.h"
30 #include <boost/algorithm/string/predicate.hpp>
31 #include <boost/filesystem.hpp>
32 #include <boost/test/unit_test.hpp>
38 using boost::optional;
42 run(vector<string> const& args, vector<string>& output)
44 std::vector<char*> argv(args.size());
45 for (auto i = 0U; i < args.size(); ++i) {
46 argv[i] = const_cast<char*>(args[i].c_str());
49 auto error = kdm_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); });
51 std::cout << *error << "\n";
58 BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate)
60 vector<string> args = {
63 "--valid-from", "now",
64 "--valid-duration", "2 weeks",
65 "--certificate", "test/data/cert.pem",
66 "-S", "my great screen",
71 boost::filesystem::path const kdm_filename = "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV__my_great_screen.xml";
72 boost::system::error_code ec;
73 boost::filesystem::remove(kdm_filename, ec);
75 vector<string> output;
76 auto error = run(args, output);
79 BOOST_CHECK(boost::filesystem::exists(kdm_filename));
87 auto config = Config::instance();
88 auto const cert = dcp::Certificate(dcp::file_to_string("test/data/cert.pem"));
90 auto cinema_a = std::make_shared<Cinema>("Dean's Screens", vector<string>(), "", 0, 0);
91 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 1", "", cert, boost::none, std::vector<TrustedDevice>()));
92 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 2", "", cert, boost::none, std::vector<TrustedDevice>()));
93 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 3", "", cert, boost::none, std::vector<TrustedDevice>()));
94 config->add_cinema(cinema_a);
96 auto cinema_b = std::make_shared<Cinema>("Floyd's Celluloid", vector<string>(), "", 0, 0);
97 cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Foo", "", cert, boost::none, std::vector<TrustedDevice>()));
98 cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Bar", "", cert, boost::none, std::vector<TrustedDevice>()));
99 config->add_cinema(cinema_b);
103 BOOST_AUTO_TEST_CASE(kdm_cli_select_cinema)
109 vector<boost::filesystem::path> kdm_filenames = {
110 "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Foo.xml",
111 "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Bar.xml"
114 for (auto path: kdm_filenames) {
115 boost::system::error_code ec;
116 boost::filesystem::remove(path, ec);
119 vector<string> args = {
122 "--valid-from", "now",
123 "--valid-duration", "2 weeks",
124 "-c", "Floyd's Celluloid",
129 vector<string> output;
130 auto error = run(args, output);
133 BOOST_REQUIRE_EQUAL(output.size(), 2U);
134 BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
135 BOOST_CHECK_EQUAL(output[1], "Wrote 2 KDM files to build/test");
137 for (auto path: kdm_filenames) {
138 BOOST_CHECK(boost::filesystem::exists(path));
143 BOOST_AUTO_TEST_CASE(kdm_cli_select_screen)
149 boost::filesystem::path kdm_filename = "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Deans_Screens_Screen_2.xml";
151 boost::system::error_code ec;
152 boost::filesystem::remove(kdm_filename, ec);
154 vector<string> args = {
157 "--valid-from", "now",
158 "--valid-duration", "2 weeks",
159 "-c", "Dean's Screens",
165 vector<string> output;
166 auto error = run(args, output);
169 BOOST_REQUIRE_EQUAL(output.size(), 2U);
170 BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
171 BOOST_CHECK_EQUAL(output[1], "Wrote 1 KDM files to build/test");
173 BOOST_CHECK(boost::filesystem::exists(kdm_filename));
177 BOOST_AUTO_TEST_CASE(kdm_cli_specify_cinemas_file)
183 vector<string> args = {
186 "test/data/cinemas.xml",
190 vector<string> output;
191 auto const error = run(args, output);
194 BOOST_REQUIRE_EQUAL(output.size(), 3U);
195 BOOST_CHECK_EQUAL(output[0], "stinking dump ()");
196 BOOST_CHECK_EQUAL(output[1], "classy joint ()");
197 BOOST_CHECK_EQUAL(output[2], "Great ()");
201 BOOST_AUTO_TEST_CASE(kdm_cli_specify_cert)
203 boost::filesystem::path kdm_filename = "build/test/KDM_KDMCLI__.xml";
205 boost::system::error_code ec;
206 boost::filesystem::remove(kdm_filename, ec);
208 auto film = new_test_film2("kdm_cli_specify_cert", content_factory("test/data/flat_red.png"));
209 film->set_encrypted(true);
210 film->set_name("KDMCLI");
211 film->set_use_isdcf_name(false);
212 make_and_verify_dcp(film);
214 vector<string> args = {
216 "--valid-from", "2024-01-01 10:10:10",
217 "--valid-duration", "2 weeks",
218 "-C", "test/data/cert.pem",
220 "build/test/kdm_cli_specify_cert"
223 vector<string> output;
224 auto error = run(args, output);
227 BOOST_CHECK(output.empty());
228 BOOST_CHECK(boost::filesystem::exists(kdm_filename));