Bv2.1 6.2.1: Check that subtitle XML <Language> conforms to RFC 5646.
[libdcp.git] / test / verify_test.cc
index 47828ca58ae9f0e6648393ce7a44b781a2758021..62b5c6c49e406917be26b0d9a9676cf084b4c41e 100644 (file)
@@ -58,7 +58,7 @@ using std::string;
 using std::vector;
 using std::make_pair;
 using boost::optional;
-using boost::shared_ptr;
+using std::shared_ptr;
 
 
 static list<pair<string, optional<boost::filesystem::path> > > stages;
@@ -75,11 +75,19 @@ progress (float)
 
 }
 
+static void
+prepare_directory (boost::filesystem::path path)
+{
+       using namespace boost::filesystem;
+       remove_all (path);
+       create_directories (path);
+}
+
+
 static vector<boost::filesystem::path>
 setup (int reference_number, int verify_test_number)
 {
-       boost::filesystem::remove_all (dcp::String::compose("build/test/verify_test%1", verify_test_number));
-       boost::filesystem::create_directory (dcp::String::compose("build/test/verify_test%1", verify_test_number));
+       prepare_directory (dcp::String::compose("build/test/verify_test%1", verify_test_number));
        for (boost::filesystem::directory_iterator i(dcp::String::compose("test/ref/DCP/dcp_test%1", reference_number)); i != boost::filesystem::directory_iterator(); ++i) {
                boost::filesystem::copy_file (i->path(), dcp::String::compose("build/test/verify_test%1", verify_test_number) / i->path().filename());
        }
@@ -141,7 +149,7 @@ BOOST_AUTO_TEST_CASE (verify_test1)
        list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress, xsd_test);
 
        boost::filesystem::path const cpl_file = "build/test/verify_test1/cpl_81fb54df-e1bf-4647-8788-ea7ba154375b.xml";
-       boost::filesystem::path const pkl_file = "build/test/verify_test1/pkl_18be072e-5a0f-44e1-b2eb-c8a52ae12789.xml";
+       boost::filesystem::path const pkl_file = "build/test/verify_test1/pkl_cd49971e-bf4c-4594-8474-54ebef09a40c.xml";
        boost::filesystem::path const assetmap_file = "build/test/verify_test1/ASSETMAP.xml";
 
        list<pair<string, optional<boost::filesystem::path> > >::const_iterator st = stages.begin();
@@ -195,7 +203,7 @@ BOOST_AUTO_TEST_CASE (verify_test2)
 
        mod = fopen("build/test/verify_test2/audio.mxf", "r+b");
        BOOST_REQUIRE (mod);
-       fseek (mod, 4096, SEEK_SET);
+       BOOST_REQUIRE_EQUAL (fseek(mod, -64, SEEK_END), 0);
        BOOST_REQUIRE (fwrite (&x, sizeof(x), 1, mod) == 1);
        fclose (mod);
 
@@ -218,7 +226,7 @@ BOOST_AUTO_TEST_CASE (verify_test3)
        vector<boost::filesystem::path> directories = setup (1, 3);
 
        {
-               Editor e ("build/test/verify_test3/pkl_18be072e-5a0f-44e1-b2eb-c8a52ae12789.xml");
+               Editor e ("build/test/verify_test3/pkl_cd49971e-bf4c-4594-8474-54ebef09a40c.xml");
                e.replace ("<Hash>", "<Hash>x");
        }
 
@@ -274,7 +282,7 @@ static
 boost::filesystem::path
 pkl (int n)
 {
-       return dcp::String::compose("build/test/verify_test%1/pkl_18be072e-5a0f-44e1-b2eb-c8a52ae12789.xml", n);
+       return dcp::String::compose("build/test/verify_test%1/pkl_cd49971e-bf4c-4594-8474-54ebef09a40c.xml", n);
 }
 
 static
@@ -425,7 +433,7 @@ BOOST_AUTO_TEST_CASE (verify_test11)
 {
        check_after_replace (
                11, &pkl,
-               "<Id>urn:uuid:18b", "<Id>urn:uuid:x8b",
+               "<Id>urn:uuid:cd4", "<Id>urn:uuid:xd4",
                dcp::VerificationNote::XML_VALIDATION_ERROR
                );
 }
@@ -435,7 +443,7 @@ BOOST_AUTO_TEST_CASE (verify_test12)
 {
        check_after_replace (
                12, &asset_map,
-               "<Id>urn:uuid:ae8", "<Id>urn:uuid:xe8",
+               "<Id>urn:uuid:63c", "<Id>urn:uuid:x3c",
                dcp::VerificationNote::XML_VALIDATION_ERROR
                );
 }
@@ -485,7 +493,10 @@ BOOST_AUTO_TEST_CASE (verify_test13)
        ++st;
        BOOST_REQUIRE (st == stages.end());
 
-       BOOST_CHECK_EQUAL (notes.size(), 0);
+       BOOST_REQUIRE_EQUAL (notes.size(), 1U);
+       list<dcp::VerificationNote>::const_iterator i = notes.begin ();
+       BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_BV21_ERROR);
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::NOT_SMPTE);
 }
 
 /* DCP with a short asset */
@@ -494,8 +505,10 @@ BOOST_AUTO_TEST_CASE (verify_test14)
        vector<boost::filesystem::path> directories = setup (8, 14);
        list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress, xsd_test);
 
-       BOOST_REQUIRE_EQUAL (notes.size(), 4);
+       BOOST_REQUIRE_EQUAL (notes.size(), 5);
        list<dcp::VerificationNote>::const_iterator i = notes.begin ();
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::NOT_SMPTE);
+       ++i;
        BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::DURATION_TOO_SMALL);
        ++i;
        BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::INTRINSIC_DURATION_TOO_SMALL);
@@ -509,13 +522,13 @@ BOOST_AUTO_TEST_CASE (verify_test14)
 
 static
 void
-dcp_from_frame (dcp::Data const& frame, boost::filesystem::path dir)
+dcp_from_frame (dcp::ArrayData const& frame, boost::filesystem::path dir)
 {
        shared_ptr<dcp::MonoPictureAsset> asset(new dcp::MonoPictureAsset(dcp::Fraction(24, 1), dcp::SMPTE));
        boost::filesystem::create_directories (dir);
        shared_ptr<dcp::PictureAssetWriter> writer = asset->start_write (dir / "pic.mxf", true);
        for (int i = 0; i < 24; ++i) {
-               writer->write (frame.data().get(), frame.size());
+               writer->write (frame.data(), frame.size());
        }
        writer->finalize ();
 
@@ -537,13 +550,13 @@ BOOST_AUTO_TEST_CASE (verify_test15)
 
        /* Compress a black image */
        shared_ptr<dcp::OpenJPEGImage> image = black_image ();
-       dcp::Data frame = dcp::compress_j2k (image, 100000000, 24, false, false);
+       dcp::ArrayData frame = dcp::compress_j2k (image, 100000000, 24, false, false);
        BOOST_REQUIRE (frame.size() < too_big);
 
        /* Place it in a bigger block with some zero padding at the end */
-       dcp::Data oversized_frame(too_big);
-       memcpy (oversized_frame.data().get(), frame.data().get(), frame.size());
-       memset (oversized_frame.data().get() + frame.size(), 0, too_big - frame.size());
+       dcp::ArrayData oversized_frame(too_big);
+       memcpy (oversized_frame.data(), frame.data(), frame.size());
+       memset (oversized_frame.data() + frame.size(), 0, too_big - frame.size());
 
        boost::filesystem::path const dir("build/test/verify_test15");
        boost::filesystem::remove_all (dir);
@@ -564,13 +577,13 @@ BOOST_AUTO_TEST_CASE (verify_test16)
 
        /* Compress a black image */
        shared_ptr<dcp::OpenJPEGImage> image = black_image ();
-       dcp::Data frame = dcp::compress_j2k (image, 100000000, 24, false, false);
+       dcp::ArrayData frame = dcp::compress_j2k (image, 100000000, 24, false, false);
        BOOST_REQUIRE (frame.size() < nearly_too_big);
 
        /* Place it in a bigger block with some zero padding at the end */
-       dcp::Data oversized_frame(nearly_too_big);
-       memcpy (oversized_frame.data().get(), frame.data().get(), frame.size());
-       memset (oversized_frame.data().get() + frame.size(), 0, nearly_too_big - frame.size());
+       dcp::ArrayData oversized_frame(nearly_too_big);
+       memcpy (oversized_frame.data(), frame.data(), frame.size());
+       memset (oversized_frame.data() + frame.size(), 0, nearly_too_big - frame.size());
 
        boost::filesystem::path const dir("build/test/verify_test16");
        boost::filesystem::remove_all (dir);
@@ -589,7 +602,7 @@ BOOST_AUTO_TEST_CASE (verify_test17)
 {
        /* Compress a black image */
        shared_ptr<dcp::OpenJPEGImage> image = black_image ();
-       dcp::Data frame = dcp::compress_j2k (image, 100000000, 24, false, false);
+       dcp::ArrayData frame = dcp::compress_j2k (image, 100000000, 24, false, false);
        BOOST_REQUIRE (frame.size() < 230000000 / (24 * 8));
 
        boost::filesystem::path const dir("build/test/verify_test17");
@@ -607,8 +620,7 @@ BOOST_AUTO_TEST_CASE (verify_test17)
 BOOST_AUTO_TEST_CASE (verify_test18)
 {
        boost::filesystem::path const dir("build/test/verify_test18");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
        boost::filesystem::copy_file ("test/data/subs1.xml", dir / "subs.xml");
        shared_ptr<dcp::InteropSubtitleAsset> asset(new dcp::InteropSubtitleAsset(dir / "subs.xml"));
        shared_ptr<dcp::ReelAsset> reel_asset(new dcp::ReelSubtitleAsset(asset, dcp::Fraction(24, 1), 16 * 24, 0));
@@ -623,7 +635,9 @@ BOOST_AUTO_TEST_CASE (verify_test18)
        vector<boost::filesystem::path> dirs;
        dirs.push_back (dir);
        list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, xsd_test);
-       BOOST_REQUIRE_EQUAL (notes.size(), 0);
+       BOOST_REQUIRE_EQUAL (notes.size(), 1U);
+       list<dcp::VerificationNote>::const_iterator i = notes.begin ();
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::NOT_SMPTE);
 }
 
 
@@ -631,8 +645,7 @@ BOOST_AUTO_TEST_CASE (verify_test18)
 BOOST_AUTO_TEST_CASE (verify_test19)
 {
        boost::filesystem::path const dir("build/test/verify_test19");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
        boost::filesystem::copy_file ("test/data/subs1.xml", dir / "subs.xml");
        shared_ptr<dcp::InteropSubtitleAsset> asset(new dcp::InteropSubtitleAsset(dir / "subs.xml"));
        shared_ptr<dcp::ReelAsset> reel_asset(new dcp::ReelSubtitleAsset(asset, dcp::Fraction(24, 1), 16 * 24, 0));
@@ -652,9 +665,14 @@ BOOST_AUTO_TEST_CASE (verify_test19)
        vector<boost::filesystem::path> dirs;
        dirs.push_back (dir);
        list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, xsd_test);
-       BOOST_REQUIRE_EQUAL (notes.size(), 2);
-       BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::XML_VALIDATION_ERROR);
-       BOOST_CHECK_EQUAL (notes.back().code(), dcp::VerificationNote::XML_VALIDATION_ERROR);
+       BOOST_REQUIRE_EQUAL (notes.size(), 3);
+       list<dcp::VerificationNote>::const_iterator i = notes.begin ();
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::NOT_SMPTE);
+       ++i;
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::XML_VALIDATION_ERROR);
+       ++i;
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::XML_VALIDATION_ERROR);
+       ++i;
 }
 
 
@@ -662,8 +680,7 @@ BOOST_AUTO_TEST_CASE (verify_test19)
 BOOST_AUTO_TEST_CASE (verify_test20)
 {
        boost::filesystem::path const dir("build/test/verify_test20");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
        boost::filesystem::copy_file ("test/data/subs.mxf", dir / "subs.mxf");
        shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset(dir / "subs.mxf"));
        shared_ptr<dcp::ReelAsset> reel_asset(new dcp::ReelSubtitleAsset(asset, dcp::Fraction(24, 1), 16 * 24, 0));
@@ -686,8 +703,7 @@ BOOST_AUTO_TEST_CASE (verify_test20)
 BOOST_AUTO_TEST_CASE (verify_test21)
 {
        boost::filesystem::path const dir("build/test/verify_test21");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
        boost::filesystem::copy_file ("test/data/broken_smpte.mxf", dir / "subs.mxf");
        shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset(dir / "subs.mxf"));
        shared_ptr<dcp::ReelAsset> reel_asset(new dcp::ReelSubtitleAsset(asset, dcp::Fraction(24, 1), 16 * 24, 0));
@@ -712,11 +728,10 @@ BOOST_AUTO_TEST_CASE (verify_test21)
 BOOST_AUTO_TEST_CASE (verify_test22)
 {
        boost::filesystem::path const ov_dir("build/test/verify_test22_ov");
-       boost::filesystem::remove_all (ov_dir);
-       boost::filesystem::create_directories (ov_dir);
+       prepare_directory (ov_dir);
 
        shared_ptr<dcp::OpenJPEGImage> image = black_image ();
-       dcp::Data frame = dcp::compress_j2k (image, 100000000, 24, false, false);
+       dcp::ArrayData frame = dcp::compress_j2k (image, 100000000, 24, false, false);
        BOOST_REQUIRE (frame.size() < 230000000 / (24 * 8));
        dcp_from_frame (frame, ov_dir);
 
@@ -724,8 +739,7 @@ BOOST_AUTO_TEST_CASE (verify_test22)
        ov.read ();
 
        boost::filesystem::path const vf_dir("build/test/verify_test22_vf");
-       boost::filesystem::remove_all (vf_dir);
-       boost::filesystem::create_directories (vf_dir);
+       prepare_directory (vf_dir);
 
        shared_ptr<dcp::Reel> reel(new dcp::Reel());
        reel->add (ov.cpls().front()->reels().front()->main_picture());
@@ -747,8 +761,7 @@ BOOST_AUTO_TEST_CASE (verify_test22)
 BOOST_AUTO_TEST_CASE (verify_test23)
 {
        boost::filesystem::path const dir("build/test/verify_test23");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
 
        boost::filesystem::copy_file ("test/data/subs.mxf", dir / "subs.mxf");
        shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset(dir / "subs.mxf"));
@@ -790,8 +803,7 @@ boost::filesystem::path find_cpl (boost::filesystem::path dir)
 BOOST_AUTO_TEST_CASE (verify_test24)
 {
        boost::filesystem::path const dir("build/test/verify_test24");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
 
        shared_ptr<dcp::Reel> reel(new dcp::Reel());
        reel->add (black_picture_asset(dir));
@@ -832,8 +844,7 @@ BOOST_AUTO_TEST_CASE (verify_test24)
 BOOST_AUTO_TEST_CASE (verify_test25)
 {
        boost::filesystem::path const dir("build/test/verify_test25");
-       boost::filesystem::remove_all (dir);
-       boost::filesystem::create_directories (dir);
+       prepare_directory (dir);
 
        boost::filesystem::copy_file ("test/data/subs.mxf", dir / "subs.mxf");
        shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset(dir / "subs.mxf"));
@@ -862,3 +873,37 @@ BOOST_AUTO_TEST_CASE (verify_test25)
        list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, xsd_test);
 }
 
+
+/* SMPTE DCP with invalid <Language> in the MainSubtitle reel and also in the XML within the MXF */
+BOOST_AUTO_TEST_CASE (verify_test26)
+{
+       boost::filesystem::path const dir("build/test/verify_test26");
+       prepare_directory (dir);
+       boost::filesystem::copy_file ("test/data/subs.mxf", dir / "subs.mxf");
+       shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset(dir / "subs.mxf"));
+       asset->_language = "wrong-andbad";
+       asset->write (dir / "subs.mxf");
+       shared_ptr<dcp::ReelSubtitleAsset> reel_asset(new dcp::ReelSubtitleAsset(asset, dcp::Fraction(24, 1), 16 * 24, 0));
+       reel_asset->_language = "badlang";
+       shared_ptr<dcp::Reel> reel(new dcp::Reel());
+       reel->add (reel_asset);
+       shared_ptr<dcp::CPL> cpl(new dcp::CPL("hello", dcp::FEATURE));
+       cpl->add (reel);
+       shared_ptr<dcp::DCP> dcp(new dcp::DCP(dir));
+       dcp->add (cpl);
+       dcp->write_xml (dcp::SMPTE);
+
+       vector<boost::filesystem::path> dirs;
+       dirs.push_back (dir);
+       list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, xsd_test);
+       BOOST_REQUIRE_EQUAL (notes.size(), 2U);
+       list<dcp::VerificationNote>::const_iterator i = notes.begin ();
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::BAD_LANGUAGE);
+       BOOST_REQUIRE (i->note());
+       BOOST_CHECK_EQUAL (*i->note(), "badlang");
+       i++;
+       BOOST_CHECK_EQUAL (i->code(), dcp::VerificationNote::BAD_LANGUAGE);
+       BOOST_REQUIRE (i->note());
+       BOOST_CHECK_EQUAL (*i->note(), "wrong-andbad");
+}
+