diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-09-09 01:48:52 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-09-09 01:54:38 +0200 |
| commit | 3e1f008d416a5d0493b799599e1e6ee29785d754 (patch) | |
| tree | 8c631fe933f9e4e75be5bc1448b1ab8bd1bd9bd3 | |
| parent | b1d0ce202bac3fedbc5c77e879cbfd253befbf8a (diff) | |
Make -S parameter to dcpomatic2_kdm_cli also filter screens (#2324).
| -rw-r--r-- | src/lib/kdm_cli.cc | 13 | ||||
| -rw-r--r-- | test/kdm_cli_test.cc | 103 |
2 files changed, 114 insertions, 2 deletions
diff --git a/src/lib/kdm_cli.cc b/src/lib/kdm_cli.cc index 56977b521..79e65f9de 100644 --- a/src/lib/kdm_cli.cc +++ b/src/lib/kdm_cli.cc @@ -423,7 +423,7 @@ try 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; @@ -440,6 +440,9 @@ try 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[] = { @@ -535,6 +538,9 @@ try 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': @@ -558,7 +564,7 @@ try 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); } @@ -596,6 +602,9 @@ try } 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) { diff --git a/test/kdm_cli_test.cc b/test/kdm_cli_test.cc index 52b031623..107a6210a 100644 --- a/test/kdm_cli_test.cc +++ b/test/kdm_cli_test.cc @@ -19,14 +19,23 @@ */ +#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) { @@ -66,6 +75,100 @@ BOOST_AUTO_TEST_CASE (kdm_cli_test_certificate) 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)); +} + + |
