Cleanup: test tidying.
[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/mono_picture_asset.h>
36 #include <dcp/stereo_picture_asset.h>
37 #include <boost/test/unit_test.hpp>
38 #include <iostream>
39
40
41 using std::cout;
42 using std::make_shared;
43 using std::string;
44 #if BOOST_VERSION >= 106100
45 using namespace boost::placeholders;
46 #endif
47
48
49 static void
50 note (dcp::NoteType t, string n)
51 {
52         if (t == dcp::NoteType::ERROR) {
53                 cout << n << "\n";
54         }
55 }
56
57
58 BOOST_AUTO_TEST_CASE (recover_test_2d)
59 {
60         auto film = new_test_film("recover_test_2d");
61         film->set_interop (false);
62         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
63         film->set_container (Ratio::from_id ("185"));
64         film->set_name ("recover_test");
65
66         auto content = make_shared<FFmpegContent>("test/data/count300bd24.m2ts");
67         film->examine_and_add_content (content);
68         BOOST_REQUIRE (!wait_for_jobs());
69
70         make_and_verify_dcp (
71                 film,
72                 {
73                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
74                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
75                 });
76
77         boost::filesystem::path const video = "build/test/recover_test_2d/video/185_2K_02543352c540f4b083bff3f1e309d4a9_24_100000000_P_S_0_1200000.mxf";
78         boost::filesystem::copy_file (
79                 video,
80                 "build/test/recover_test_2d/original.mxf"
81                 );
82
83         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
84
85         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
86
87         auto A = make_shared<dcp::MonoPictureAsset>("build/test/recover_test_2d/original.mxf");
88         auto B = make_shared<dcp::MonoPictureAsset>(video);
89
90         dcp::EqualityOptions eq;
91         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
92 }
93
94
95 BOOST_AUTO_TEST_CASE (recover_test_3d, * boost::unit_test::depends_on("recover_test_2d"))
96 {
97         auto film = new_test_film ("recover_test_3d");
98         film->set_interop (false);
99         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
100         film->set_container (Ratio::from_id ("185"));
101         film->set_name ("recover_test");
102         film->set_three_d (true);
103
104         auto content = make_shared<ImageContent>("test/data/3d_test");
105         content->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
106         film->examine_and_add_content (content);
107         BOOST_REQUIRE (!wait_for_jobs());
108
109         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
110
111         boost::filesystem::path const video = "build/test/recover_test_3d/video/185_2K_70e6661af92ae94458784c16a21a9748_24_100000000_P_S_3D_0_96000.mxf";
112
113         boost::filesystem::copy_file (
114                 video,
115                 "build/test/recover_test_3d/original.mxf"
116                 );
117
118         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
119
120         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
121
122         auto A = make_shared<dcp::StereoPictureAsset>("build/test/recover_test_3d/original.mxf");
123         auto B = make_shared<dcp::StereoPictureAsset>(video);
124
125         dcp::EqualityOptions eq;
126         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
127 }
128
129
130 BOOST_AUTO_TEST_CASE (recover_test_2d_encrypted, * boost::unit_test::depends_on("recover_test_3d"))
131 {
132         auto film = new_test_film ("recover_test_2d_encrypted");
133         film->set_interop (false);
134         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
135         film->set_container (Ratio::from_id ("185"));
136         film->set_name ("recover_test");
137         film->set_encrypted (true);
138         film->_key = dcp::Key("eafcb91c9f5472edf01f3a2404c57258");
139
140         auto content = make_shared<FFmpegContent>("test/data/count300bd24.m2ts");
141         film->examine_and_add_content (content);
142         BOOST_REQUIRE (!wait_for_jobs());
143
144         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
145
146         boost::filesystem::path const video =
147                 "build/test/recover_test_2d_encrypted/video/185_2K_02543352c540f4b083bff3f1e309d4a9_24_100000000_Eeafcb91c9f5472edf01f3a2404c57258_S_0_1200000.mxf";
148
149         boost::filesystem::copy_file (
150                 video,
151                 "build/test/recover_test_2d_encrypted/original.mxf"
152                 );
153
154         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
155
156         make_and_verify_dcp (film, { dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE, dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE });
157
158         auto A = make_shared<dcp::MonoPictureAsset>("build/test/recover_test_2d_encrypted/original.mxf");
159         A->set_key (film->key ());
160         auto B = make_shared<dcp::MonoPictureAsset>(video);
161         B->set_key (film->key ());
162
163         dcp::EqualityOptions eq;
164         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
165 }