Fix errors when mapping DCPs referring to the same asset multiple times (#2542).
[dcpomatic.git] / test / map_cli_test.cc
index 3e6abc059cd9b93f031cce5fabdfaaddecd19200..387e04c8cb775ea4f53f62635f504e616673eae4 100644 (file)
@@ -209,8 +209,9 @@ BOOST_AUTO_TEST_CASE(map_simple_interop_dcp_with_subs)
 }
 
 
-/** Map an OV and a VF into a single DCP */
-BOOST_AUTO_TEST_CASE(map_ov_vf_copy)
+static
+void
+test_map_ov_vf_copy(vector<string> extra_args = {})
 {
        string const name = "map_ov_vf_copy";
        string const out = String::compose("build/test/%1_out", name);
@@ -229,7 +230,7 @@ BOOST_AUTO_TEST_CASE(map_ov_vf_copy)
 
        auto const vf_dir = vf_film->dir(vf_film->dcp_name());
 
-       vector<string> const args = {
+       vector<string> args = {
                "map_cli",
                "-o", out,
                "-d", ov_dir.string(),
@@ -237,6 +238,8 @@ BOOST_AUTO_TEST_CASE(map_ov_vf_copy)
                find_cpl(vf_dir).string()
        };
 
+       args.insert(std::end(args), std::begin(extra_args), std::end(extra_args));
+
        boost::filesystem::remove_all(out);
 
        vector<string> output_messages;
@@ -251,6 +254,60 @@ BOOST_AUTO_TEST_CASE(map_ov_vf_copy)
 }
 
 
+/** Map an OV and a VF into a single DCP */
+BOOST_AUTO_TEST_CASE(map_ov_vf_copy)
+{
+       test_map_ov_vf_copy();
+       test_map_ov_vf_copy({"-l"});
+}
+
+
+/** Map an OV and VF into a single DCP, where the VF refers to the OV's assets multiple times */
+BOOST_AUTO_TEST_CASE(map_ov_vf_copy_multiple_reference)
+{
+       string const name = "map_ov_vf_copy_multiple_reference";
+       string const out = String::compose("build/test/%1_out", name);
+
+       auto ov_content = content_factory("test/data/flat_red.png");
+       auto ov_film = new_test_film2(name + "_ov", ov_content);
+       make_and_verify_dcp(ov_film);
+
+       auto const ov_dir = ov_film->dir(ov_film->dcp_name());
+
+       auto vf_ov1 = make_shared<DCPContent>(ov_dir);
+       auto vf_ov2 = make_shared<DCPContent>(ov_dir);
+       auto vf_sound = content_factory("test/data/sine_440.wav").front();
+       auto vf_film = new_test_film2(name + "_vf", { vf_ov1, vf_ov2, vf_sound });
+       vf_film->set_reel_type(ReelType::BY_VIDEO_CONTENT);
+       vf_ov2->set_position(vf_film, vf_ov1->end(vf_film));
+       vf_ov1->set_reference_video(true);
+       vf_ov2->set_reference_video(true);
+       make_and_verify_dcp(vf_film, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
+
+       auto const vf_dir = vf_film->dir(vf_film->dcp_name());
+
+       vector<string> const args = {
+               "map_cli",
+               "-o", out,
+               "-d", ov_dir.string(),
+               "-d", vf_dir.string(),
+               "-l",
+               find_cpl(vf_dir).string()
+       };
+
+       boost::filesystem::remove_all(out);
+
+       vector<string> output_messages;
+       auto error = run(args, output_messages);
+       BOOST_CHECK(!error);
+
+       verify_dcp(out, {});
+
+       check_file(find_file(out, "cpl_"), find_file(vf_dir, "cpl_"));
+       check_file(find_file(out, "j2c_"), find_file(ov_dir, "j2c_"));
+}
+
+
 /** Map a single DCP into a new DCP using the rename option */
 BOOST_AUTO_TEST_CASE(map_simple_dcp_copy_with_rename)
 {
@@ -353,3 +410,32 @@ BOOST_AUTO_TEST_CASE(map_two_smpte_cpls_each_with_subs)
 {
        test_two_cpls_each_with_subs("map_two_smpte_cpls_each_with_subs", false);
 }
+
+
+BOOST_AUTO_TEST_CASE(map_with_given_config)
+{
+       string const name = "map_with_given_config";
+       string const out = String::compose("build/test/%1_out", name);
+
+       auto content = content_factory("test/data/flat_red.png");
+       auto film = new_test_film2(name + "_in", content);
+       make_and_verify_dcp(film);
+
+       vector<string> const args = {
+               "map_cli",
+               "-o", out,
+               "-d", film->dir(film->dcp_name()).string(),
+               "--config", "test/data/map_with_given_config",
+               find_cpl(film->dir(film->dcp_name())).string()
+       };
+
+       boost::filesystem::remove_all(out);
+
+       Config::instance()->drop();
+       vector<string> output_messages;
+       auto error = run(args, output_messages);
+       BOOST_CHECK(!error);
+
+       /* It should be signed by the key in test/data/map_with_given_config, not the one in test/data/signer_key */
+       BOOST_CHECK(dcp::file_to_string(find_file(out, "cpl_")).find("dnQualifier=\\+uOcNN2lPuxpxgd/5vNkkBER0GE=,CN=CS.dcpomatic.smpte-430-2.LEAF,OU=dcpomatic.com,O=dcpomatic.com") != std::string::npos);
+}