2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
36 #include <boost/test/unit_test.hpp>
37 #include <boost/algorithm/string.hpp>
46 using boost::optional;
48 static list<pair<string, optional<boost::filesystem::path> > > stages;
51 stage (string s, optional<boost::filesystem::path> p)
53 stages.push_back (make_pair (s, p));
62 /* Check DCP as-is (should be OK) */
63 BOOST_AUTO_TEST_CASE (verify_test1)
65 boost::filesystem::remove_all ("build/test/verify_test1");
66 boost::filesystem::create_directory ("build/test/verify_test1");
67 for (boost::filesystem::directory_iterator i("test/ref/DCP/dcp_test1"); i != boost::filesystem::directory_iterator(); ++i) {
68 boost::filesystem::copy_file (i->path(), "build/test/verify_test1" / i->path().filename());
71 vector<boost::filesystem::path> directories;
72 directories.push_back ("build/test/verify_test1");
73 list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress);
75 boost::filesystem::path const cpl_file = "build/test/verify_test1/cpl_81fb54df-e1bf-4647-8788-ea7ba154375b.xml";
77 list<pair<string, optional<boost::filesystem::path> > >::const_iterator st = stages.begin();
78 BOOST_CHECK_EQUAL (st->first, "Checking DCP");
79 BOOST_REQUIRE (st->second);
80 BOOST_CHECK_EQUAL (st->second.get(), boost::filesystem::canonical("build/test/verify_test1"));
82 BOOST_CHECK_EQUAL (st->first, "Checking CPL");
83 BOOST_REQUIRE (st->second);
84 BOOST_CHECK_EQUAL (st->second.get(), boost::filesystem::canonical(cpl_file));
86 BOOST_CHECK_EQUAL (st->first, "Checking reel");
87 BOOST_REQUIRE (!st->second);
89 BOOST_CHECK_EQUAL (st->first, "Checking picture asset hash");
90 BOOST_REQUIRE (st->second);
91 BOOST_CHECK_EQUAL (st->second.get(), boost::filesystem::canonical("build/test/verify_test1/video.mxf"));
93 BOOST_CHECK_EQUAL (st->first, "Checking sound asset hash");
94 BOOST_REQUIRE (st->second);
95 BOOST_CHECK_EQUAL (st->second.get(), boost::filesystem::canonical("build/test/verify_test1/audio.mxf"));
97 BOOST_REQUIRE (st == stages.end());
99 BOOST_CHECK_EQUAL (notes.size(), 0);
102 /* Corrupt the MXFs and check that this is spotted */
103 BOOST_AUTO_TEST_CASE (verify_test2)
105 boost::filesystem::remove_all ("build/test/verify_test2");
106 boost::filesystem::create_directory ("build/test/verify_test2");
107 for (boost::filesystem::directory_iterator i("test/ref/DCP/dcp_test1"); i != boost::filesystem::directory_iterator(); ++i) {
108 boost::filesystem::copy_file (i->path(), "build/test/verify_test2" / i->path().filename());
111 FILE* mod = fopen("build/test/verify_test2/video.mxf", "r+b");
113 fseek (mod, 4096, SEEK_SET);
115 fwrite (&x, sizeof(x), 1, mod);
118 mod = fopen("build/test/verify_test2/audio.mxf", "r+b");
120 fseek (mod, 4096, SEEK_SET);
121 BOOST_REQUIRE (fwrite (&x, sizeof(x), 1, mod) == 1);
124 vector<boost::filesystem::path> directories;
125 directories.push_back ("build/test/verify_test2");
126 list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress);
127 BOOST_CHECK_EQUAL (notes.size(), 2);
128 BOOST_CHECK_EQUAL (notes.front().type(), dcp::VerificationNote::VERIFY_ERROR);
129 BOOST_CHECK_EQUAL (notes.front().note(), "Picture asset hash is incorrect.");
130 BOOST_CHECK_EQUAL (notes.back().type(), dcp::VerificationNote::VERIFY_ERROR);
131 BOOST_CHECK_EQUAL (notes.back().note(), "Sound asset hash is incorrect.");
134 /* Corrupt the hashes in the PKL and check that the disagreement between CPL and PKL is spotted */
135 BOOST_AUTO_TEST_CASE (verify_test3)
137 boost::filesystem::remove_all ("build/test/verify_test3");
138 boost::filesystem::create_directory ("build/test/verify_test3");
139 for (boost::filesystem::directory_iterator i("test/ref/DCP/dcp_test1"); i != boost::filesystem::directory_iterator(); ++i) {
140 boost::filesystem::copy_file (i->path(), "build/test/verify_test3" / i->path().filename());
143 boost::filesystem::path const pkl_file = "build/test/verify_test3/pkl_74e205d0-d145-42d2-8c49-7b55d058ca55.xml";
144 boost::filesystem::path const cpl_file = "build/test/verify_test3/cpl_81fb54df-e1bf-4647-8788-ea7ba154375b.xml";
146 string pkl = dcp::file_to_string (pkl_file);
147 boost::algorithm::replace_all (pkl, "<Hash>", "<Hash>x");
148 FILE* f = fopen(pkl_file.string().c_str(), "w");
149 fwrite(pkl.c_str(), pkl.length(), 1, f);
152 vector<boost::filesystem::path> directories;
153 directories.push_back ("build/test/verify_test3");
154 list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress);
155 BOOST_CHECK_EQUAL (notes.size(), 3);
156 list<dcp::VerificationNote>::const_iterator i = notes.begin();
157 BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR);
158 BOOST_CHECK_EQUAL (i->note(), "CPL hash is incorrect.");
160 BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR);
161 BOOST_CHECK_EQUAL (i->note(), "PKL and CPL hashes differ for picture asset.");
163 BOOST_CHECK_EQUAL (i->type(), dcp::VerificationNote::VERIFY_ERROR);
164 BOOST_CHECK_EQUAL (i->note(), "PKL and CPL hashes differ for sound asset.");
168 /* Corrupt the ContentKind in the CPL */
169 BOOST_AUTO_TEST_CASE (verify_test4)
171 boost::filesystem::remove_all ("build/test/verify_test4");
172 boost::filesystem::create_directory ("build/test/verify_test4");
173 for (boost::filesystem::directory_iterator i("test/ref/DCP/dcp_test1"); i != boost::filesystem::directory_iterator(); ++i) {
174 boost::filesystem::copy_file (i->path(), "build/test/verify_test4" / i->path().filename());
177 boost::filesystem::path const cpl_file = "build/test/verify_test4/cpl_81fb54df-e1bf-4647-8788-ea7ba154375b.xml";
179 string cpl = dcp::file_to_string (cpl_file);
180 boost::algorithm::replace_all (cpl, "<ContentKind>", "<ContentKind>x");
181 FILE* f = fopen(cpl_file.string().c_str(), "w");
182 fwrite(cpl.c_str(), cpl.length(), 1, f);
185 vector<boost::filesystem::path> directories;
186 directories.push_back ("build/test/verify_test4");
187 list<dcp::VerificationNote> notes = dcp::verify (directories, &stage, &progress);
188 BOOST_CHECK_EQUAL (notes.size(), 1);
189 BOOST_CHECK_EQUAL (notes.front().note(), "Bad content kind 'xfeature'");