1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/*
Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lib/cinema.h"
#include "lib/config.h"
#include "lib/kdm_cli.h"
#include "lib/screen.h"
#include "lib/trusted_device.h"
#include "test.h"
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
using std::string;
using std::vector;
using boost::optional;
optional<string>
run(vector<string> const& args, vector<string>& output)
{
std::vector<char*> argv(args.size());
for (auto i = 0U; i < args.size(); ++i) {
argv[i] = const_cast<char*>(args[i].c_str());
}
auto error = kdm_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); });
if (error) {
std::cout << *error << "\n";
}
return error;
}
BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate)
{
vector<string> args = {
"kdm_cli",
"--verbose",
"--valid-from", "now",
"--valid-duration", "2 weeks",
"--certificate", "test/data/cert.pem",
"-S", "my great screen",
"-o", "build/test",
"test/data/dkdm.xml"
};
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";
boost::system::error_code ec;
boost::filesystem::remove(kdm_filename, ec);
vector<string> output;
auto error = run(args, output);
BOOST_CHECK (!error);
BOOST_CHECK(boost::filesystem::exists(kdm_filename));
}
static
void
setup_test_config()
{
auto config = Config::instance();
auto const cert = dcp::Certificate(dcp::file_to_string("test/data/cert.pem"));
auto cinema_a = std::make_shared<Cinema>("Dean's Screens", vector<string>(), "");
cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 1", "", cert, boost::none, std::vector<TrustedDevice>()));
cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 2", "", cert, boost::none, std::vector<TrustedDevice>()));
cinema_a->add_screen(std::make_shared<dcpomatic::Screen>("Screen 3", "", cert, boost::none, std::vector<TrustedDevice>()));
config->add_cinema(cinema_a);
auto cinema_b = std::make_shared<Cinema>("Floyd's Celluloid", vector<string>(), "");
cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Foo", "", cert, boost::none, std::vector<TrustedDevice>()));
cinema_b->add_screen(std::make_shared<dcpomatic::Screen>("Bar", "", cert, boost::none, std::vector<TrustedDevice>()));
config->add_cinema(cinema_b);
}
BOOST_AUTO_TEST_CASE(kdm_cli_select_cinema)
{
ConfigRestorer cr;
setup_test_config();
vector<boost::filesystem::path> kdm_filenames = {
"build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Foo.xml",
"build/test/KDM_Test_FTR-1_F-133_XX-XX_MOS_2K_20220109_SMPTE_OV_Floyds_Celluloid_Bar.xml"
};
for (auto path: kdm_filenames) {
boost::system::error_code ec;
boost::filesystem::remove(path, ec);
}
vector<string> args = {
"kdm_cli",
"--verbose",
"--valid-from", "now",
"--valid-duration", "2 weeks",
"-c", "Floyd's Celluloid",
"-o", "build/test",
"test/data/dkdm.xml"
};
vector<string> output;
auto error = run(args, output);
BOOST_CHECK(!error);
BOOST_REQUIRE_EQUAL(output.size(), 2U);
BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
BOOST_CHECK_EQUAL(output[1], "Wrote 2 KDM files to build/test");
for (auto path: kdm_filenames) {
BOOST_CHECK(boost::filesystem::exists(path));
}
}
BOOST_AUTO_TEST_CASE(kdm_cli_select_screen)
{
ConfigRestorer cr;
setup_test_config();
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";
boost::system::error_code ec;
boost::filesystem::remove(kdm_filename, ec);
vector<string> args = {
"kdm_cli",
"--verbose",
"--valid-from", "now",
"--valid-duration", "2 weeks",
"-c", "Dean's Screens",
"-S", "Screen 2",
"-o", "build/test",
"test/data/dkdm.xml"
};
vector<string> output;
auto error = run(args, output);
BOOST_CHECK(!error);
BOOST_REQUIRE_EQUAL(output.size(), 2U);
BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
BOOST_CHECK_EQUAL(output[1], "Wrote 1 KDM files to build/test");
BOOST_CHECK(boost::filesystem::exists(kdm_filename));
}
BOOST_AUTO_TEST_CASE(kdm_cli_specify_cinemas_file)
{
ConfigRestorer cr;
setup_test_config();
vector<string> args = {
"kdm_cli",
"--cinemas-file",
"test/data/cinemas.xml",
"--list-cinemas"
};
vector<string> output;
auto const error = run(args, output);
BOOST_CHECK(!error);
BOOST_REQUIRE_EQUAL(output.size(), 3U);
BOOST_CHECK_EQUAL(output[0], "stinking dump ()");
BOOST_CHECK_EQUAL(output[1], "classy joint ()");
BOOST_CHECK_EQUAL(output[2], "Great ()");
}
BOOST_AUTO_TEST_CASE(kdm_cli_time)
{
ConfigRestorer cr;
setup_test_config();
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";
boost::system::error_code ec;
boost::filesystem::remove(kdm_filename, ec);
dcp::LocalTime now;
now.add_days(2);
vector<string> args = {
"kdm_cli",
"--verbose",
"--valid-from", now.as_string(),
"--valid-duration", "2 weeks",
"-c", "Dean's Screens",
"-S", "Screen 2",
"-o", "build/test",
"test/data/dkdm.xml"
};
vector<string> output;
auto error = run(args, output);
BOOST_CHECK(!error);
BOOST_REQUIRE_EQUAL(output.size(), 2U);
BOOST_CHECK(boost::algorithm::starts_with(output[0], "Making KDMs valid from"));
BOOST_CHECK_EQUAL(output[1], "Wrote 1 KDM files to build/test");
BOOST_CHECK(boost::filesystem::exists(kdm_filename));
}
|