Use sqlite for cinema and DKDM recipient lists.
[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_j2k_picture_asset.h>
37 #include <dcp/stereo_j2k_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         film->set_video_bit_rate(VideoEncoding::JPEG2000, 100000000);
67
68         auto content = make_shared<FFmpegContent>("test/data/count300bd24.m2ts");
69         film->examine_and_add_content (content);
70         BOOST_REQUIRE (!wait_for_jobs());
71
72         make_and_verify_dcp (
73                 film,
74                 {
75                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
76                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
77                 });
78
79         boost::filesystem::path const video = "build/test/recover_test_2d/video/185_2K_4650f318cea570763a0c6411c8c098ce_24_100000000_P_S_L21_0_1200000.mxf";
80         boost::filesystem::copy_file (
81                 video,
82                 "build/test/recover_test_2d/original.mxf"
83                 );
84
85         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
86
87         make_and_verify_dcp(
88                 film,
89                 {
90                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE,
91                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE
92                 },
93                 true,
94                 /* We end up with two CPLs in this directory, which Clairmeta gives an error for */
95                 false
96                 );
97
98         auto A = make_shared<dcp::MonoJ2KPictureAsset>("build/test/recover_test_2d/original.mxf");
99         auto B = make_shared<dcp::MonoJ2KPictureAsset>(video);
100
101         dcp::EqualityOptions eq;
102         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
103 }
104
105
106 BOOST_AUTO_TEST_CASE (recover_test_3d, * boost::unit_test::depends_on("recover_test_2d"))
107 {
108         auto film = new_test_film ("recover_test_3d");
109         film->set_interop (false);
110         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
111         film->set_container (Ratio::from_id ("185"));
112         film->set_name ("recover_test");
113         film->set_three_d (true);
114         film->set_video_bit_rate(VideoEncoding::JPEG2000, 100000000);
115
116         auto content = make_shared<ImageContent>("test/data/3d_test");
117         content->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
118         film->examine_and_add_content (content);
119         BOOST_REQUIRE (!wait_for_jobs());
120
121         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
122
123         boost::filesystem::path const video = "build/test/recover_test_3d/video/185_2K_60a75a531ca9546bdd513163117e2214_24_100000000_P_S_L21_3D_0_96000.mxf";
124
125         boost::filesystem::copy_file (
126                 video,
127                 "build/test/recover_test_3d/original.mxf"
128                 );
129
130         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
131
132         make_and_verify_dcp(
133                 film,
134                 {
135                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE
136                 },
137                 true,
138                 /* We end up with two CPLs in this directory, which Clairmeta gives an error for */
139                 false
140                 );
141
142         auto A = make_shared<dcp::StereoJ2KPictureAsset>("build/test/recover_test_3d/original.mxf");
143         auto B = make_shared<dcp::StereoJ2KPictureAsset>(video);
144
145         dcp::EqualityOptions eq;
146         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
147 }
148
149
150 BOOST_AUTO_TEST_CASE (recover_test_2d_encrypted, * boost::unit_test::depends_on("recover_test_3d"))
151 {
152         auto film = new_test_film ("recover_test_2d_encrypted");
153         film->set_interop (false);
154         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
155         film->set_container (Ratio::from_id ("185"));
156         film->set_name ("recover_test");
157         film->set_encrypted (true);
158         film->_key = dcp::Key("eafcb91c9f5472edf01f3a2404c57258");
159         film->set_video_bit_rate(VideoEncoding::JPEG2000, 100000000);
160
161         auto content = make_shared<FFmpegContent>("test/data/count300bd24.m2ts");
162         film->examine_and_add_content (content);
163         BOOST_REQUIRE (!wait_for_jobs());
164
165         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
166
167         boost::filesystem::path const video =
168                 "build/test/recover_test_2d_encrypted/video/185_2K_4650f318cea570763a0c6411c8c098ce_24_100000000_Eeafcb91c9f5472edf01f3a2404c57258_S_L21_0_1200000.mxf";
169
170         boost::filesystem::copy_file (
171                 video,
172                 "build/test/recover_test_2d_encrypted/original.mxf"
173                 );
174
175         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
176
177         make_and_verify_dcp(
178                 film,
179                 {
180                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE
181                 },
182                 true,
183                 /* We end up with two CPLs in this directory, which Clairmeta gives an error for */
184                 false
185                 );
186
187         auto A = make_shared<dcp::MonoJ2KPictureAsset>("build/test/recover_test_2d_encrypted/original.mxf");
188         A->set_key (film->key ());
189         auto B = make_shared<dcp::MonoJ2KPictureAsset>(video);
190         B->set_key (film->key ());
191
192         dcp::EqualityOptions eq;
193         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
194 }