fixup! WIP: stop using video directory and hard-linking (#2756).
[dcpomatic.git] / test / recover_test.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21
22 /** @file  test/recover_test.cc
23  *  @brief Test recovery of a DCP transcode after a crash.
24  *  @ingroup feature
25  */
26
27
28 #include "test.h"
29 #include "lib/film.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/image_content.h"
32 #include "lib/ffmpeg_content.h"
33 #include "lib/video_content.h"
34 #include "lib/ratio.h"
35 #include <dcp/equality_options.h>
36 #include <dcp/mono_picture_asset.h>
37 #include <dcp/stereo_picture_asset.h>
38 #include <boost/test/unit_test.hpp>
39 #include <iostream>
40
41
42 using std::cout;
43 using std::make_shared;
44 using std::string;
45 #if BOOST_VERSION >= 106100
46 using namespace boost::placeholders;
47 #endif
48
49
50 static void
51 note (dcp::NoteType t, string n)
52 {
53         if (t == dcp::NoteType::ERROR) {
54                 cout << n << "\n";
55         }
56 }
57
58
59 BOOST_AUTO_TEST_CASE (recover_test_2d)
60 {
61         auto film = new_test_film("recover_test_2d");
62         film->set_interop (false);
63         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
64         film->set_container (Ratio::from_id ("185"));
65         film->set_name ("recover_test");
66
67         auto content = make_shared<FFmpegContent>("test/data/count300bd24.m2ts");
68         film->examine_and_add_content (content);
69         BOOST_REQUIRE (!wait_for_jobs());
70
71         make_and_verify_dcp (
72                 film,
73                 {
74                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
75                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
76                 });
77
78         auto video = [film]() {
79                 return find_file(boost::filesystem::path("build/test/recover_test_2d") / film->dcp_name(false), "j2c_");
80         };
81
82         boost::filesystem::copy_file (
83                 video(),
84                 "build/test/recover_test_2d/original.mxf"
85                 );
86
87         boost::filesystem::resize_file(video(), 2 * 1024 * 1024);
88
89         make_and_verify_dcp(
90                 film,
91                 {
92                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE,
93                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE
94                 },
95                 true,
96                 /* We end up with two CPLs in this directory, which Clairmeta gives an error for */
97                 false
98                 );
99
100         auto A = make_shared<dcp::MonoPictureAsset>("build/test/recover_test_2d/original.mxf");
101         auto B = make_shared<dcp::MonoPictureAsset>(video());
102
103         dcp::EqualityOptions eq;
104         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
105 }
106
107
108 BOOST_AUTO_TEST_CASE (recover_test_3d, * boost::unit_test::depends_on("recover_test_2d"))
109 {
110         auto film = new_test_film ("recover_test_3d");
111         film->set_interop (false);
112         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
113         film->set_container (Ratio::from_id ("185"));
114         film->set_name ("recover_test");
115         film->set_three_d (true);
116
117         auto content = make_shared<ImageContent>("test/data/3d_test");
118         content->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
119         film->examine_and_add_content (content);
120         BOOST_REQUIRE (!wait_for_jobs());
121
122         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
123
124         auto video = [film]() {
125                 return find_file(boost::filesystem::path("build/test/recover_test_3d") / film->dcp_name(false), "j2c_");
126         };
127
128         boost::filesystem::copy_file (
129                 video(),
130                 "build/test/recover_test_3d/original.mxf"
131                 );
132
133         boost::filesystem::resize_file(video(), 2 * 1024 * 1024);
134
135         make_and_verify_dcp(
136                 film,
137                 {
138                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE
139                 },
140                 true,
141                 /* We end up with two CPLs in this directory, which Clairmeta gives an error for */
142                 false
143                 );
144
145         auto A = make_shared<dcp::StereoPictureAsset>("build/test/recover_test_3d/original.mxf");
146         auto B = make_shared<dcp::StereoPictureAsset>(video());
147
148         dcp::EqualityOptions eq;
149         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
150 }
151
152
153 BOOST_AUTO_TEST_CASE (recover_test_2d_encrypted, * boost::unit_test::depends_on("recover_test_3d"))
154 {
155         auto film = new_test_film ("recover_test_2d_encrypted");
156         film->set_interop (false);
157         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
158         film->set_container (Ratio::from_id ("185"));
159         film->set_name ("recover_test");
160         film->set_encrypted (true);
161         film->_key = dcp::Key("eafcb91c9f5472edf01f3a2404c57258");
162
163         auto content = make_shared<FFmpegContent>("test/data/count300bd24.m2ts");
164         film->examine_and_add_content (content);
165         BOOST_REQUIRE (!wait_for_jobs());
166
167         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
168
169         auto video = [film]() {
170                 return find_file(boost::filesystem::path("build/test/recover_test_2d_encrypted") / film->dcp_name(false), "j2c_");
171         };
172
173         boost::filesystem::copy_file (
174                 video(),
175                 "build/test/recover_test_2d_encrypted/original.mxf"
176                 );
177
178         boost::filesystem::resize_file(video(), 2 * 1024 * 1024);
179
180         make_and_verify_dcp(
181                 film,
182                 {
183                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE
184                 },
185                 true,
186                 /* We end up with two CPLs in this directory, which Clairmeta gives an error for */
187                 false
188                 );
189
190         auto A = make_shared<dcp::MonoPictureAsset>("build/test/recover_test_2d_encrypted/original.mxf");
191         A->set_key (film->key ());
192         auto B = make_shared<dcp::MonoPictureAsset>(video());
193         B->set_key (film->key ());
194
195         dcp::EqualityOptions eq;
196         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
197 }