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>
37 using boost::optional;
41 run(vector<string> const& args, vector<string>& output)
43 std::vector<char*> argv(args.size());
44 for (auto i = 0U; i < args.size(); ++i) {
45 argv[i] = const_cast<char*>(args[i].c_str());
48 auto error = kdm_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); });
50 std::cout << *error << "\n";
57 BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate)
59 vector<string> args = {
62 "--valid-from", "now",
63 "--valid-duration", "2 weeks",
64 "--certificate", "test/data/cert.pem",
65 "-S", "my great screen",
70 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";
71 boost::system::error_code ec;
72 boost::filesystem::remove(kdm_filename, ec);
74 vector<string> output;
75 auto error = run(args, output);
78 BOOST_CHECK(boost::filesystem::exists(kdm_filename));
86 auto config = Config::instance();
87 auto const cert = dcp::Certificate(dcp::file_to_string("test/data/cert.pem"));
89 auto cinema_a = std::make_shared<Cinema>("Dean's Screens", list<string>(), "", 0, 0);
90 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 1", "", cert, boost::none, std::vector<TrustedDevice>()));
91 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 2", "", cert, boost::none, std::vector<TrustedDevice>()));
92 cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 3", "", cert, boost::none, std::vector<TrustedDevice>()));
93 config->add_cinema(cinema_a);
95 auto cinema_b = std::make_shared<Cinema>("Floyd's Celluloid", list<string>(), "", 0, 0);
96 cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Foo", "", cert, boost::none, std::vector<TrustedDevice>()));
97 cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Bar", "", cert, boost::none, std::vector<TrustedDevice>()));
98 config->add_cinema(cinema_b);
102 BOOST_AUTO_TEST_CASE(kdm_cli_select_cinema)
108 vector<boost::filesystem::path> kdm_filenames = {
109 "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Foo.xml",
110 "build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Bar.xml"
113 for (auto path: kdm_filenames) {
114 boost::system::error_code ec;
115 boost::filesystem::remove(path, ec);
118 vector<string> args = {
121 "--valid-from", "now",
122 "--valid-duration", "2 weeks",
123 "-c", "Floyd's Celluloid",
128 vector<string> output;
129 auto error = run(args, output);
132 BOOST_REQUIRE_EQUAL(output.size(), 2U);
133 BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
134 BOOST_CHECK_EQUAL(output[1], "Wrote 2 KDM files to build/test");
136 for (auto path: kdm_filenames) {
137 BOOST_CHECK(boost::filesystem::exists(path));
142 BOOST_AUTO_TEST_CASE(kdm_cli_select_screen)
148 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";
150 boost::system::error_code ec;
151 boost::filesystem::remove(kdm_filename, ec);
153 vector<string> args = {
156 "--valid-from", "now",
157 "--valid-duration", "2 weeks",
158 "-c", "Dean's Screens",
164 vector<string> output;
165 auto error = run(args, output);
168 BOOST_REQUIRE_EQUAL(output.size(), 2U);
169 BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
170 BOOST_CHECK_EQUAL(output[1], "Wrote 1 KDM files to build/test");
172 BOOST_CHECK(boost::filesystem::exists(kdm_filename));