Add check for empty <LabelText> in <ContentVersion>
[libdcp.git] / test / verify_test.cc
index 310c1f81c5de9037d5a4b2221b854dc70d225b91..4138138f11d215d8517cfe3f8f24320da9ad7a0f 100644 (file)
@@ -153,135 +153,6 @@ write_dcp_with_single_asset (path dir, shared_ptr<dcp::ReelAsset> reel_asset, dc
 }
 
 
-/** Class that can alter a file by searching and replacing strings within it.
- *  On destruction modifies the file whose name was given to the constructor.
- */
-class Editor
-{
-public:
-       Editor (path path)
-               : _path(path)
-       {
-               _content = dcp::file_to_string (_path);
-       }
-
-       ~Editor ()
-       {
-               auto f = fopen(_path.string().c_str(), "w");
-               BOOST_REQUIRE (f);
-               fwrite (_content.c_str(), _content.length(), 1, f);
-               fclose (f);
-       }
-
-       class ChangeChecker
-       {
-       public:
-               ChangeChecker(Editor* editor)
-                       : _editor(editor)
-               {
-                       _old_content = _editor->_content;
-               }
-
-               ~ChangeChecker()
-               {
-                       BOOST_REQUIRE(_old_content != _editor->_content);
-               }
-       private:
-               Editor* _editor;
-               std::string _old_content;
-       };
-
-       void replace (string a, string b)
-       {
-               ChangeChecker cc(this);
-               boost::algorithm::replace_all (_content, a, b);
-       }
-
-       void delete_first_line_containing (string s)
-       {
-               ChangeChecker cc(this);
-               auto lines = as_lines();
-               _content = "";
-               bool done = false;
-               for (auto i: lines) {
-                       if (i.find(s) == string::npos || done) {
-                               _content += i + "\n";
-                       } else {
-                               done = true;
-                       }
-               }
-       }
-
-       void delete_lines (string from, string to)
-       {
-               ChangeChecker cc(this);
-               auto lines = as_lines();
-               bool deleting = false;
-               _content = "";
-               for (auto i: lines) {
-                       if (i.find(from) != string::npos) {
-                               deleting = true;
-                       }
-                       if (!deleting) {
-                               _content += i + "\n";
-                       }
-                       if (deleting && i.find(to) != string::npos) {
-                               deleting = false;
-                       }
-               }
-       }
-
-       void insert (string after, string line)
-       {
-               ChangeChecker cc(this);
-               auto lines = as_lines();
-               _content = "";
-               bool replaced = false;
-               for (auto i: lines) {
-                       _content += i + "\n";
-                       if (!replaced && i.find(after) != string::npos) {
-                               _content += line + "\n";
-                               replaced = true;
-                       }
-               }
-       }
-
-       void delete_lines_after(string after, int lines_to_delete)
-       {
-               ChangeChecker cc(this);
-               auto lines = as_lines();
-               _content = "";
-               auto iter = std::find_if(lines.begin(), lines.end(), [after](string const& line) {
-                       return line.find(after) != string::npos;
-               });
-               int to_delete = 0;
-               for (auto i = lines.begin(); i != lines.end(); ++i) {
-                       if (i == iter) {
-                               to_delete = lines_to_delete;
-                               _content += *i + "\n";
-                       } else if (to_delete == 0) {
-                               _content += *i + "\n";
-                       } else {
-                               --to_delete;
-                       }
-               }
-       }
-
-private:
-       friend class ChangeChecker;
-
-       vector<string> as_lines() const
-       {
-               vector<string> lines;
-               boost::algorithm::split(lines, _content, boost::is_any_of("\r\n"), boost::token_compress_on);
-               return lines;
-       }
-
-       path _path;
-       std::string _content;
-};
-
-
 LIBDCP_DISABLE_WARNINGS
 static
 void
@@ -670,6 +541,12 @@ BOOST_AUTO_TEST_CASE (verify_invalid_standard)
 BOOST_AUTO_TEST_CASE (verify_invalid_duration)
 {
        auto dir = setup (8, "invalid_duration");
+
+       dcp::DCP dcp(dir);
+       dcp.read();
+       BOOST_REQUIRE(dcp.cpls().size() == 1);
+       auto cpl = dcp.cpls()[0];
+
        check_verify_result (
                { dir },
                {
@@ -678,7 +555,12 @@ BOOST_AUTO_TEST_CASE (verify_invalid_duration)
                        { dcp::VerificationNote::Type::ERROR, dcp::VerificationNote::Code::INVALID_INTRINSIC_DURATION, string("d7576dcb-a361-4139-96b8-267f5f8d7f91") },
                        { dcp::VerificationNote::Type::ERROR, dcp::VerificationNote::Code::INVALID_DURATION, string("a2a87f5d-b749-4a7e-8d0c-9d48a4abf626") },
                        { dcp::VerificationNote::Type::ERROR, dcp::VerificationNote::Code::INVALID_INTRINSIC_DURATION, string("a2a87f5d-b749-4a7e-8d0c-9d48a4abf626") },
-                       { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_JPEG2000_GUARD_BITS_FOR_2K, string("2") }
+                       { dcp::VerificationNote::Type::BV21_ERROR, dcp::VerificationNote::Code::INVALID_JPEG2000_GUARD_BITS_FOR_2K, string("2") },
+                       dcp::VerificationNote(
+                               dcp::VerificationNote::Type::WARNING,
+                               dcp::VerificationNote::Code::EMPTY_CONTENT_VERSION_LABEL_TEXT,
+                               cpl->file().get()
+                       ).set_id("d74fda30-d5f4-4c5f-870f-ebc089d97eb7")
                });
 }
 
@@ -2363,8 +2245,8 @@ verify_subtitles_must_be_in_all_reels_check (path dir, bool add_to_reel1, bool a
        auto reel_subs = make_shared<dcp::ReelSMPTESubtitleAsset>(subs, dcp::Fraction(24, 1), reel_length, 0);
 
        auto reel1 = make_shared<dcp::Reel>(
-               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "", reel_length), 0),
-               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "", dcp::MXFMetadata(), "en-US", reel_length), 0)
+               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "1", reel_length), 0),
+               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "1", dcp::MXFMetadata(), "en-US", reel_length), 0)
                );
 
        if (add_to_reel1) {
@@ -2378,8 +2260,8 @@ verify_subtitles_must_be_in_all_reels_check (path dir, bool add_to_reel1, bool a
        cpl->add (reel1);
 
        auto reel2 = make_shared<dcp::Reel>(
-               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "", reel_length), 0),
-               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "", dcp::MXFMetadata(), "en-US", reel_length), 0)
+               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "2", reel_length), 0),
+               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "2", dcp::MXFMetadata(), "en-US", reel_length), 0)
                );
 
        if (add_to_reel2) {
@@ -2446,8 +2328,8 @@ verify_closed_captions_must_be_in_all_reels_check (path dir, int caps_in_reel1,
        subs->write (dir / "subs.mxf");
 
        auto reel1 = make_shared<dcp::Reel>(
-               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "", reel_length), 0),
-               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "", dcp::MXFMetadata(), "en-US", reel_length), 0)
+               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "1", reel_length), 0),
+               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "1", dcp::MXFMetadata(), "en-US", reel_length), 0)
                );
 
        for (int i = 0; i < caps_in_reel1; ++i) {
@@ -2461,8 +2343,8 @@ verify_closed_captions_must_be_in_all_reels_check (path dir, int caps_in_reel1,
        cpl->add (reel1);
 
        auto reel2 = make_shared<dcp::Reel>(
-               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "", reel_length), 0),
-               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "", dcp::MXFMetadata(), "en-US", reel_length), 0)
+               make_shared<dcp::ReelMonoPictureAsset>(simple_picture(dir, "2", reel_length), 0),
+               make_shared<dcp::ReelSoundAsset>(simple_sound(dir, "2", dcp::MXFMetadata(), "en-US", reel_length), 0)
                );
 
        for (int i = 0; i < caps_in_reel2; ++i) {
@@ -3723,3 +3605,46 @@ BOOST_AUTO_TEST_CASE(verify_missing_load_font)
                });
 }
 
+
+BOOST_AUTO_TEST_CASE(verify_spots_wrong_asset)
+{
+       boost::filesystem::path const dir = "build/test/verify_spots_wrong_asset";
+       boost::filesystem::remove_all(dir);
+
+       auto dcp1 = make_simple(dir / "1");
+       dcp1->write_xml();
+
+       auto const asset_1 = dcp::MonoPictureAsset(dir / "1" / "video.mxf").id();
+
+       auto dcp2 = make_simple(dir / "2");
+       dcp2->write_xml();
+       auto const asset_2 = dcp::MonoPictureAsset(dir / "2" / "video.mxf").id();
+
+       boost::filesystem::remove(dir / "1" / "video.mxf");
+       boost::filesystem::copy_file(dir / "2" / "video.mxf", dir / "1" / "video.mxf");
+
+       check_verify_result(
+               {dir / "1"},
+               {
+                       dcp::VerificationNote(dcp::VerificationNote::Type::ERROR, dcp::VerificationNote::Code::MISMATCHED_ASSET_MAP_ID).set_id(asset_1).set_other_id(asset_2)
+               });
+}
+
+
+BOOST_AUTO_TEST_CASE(verify_cpl_content_version_label_text_empty)
+{
+       boost::filesystem::path const dir = "build/test/verify_cpl_content_version_label_text_empty";
+       boost::filesystem::remove_all(dir);
+
+       auto dcp = make_simple(dir);
+       BOOST_REQUIRE(dcp->cpls().size() == 1);
+       auto cpl = dcp->cpls()[0];
+       cpl->set_content_version(dcp::ContentVersion(""));
+       dcp->write_xml();
+
+       check_verify_result(
+               {dir},
+               {
+                       dcp::VerificationNote(dcp::VerificationNote::Type::WARNING, dcp::VerificationNote::Code::EMPTY_CONTENT_VERSION_LABEL_TEXT, cpl->file().get()).set_id(cpl->id())
+               });
+}