optional<string> cinema_name;
shared_ptr<Cinema> cinema;
optional<boost::filesystem::path> certificate;
- string screen;
+ optional<string> screen;
list<shared_ptr<Screen>> screens;
optional<dcp::EncryptedKDM> dkdm;
optional<boost::posix_time::ptime> valid_from;
program_name = argv[0];
+ /* Reset getopt() so we can call this method several times in one test process */
+ optind = 1;
+
int option_index = 0;
while (true) {
static struct option long_options[] = {
cinema = make_shared<Cinema>(optarg, list<string>(), "", 0, 0);
break;
case 'S':
+ /* Similarly, this could be the name of a new (temporary) screen or the name of a screen
+ * to search for.
+ */
screen = optarg;
break;
case 'C':
if (certificate) {
/* Make a new screen and add it to the current cinema */
dcp::CertificateChain chain(dcp::file_to_string(*certificate));
- auto screen_to_add = std::make_shared<Screen>(screen, "", chain.leaf(), boost::none, vector<TrustedDevice>());
+ auto screen_to_add = std::make_shared<Screen>(screen.get_value_or(""), "", chain.leaf(), boost::none, vector<TrustedDevice>());
if (cinema) {
cinema->add_screen(screen_to_add);
}
}
screens = find_cinema (*cinema_name)->screens ();
+ if (screen) {
+ screens.erase(std::remove_if(screens.begin(), screens.end(), [&screen](shared_ptr<Screen> s) { return s->name != *screen; }), screens.end());
+ }
}
if (duration_string) {
*/
+#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/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
+using std::list;
using std::string;
using std::vector;
+using boost::optional;
+
+
optional<string>
run(vector<string> const& args, vector<string>& 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", list<string>(), "", 0, 0);
+ 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", list<string>(), "", 0, 0);
+ 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(), 2);
+ 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(), 2);
+ 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));
+}
+
+