std::shared_ptr
[dcpomatic.git] / test / recover_test.cc
1 /*
2     Copyright (C) 2014-2015 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 /** @file  test/recover_test.cc
22  *  @brief Test recovery of a DCP transcode after a crash.
23  *  @ingroup feature
24  */
25
26 #include "test.h"
27 #include "lib/film.h"
28 #include "lib/dcp_content_type.h"
29 #include "lib/image_content.h"
30 #include "lib/ffmpeg_content.h"
31 #include "lib/video_content.h"
32 #include "lib/ratio.h"
33 #include <dcp/mono_picture_asset.h>
34 #include <dcp/stereo_picture_asset.h>
35 #include <boost/test/unit_test.hpp>
36 #include <iostream>
37
38 using std::cout;
39 using std::string;
40 using std::shared_ptr;
41 #if BOOST_VERSION >= 106100
42 using namespace boost::placeholders;
43 #endif
44
45 static void
46 note (dcp::NoteType t, string n)
47 {
48         if (t == dcp::DCP_ERROR) {
49                 cout << n << "\n";
50         }
51 }
52
53 BOOST_AUTO_TEST_CASE (recover_test_2d)
54 {
55         shared_ptr<Film> film = new_test_film ("recover_test_2d");
56         film->set_interop (false);
57         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
58         film->set_container (Ratio::from_id ("185"));
59         film->set_name ("recover_test");
60
61         shared_ptr<FFmpegContent> content (new FFmpegContent("test/data/count300bd24.m2ts"));
62         film->examine_and_add_content (content);
63         BOOST_REQUIRE (!wait_for_jobs());
64
65         film->make_dcp ();
66         BOOST_REQUIRE (!wait_for_jobs());
67
68         boost::filesystem::path const video = "build/test/recover_test_2d/video/185_2K_02543352c540f4b083bff3f1e309d4a9_24_100000000_P_S_0_1200000.mxf";
69         boost::filesystem::copy_file (
70                 video,
71                 "build/test/recover_test_2d/original.mxf"
72                 );
73
74         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
75
76         film->make_dcp ();
77         BOOST_REQUIRE (!wait_for_jobs());
78
79         shared_ptr<dcp::MonoPictureAsset> A (new dcp::MonoPictureAsset ("build/test/recover_test_2d/original.mxf"));
80         shared_ptr<dcp::MonoPictureAsset> B (new dcp::MonoPictureAsset (video));
81
82         dcp::EqualityOptions eq;
83         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
84 }
85
86 BOOST_AUTO_TEST_CASE (recover_test_3d, * boost::unit_test::depends_on("recover_test_2d"))
87 {
88         shared_ptr<Film> film = new_test_film ("recover_test_3d");
89         film->set_interop (false);
90         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
91         film->set_container (Ratio::from_id ("185"));
92         film->set_name ("recover_test");
93         film->set_three_d (true);
94
95         shared_ptr<ImageContent> content (new ImageContent("test/data/3d_test"));
96         content->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT_RIGHT);
97         film->examine_and_add_content (content);
98         BOOST_REQUIRE (!wait_for_jobs());
99
100         film->make_dcp ();
101         BOOST_REQUIRE (!wait_for_jobs());
102
103         boost::filesystem::path const video = "build/test/recover_test_3d/video/185_2K_70e6661af92ae94458784c16a21a9748_24_100000000_P_S_3D_0_96000.mxf";
104
105         boost::filesystem::copy_file (
106                 video,
107                 "build/test/recover_test_3d/original.mxf"
108                 );
109
110         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
111
112         film->make_dcp ();
113         BOOST_REQUIRE (!wait_for_jobs());
114
115         shared_ptr<dcp::StereoPictureAsset> A (new dcp::StereoPictureAsset ("build/test/recover_test_3d/original.mxf"));
116         shared_ptr<dcp::StereoPictureAsset> B (new dcp::StereoPictureAsset (video));
117
118         dcp::EqualityOptions eq;
119         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
120 }
121
122
123 BOOST_AUTO_TEST_CASE (recover_test_2d_encrypted, * boost::unit_test::depends_on("recover_test_3d"))
124 {
125         shared_ptr<Film> film = new_test_film ("recover_test_2d_encrypted");
126         film->set_interop (false);
127         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
128         film->set_container (Ratio::from_id ("185"));
129         film->set_name ("recover_test");
130         film->set_encrypted (true);
131         film->_key = dcp::Key("eafcb91c9f5472edf01f3a2404c57258");
132
133         shared_ptr<FFmpegContent> content (new FFmpegContent("test/data/count300bd24.m2ts"));
134         film->examine_and_add_content (content);
135         BOOST_REQUIRE (!wait_for_jobs());
136
137         film->make_dcp ();
138         BOOST_REQUIRE (!wait_for_jobs());
139
140         boost::filesystem::path const video =
141                 "build/test/recover_test_2d_encrypted/video/185_2K_02543352c540f4b083bff3f1e309d4a9_24_100000000_Eeafcb91c9f5472edf01f3a2404c57258_S_0_1200000.mxf";
142
143         boost::filesystem::copy_file (
144                 video,
145                 "build/test/recover_test_2d_encrypted/original.mxf"
146                 );
147
148         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
149
150         film->make_dcp ();
151         BOOST_REQUIRE (!wait_for_jobs());
152
153         shared_ptr<dcp::MonoPictureAsset> A (new dcp::MonoPictureAsset ("build/test/recover_test_2d_encrypted/original.mxf"));
154         A->set_key (film->key ());
155         shared_ptr<dcp::MonoPictureAsset> B (new dcp::MonoPictureAsset (video));
156         B->set_key (film->key ());
157
158         dcp::EqualityOptions eq;
159         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
160 }