More unit testing. dkdm2
authorCarl Hetherington <cth@carlh.net>
Tue, 5 May 2020 23:07:26 +0000 (01:07 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 5 May 2020 23:07:26 +0000 (01:07 +0200)
test/kdm_naming_test.cc

index d9451a92d31fe57d36b242f82bc5f0ff9f752ba2..d45e4a44e7302c1d5e97e7670a3595bca6b77f48 100644 (file)
@@ -33,6 +33,7 @@ using std::string;
 using std::vector;
 using boost::shared_ptr;
 using boost::optional;
+using boost::dynamic_pointer_cast;
 
 static
 bool
@@ -41,8 +42,13 @@ confirm_overwrite (boost::filesystem::path)
        return true;
 }
 
+static shared_ptr<dcpomatic::Screen> cinema_a_screen_1;
+static shared_ptr<dcpomatic::Screen> cinema_a_screen_2;
+static shared_ptr<dcpomatic::Screen> cinema_b_screen_x;
+static shared_ptr<dcpomatic::Screen> cinema_b_screen_y;
+static shared_ptr<dcpomatic::Screen> cinema_b_screen_z;
 
-BOOST_AUTO_TEST_CASE (single_kdm_name_test)
+BOOST_AUTO_TEST_CASE (single_kdm_naming_test)
 {
        Config* c = Config::instance();
 
@@ -50,25 +56,25 @@ BOOST_AUTO_TEST_CASE (single_kdm_name_test)
 
        /* Cinema A: UTC +4:30 */
        shared_ptr<Cinema> cinema_a (new Cinema("Cinema A", list<string>(), "", 4, 30));
-       shared_ptr<dcpomatic::Screen> cinema_a_screen_1(new dcpomatic::Screen("Screen 1", "", cert, vector<TrustedDevice>()));
+       cinema_a_screen_1.reset(new dcpomatic::Screen("Screen 1", "", cert, vector<TrustedDevice>()));
        cinema_a->add_screen (cinema_a_screen_1);
-       shared_ptr<dcpomatic::Screen> cinema_a_screen_2(new dcpomatic::Screen("Screen 2", "", cert, vector<TrustedDevice>()));
+       cinema_a_screen_2.reset(new dcpomatic::Screen("Screen 2", "", cert, vector<TrustedDevice>()));
        cinema_a->add_screen (cinema_a_screen_2);
        c->add_cinema (cinema_a);
 
        /* Cinema B: UTC -1:00 */
        shared_ptr<Cinema> cinema_b (new Cinema("Cinema B", list<string>(), "", -1, 0));
-       shared_ptr<dcpomatic::Screen> cinema_b_screen_x(new dcpomatic::Screen("Screen X", "", cert, vector<TrustedDevice>()));
+       cinema_b_screen_x.reset(new dcpomatic::Screen("Screen X", "", cert, vector<TrustedDevice>()));
        cinema_b->add_screen (cinema_b_screen_x);
-       shared_ptr<dcpomatic::Screen> cinema_b_screen_y(new dcpomatic::Screen("Screen Y", "", cert, vector<TrustedDevice>()));
+       cinema_b_screen_y.reset(new dcpomatic::Screen("Screen Y", "", cert, vector<TrustedDevice>()));
        cinema_b->add_screen (cinema_b_screen_y);
-       shared_ptr<dcpomatic::Screen> cinema_b_screen_z(new dcpomatic::Screen("Screen Z", "", cert, vector<TrustedDevice>()));
+       cinema_b_screen_z.reset(new dcpomatic::Screen("Screen Z", "", cert, vector<TrustedDevice>()));
        cinema_b->add_screen (cinema_b_screen_z);
        c->add_cinema (cinema_a);
 
        /* Film */
-       boost::filesystem::remove_all ("build/test/single_kdm_name_test");
-       shared_ptr<Film> film = new_test_film2 ("single_kdm_name_test");
+       boost::filesystem::remove_all ("build/test/single_kdm_naming_test");
+       shared_ptr<Film> 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());
        BOOST_REQUIRE (!wait_for_jobs());
@@ -104,7 +110,7 @@ BOOST_AUTO_TEST_CASE (single_kdm_name_test)
 
        write_files (
                kdms,
-               boost::filesystem::path("build/test/single_kdm_name_test"),
+               boost::filesystem::path("build/test/single_kdm_naming_test"),
                dcp::NameFormat("KDM %c - %s - %f - %b - %e"),
                &confirm_overwrite
                );
@@ -115,6 +121,93 @@ BOOST_AUTO_TEST_CASE (single_kdm_name_test)
        boost::algorithm::replace_all (until_time, ":", "-");
 
        string 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);
-       BOOST_CHECK_MESSAGE (boost::filesystem::exists("build/test/single_kdm_name_test/" + ref), "File " << ref << " not found");
+       BOOST_CHECK_MESSAGE (boost::filesystem::exists("build/test/single_kdm_naming_test/" + ref), "File " << ref << " not found");
+}
+
+
+BOOST_AUTO_TEST_CASE (directory_kdm_naming_test, * boost::unit_test::depends_on("single_kdm_naming_test"))
+{
+       using boost::filesystem::path;
+
+       dcp::Certificate cert = Config::instance()->decryption_chain()->leaf();
+
+       /* Film */
+       boost::filesystem::remove_all ("build/test/directory_kdm_naming_test");
+       shared_ptr<Film> film = new_test_film2 ("directory_kdm_naming_test");
+       film->set_name ("my_great_film");
+       film->examine_and_add_content (content_factory("test/data/flat_black.png").front());
+       BOOST_REQUIRE (!wait_for_jobs());
+       film->set_encrypted (true);
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs());
+       film->write_metadata ();
+       vector<CPLSummary> cpls = film->cpls ();
+       BOOST_REQUIRE(cpls.size() == 1);
+
+       dcp::LocalTime from (cert.not_before());
+       from.add_months (2);
+       dcp::LocalTime until (cert.not_after());
+       until.add_months (-2);
+
+       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;
+       screens.push_back (cinema_a_screen_2);
+       screens.push_back (cinema_b_screen_x);
+       screens.push_back (cinema_a_screen_1);
+       screens.push_back (cinema_b_screen_z);
+
+       path const cpl = cpls.front().cpl_file;
+       string const cpl_id = cpls.front().cpl_id;
+
+       list<KDMWithMetadataPtr> kdms;
+       BOOST_FOREACH (shared_ptr<dcpomatic::Screen> i, screens) {
+               KDMWithMetadataPtr kdm = kdm_for_screen (
+                               film,
+                               cpls.front().cpl_file,
+                               i,
+                               boost::posix_time::time_from_string(from_string),
+                               boost::posix_time::time_from_string(until_string),
+                               dcp::MODIFIED_TRANSITIONAL_1,
+                               false,
+                               optional<int>()
+                               );
+
+               kdms.push_back (kdm);
+       }
+
+       write_directories (
+               collect(kdms),
+               path("build/test/directory_kdm_naming_test"),
+               dcp::NameFormat("%c - %s - %f - %b - %e"),
+               dcp::NameFormat("KDM %c - %s - %f - %b - %e - %i"),
+               &confirm_overwrite
+               );
+
+       string from_time = from.time_of_day (true, false);
+       boost::algorithm::replace_all (from_time, ":", "-");
+       string until_time = until.time_of_day (true, false);
+       boost::algorithm::replace_all (until_time, ":", "-");
+
+       path const base = "build/test/directory_kdm_naming_test";
+       list<KDMWithMetadataPtr>::const_iterator i = kdms.begin ();
+
+       path dir_a = String::compose("Cinema_A_-_%s_-_my_great_film_-_%1_%2_-_%3_%4", from.date(), from_time, until.date(), until_time);
+       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);
+       BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b), "Directory " << dir_b << " not found");
+
+       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);
+       BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
+
+       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);
+       BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");
+
+       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);
+       BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_a / ref), "File " << ref << " not found");
+
+       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);
+       BOOST_CHECK_MESSAGE (boost::filesystem::exists(base / dir_b / ref), "File " << ref << " not found");
 }