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/kdm_cli.h"
25 #include "lib/screen.h"
26 #include "lib/trusted_device.h"
28 #include <boost/algorithm/string/predicate.hpp>
29 #include <boost/filesystem.hpp>
30 #include <boost/test/unit_test.hpp>
36 using boost::optional;
40 run(vector<string> const& args, vector<string>& output)
42 std::vector<char*> argv(args.size());
43 for (auto i = 0U; i < args.size(); ++i) {
44 argv[i] = const_cast<char*>(args[i].c_str());
47 auto error = kdm_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); });
49 std::cout << *error << "\n";
56 BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate)
58 vector<string> args = {
61 "--valid-from", "now",
62 "--valid-duration", "2 weeks",
63 "--certificate", "test/data/cert.pem",
64 "-S", "my great screen",
69 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";
70 boost::system::error_code ec;
71 boost::filesystem::remove(kdm_filename, ec);
73 vector<string> output;
74 auto error = run(args, output);
77 BOOST_CHECK(boost::filesystem::exists(kdm_filename));
85 auto config = Config::instance();
86 auto const cert = dcp::Certificate(dcp::file_to_string("test/data/cert.pem"));
88 auto cinema_a = std::make_shared<Cinema>("Dean's Screens", vector<string>(), "", 0, 0);
89 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 1", "", cert, boost::none, std::vector<TrustedDevice>()));
90 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 2", "", cert, boost::none, std::vector<TrustedDevice>()));
91 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 3", "", cert, boost::none, std::vector<TrustedDevice>()));
92 config->add_cinema(cinema_a);
94 auto cinema_b = std::make_shared<Cinema>("Floyd's Celluloid", vector<string>(), "", 0, 0);
95 cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Foo", "", cert, boost::none, std::vector<TrustedDevice>()));
96 cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Bar", "", cert, boost::none, std::vector<TrustedDevice>()));
97 config->add_cinema(cinema_b);
101 BOOST_AUTO_TEST_CASE(kdm_cli_select_cinema)
107 vector<boost::filesystem::path> kdm_filenames = {
108 "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Foo.xml",
109 "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Bar.xml"
112 for (auto path: kdm_filenames) {
113 boost::system::error_code ec;
114 boost::filesystem::remove(path, ec);
117 vector<string> args = {
120 "--valid-from", "now",
121 "--valid-duration", "2 weeks",
122 "-c", "Floyd's Celluloid",
127 vector<string> output;
128 auto error = run(args, output);
131 BOOST_REQUIRE_EQUAL(output.size(), 2U);
132 BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
133 BOOST_CHECK_EQUAL(output[1], "Wrote 2 KDM files to build/test");
135 for (auto path: kdm_filenames) {
136 BOOST_CHECK(boost::filesystem::exists(path));
141 BOOST_AUTO_TEST_CASE(kdm_cli_select_screen)
147 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";
149 boost::system::error_code ec;
150 boost::filesystem::remove(kdm_filename, ec);
152 vector<string> args = {
155 "--valid-from", "now",
156 "--valid-duration", "2 weeks",
157 "-c", "Dean's Screens",
163 vector<string> output;
164 auto error = run(args, output);
167 BOOST_REQUIRE_EQUAL(output.size(), 2U);
168 BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
169 BOOST_CHECK_EQUAL(output[1], "Wrote 1 KDM files to build/test");
171 BOOST_CHECK(boost::filesystem::exists(kdm_filename));