Cleanup: replace some list with vector.
[dcpomatic.git] / test / kdm_naming_test.cc
index 4e1f81b1c29060110bb7290afd18e8896e4b1136..32500553e90e48065c6786064eaa94f5cf628e94 100644 (file)
@@ -60,20 +60,20 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
        auto crypt_cert = c->decryption_chain()->leaf();
 
        /* Cinema A: UTC +4:30 */
-       auto cinema_a = make_shared<Cinema>("Cinema A", list<string>(), "", 4, 30);
-       cinema_a_screen_1 = make_shared<dcpomatic::Screen>("Screen 1", "", crypt_cert, vector<TrustedDevice>());
+       auto cinema_a = make_shared<Cinema>("Cinema A", vector<string>(), "", 4, 30);
+       cinema_a_screen_1 = std::make_shared<dcpomatic::Screen>("Screen 1", "", crypt_cert, boost::none, vector<TrustedDevice>());
        cinema_a->add_screen (cinema_a_screen_1);
-       cinema_a_screen_2 = make_shared<dcpomatic::Screen>("Screen 2", "", crypt_cert, vector<TrustedDevice>());
+       cinema_a_screen_2 = std::make_shared<dcpomatic::Screen>("Screen 2", "", crypt_cert, boost::none, vector<TrustedDevice>());
        cinema_a->add_screen (cinema_a_screen_2);
        c->add_cinema (cinema_a);
 
        /* Cinema B: UTC -1:00 */
-       auto cinema_b = make_shared<Cinema>("Cinema B", list<string>(), "", -1, 0);
-       cinema_b_screen_x = make_shared<dcpomatic::Screen>("Screen X", "", crypt_cert, vector<TrustedDevice>());
+       auto cinema_b = make_shared<Cinema>("Cinema B", vector<string>(), "", -1, 0);
+       cinema_b_screen_x = std::make_shared<dcpomatic::Screen>("Screen X", "", crypt_cert, boost::none, vector<TrustedDevice>());
        cinema_b->add_screen (cinema_b_screen_x);
-       cinema_b_screen_y = make_shared<dcpomatic::Screen>("Screen Y", "", crypt_cert, vector<TrustedDevice>());
+       cinema_b_screen_y = std::make_shared<dcpomatic::Screen>("Screen Y", "", crypt_cert, boost::none, vector<TrustedDevice>());
        cinema_b->add_screen (cinema_b_screen_y);
-       cinema_b_screen_z = make_shared<dcpomatic::Screen>("Screen Z", "", crypt_cert, vector<TrustedDevice>());
+       cinema_b_screen_z = std::make_shared<dcpomatic::Screen>("Screen Z", "", crypt_cert, boost::none, vector<TrustedDevice>());
        cinema_b->add_screen (cinema_b_screen_z);
        c->add_cinema (cinema_a);
 
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
        boost::filesystem::remove_all ("build/test/single_kdm_naming_test");
        auto film = new_test_film2 ("single_kdm_naming_test");
        film->set_name ("my_great_film");
-       film->examine_and_add_content (content_factory("test/data/flat_black.png").front());
+       film->examine_and_add_content (content_factory("test/data/flat_black.png")[0]);
        BOOST_REQUIRE (!wait_for_jobs());
        film->set_encrypted (true);
        make_and_verify_dcp (film);
@@ -98,16 +98,21 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
        auto const from_string = from.date() + " " + from.time_of_day(true, false);
        auto const until_string = until.date() + " " + until.time_of_day(true, false);
 
+       std::vector<KDMCertificatePeriod> period_checks;
+
        auto cpl = cpls.front().cpl_file;
+       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, cpl](dcp::LocalTime begin, dcp::LocalTime end) {
+               return film->make_kdm(cpl, begin, end);
+       };
        auto kdm = kdm_for_screen (
-                       film,
-                       cpls.front().cpl_file,
+                       make_kdm,
                        cinema_a_screen_1,
                        boost::posix_time::time_from_string(from_string),
                        boost::posix_time::time_from_string(until_string),
                        dcp::Formulation::MODIFIED_TRANSITIONAL_1,
                        false,
-                       optional<int>()
+                       optional<int>(),
+                       period_checks
                        );
 
        write_files (
@@ -122,7 +127,8 @@ BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
        auto until_time = until.time_of_day (true, false);
        boost::algorithm::replace_all (until_time, ":", "-");
 
-       auto const ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
+       auto const dcp_date = boost::gregorian::to_iso_string(film->isdcf_date());
+       auto const ref = String::compose("KDM_Cinema_A_-_Screen_1_-_MyGreatFilm_TST-1_F_XX-XX_MOS_2K_%1_SMPTE_OV_-_%2_%3_-_%4_%5.xml", dcp_date, from.date(), from_time, until.date(), until_time);
        BOOST_CHECK_MESSAGE (boost::filesystem::exists("build/test/single_kdm_naming_test/" + ref), "File " << ref << " not found");
 }
 
@@ -135,7 +141,7 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on(
        boost::filesystem::remove_all ("build/test/directory_kdm_naming_test");
        auto film = new_test_film2 (
                "directory_kdm_naming_test",
-               { content_factory("test/data/flat_black.png").front() }
+               { content_factory("test/data/flat_black.png")[0] }
                );
 
        film->set_name ("my_great_film");
@@ -154,24 +160,30 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on(
        string const from_string = from.date() + " " + from.time_of_day(true, false);
        string const until_string = until.date() + " " + until.time_of_day(true, false);
 
-       list<shared_ptr<dcpomatic::Screen>> screens = {
+       vector<shared_ptr<dcpomatic::Screen>> screens = {
                cinema_a_screen_2, cinema_b_screen_x, cinema_a_screen_1, (cinema_b_screen_z)
        };
 
        auto const cpl = cpls.front().cpl_file;
        auto const cpl_id = cpls.front().cpl_id;
 
+       std::vector<KDMCertificatePeriod> period_checks;
        list<KDMWithMetadataPtr> kdms;
+
+       std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, cpls](dcp::LocalTime begin, dcp::LocalTime end) {
+               return film->make_kdm(cpls.front().cpl_file, begin, end);
+       };
+
        for (auto i: screens) {
                auto kdm = kdm_for_screen (
-                               film,
-                               cpls.front().cpl_file,
+                               make_kdm,
                                i,
                                boost::posix_time::time_from_string(from_string),
                                boost::posix_time::time_from_string(until_string),
                                dcp::Formulation::MODIFIED_TRANSITIONAL_1,
                                false,
-                               optional<int>()
+                               optional<int>(),
+                               period_checks
                                );
 
                kdms.push_back (kdm);
@@ -182,8 +194,8 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on(
                path("build/test/directory_kdm_naming_test"),
                dcp::NameFormat("%c - %s - %f - %b - %e"),
 #ifdef DCPOMATIC_WINDOWS
-               /* With %i in the format the path is too long for Windows */
-               dcp::NameFormat("KDM %c - %s - %f - %b - %e"),
+               /* Use a shorter name on Windows so that the paths aren't too long */
+               dcp::NameFormat("KDM %f"),
 #else
                dcp::NameFormat("KDM %c - %s - %f - %b - %e - %i"),
 #endif
@@ -195,38 +207,42 @@ BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on(
        auto until_time = until.time_of_day (true, false);
        boost::algorithm::replace_all (until_time, ":", "-");
 
+       auto const dcp_date = boost::gregorian::to_iso_string(film->isdcf_date());
+       auto const dcp_name = String::compose("MyGreatFilm_TST-1_F_XX-XX_MOS_2K_%1_SMPTE_OV", dcp_date);
+       auto const common = String::compose("%1_-_%2_%3_-_%4_%5", dcp_name, from.date(), from_time, until.date(), until_time);
+
        path const base = "build/test/directory_kdm_naming_test";
 
-       path dir_a = String::compose("Cinema_A_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
+       path dir_a = String::compose("Cinema_A_-_%s_-_%1", common);
        BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a), "Directory " << dir_a << " not found");
-       path dir_b = String::compose("Cinema_B_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
+       path dir_b = String::compose("Cinema_B_-_%s_-_%1", common);
        BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b), "Directory " << dir_b << " not found");
 
 #ifdef DCPOMATIC_WINDOWS
-       path ref = String::compose("KDM_Cinema_A_-_Screen_2_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
+       path ref = String::compose("KDM_%1.xml", dcp_name);
 #else
-       path ref = String::compose("KDM_Cinema_A_-_Screen_2_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
+       path ref = String::compose("KDM_Cinema_A_-_Screen_2_-_%1_-_%2.xml", common, cpl_id);
 #endif
        BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
 
 #ifdef DCPOMATIC_WINDOWS
-       ref = String::compose("KDM_Cinema_B_-_Screen_X_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
+       ref = String::compose("KDM_%1.xml", dcp_name);
 #else
-       ref = String::compose("KDM_Cinema_B_-_Screen_X_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
+       ref = String::compose("KDM_Cinema_B_-_Screen_X_-_%1_-_%2.xml", common, cpl_id);
 #endif
        BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");
 
 #ifdef DCPOMATIC_WINDOWS
-       ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
+       ref = String::compose("KDM_%1.xml", dcp_name);
 #else
-       ref = String::compose("KDM_Cinema_A_-_Screen_1_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
+       ref = String::compose("KDM_Cinema_A_-_Screen_1_-_%1_-_%2.xml", common, cpl_id);
 #endif
        BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
 
 #ifdef DCPOMATIC_WINDOWS
-       ref = String::compose("KDM_Cinema_B_-_Screen_Z_-_my_great_film_-_%1_%2_-_%3_%4.xml", from.date(), from_time, until.date(), until_time);
+       ref = String::compose("KDM_%1.xml", dcp_name);
 #else
-       ref = String::compose("KDM_Cinema_B_-_Screen_Z_-_my_great_film_-_%1_%2_-_%3_%4_-_%5.xml", from.date(), from_time, until.date(), until_time, cpl_id);
+       ref = String::compose("KDM_Cinema_B_-_Screen_Z_-_%1_-_%2.xml", common, cpl_id);
 #endif
        BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");
 }