2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic 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 DCP-o-matic 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/content.h"
23 #include "lib/content_factory.h"
24 #include "lib/dcp_content.h"
26 #include "lib/find_missing.h"
28 #include <boost/filesystem.hpp>
29 #include <boost/test/unit_test.hpp>
32 using std::make_shared;
36 BOOST_AUTO_TEST_CASE (find_missing_test_with_single_files)
38 using namespace boost::filesystem;
40 auto name = string{"find_missing_test_with_single_files"};
42 /* Make a directory with some content */
43 auto content_dir = path("build/test") / path(name + "_content");
44 remove_all (content_dir);
45 create_directories (content_dir);
46 copy_file ("test/data/flat_red.png", content_dir / "A.png");
47 copy_file ("test/data/flat_red.png", content_dir / "B.png");
48 copy_file ("test/data/flat_red.png", content_dir / "C.png");
50 /* Make a film with that content */
51 auto film = new_test_film2 (name + "_film", {
52 content_factory(content_dir / "A.png").front(),
53 content_factory(content_dir / "B.png").front(),
54 content_factory(content_dir / "C.png").front()
56 film->write_metadata ();
58 /* Move the content somewhere eles */
59 auto moved = path("build/test") / path(name + "_moved");
61 rename (content_dir, moved);
63 /* That should make the content paths invalid */
64 for (auto content: film->content()) {
65 BOOST_CHECK (!content->paths_valid());
68 /* Fix the missing files and check the result */
69 dcpomatic::find_missing (film->content(), moved / "A.png");
71 for (auto content: film->content()) {
72 BOOST_CHECK (content->paths_valid());
77 BOOST_AUTO_TEST_CASE (find_missing_test_with_multiple_files)
79 using namespace boost::filesystem;
81 auto name = string{"find_missing_test_with_multiple_files"};
83 /* Copy an arbitrary DCP into a test directory */
84 auto content_dir = path("build/test") / path(name + "_content");
85 remove_all (content_dir);
86 create_directories (content_dir);
87 for (auto ref: directory_iterator("test/data/scaling_test_133_185")) {
88 copy (ref, content_dir / ref.path().filename());
91 /* Make a film containing that DCP */
92 auto film = new_test_film2 (name + "_film", { make_shared<DCPContent>(content_dir) });
93 film->write_metadata ();
95 /* Move the DCP's content elsewhere */
96 auto moved = path("build/test") / path(name + "_moved");
98 rename (content_dir, moved);
100 /* That should make the content paths invalid */
101 for (auto content: film->content()) {
102 BOOST_CHECK (!content->paths_valid());
105 /* Fix the missing files and check the result */
106 dcpomatic::find_missing (film->content(), moved / "foo");
108 for (auto content: film->content()) {
109 BOOST_CHECK (content->paths_valid());
114 BOOST_AUTO_TEST_CASE (find_missing_test_with_multiple_files_one_incorrect)
116 using namespace boost::filesystem;
118 auto name = string{"find_missing_test_with_multiple_files_one_incorrect"};
120 /* Copy an arbitrary DCP into a test directory */
121 auto content_dir = path("build/test") / path(name + "_content");
122 remove_all (content_dir);
123 create_directories (content_dir);
124 for (auto ref: directory_iterator("test/data/scaling_test_133_185")) {
125 copy (ref, content_dir / ref.path().filename());
128 /* Make a film containing that DCP */
129 auto film = new_test_film2 (name + "_film", { make_shared<DCPContent>(content_dir) });
130 film->write_metadata ();
132 /* Move the DCP's content elsewhere */
133 auto moved = path("build/test") / path(name + "_moved");
135 rename (content_dir, moved);
137 /* Corrupt one of the files in the moved content, so that it should not be found in the find_missing
140 auto cpl = find_file(moved, "cpl_");
142 copy ("test/data/scaling_test_133_185/ASSETMAP.xml", cpl);
144 /* The film's contents should be invalid */
145 for (auto content: film->content()) {
146 BOOST_CHECK (!content->paths_valid());
149 dcpomatic::find_missing (film->content(), moved / "foo");
151 /* And even after find_missing there should still be missing content */
152 for (auto content: film->content()) {
153 BOOST_CHECK (!content->paths_valid());