Basics of reel split.
[dcpomatic.git] / test / recover_test.cc
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  test/recover_test.cc
21  *  @brief Test recovery of a DCP transcode after a crash.
22  */
23
24 #include "test.h"
25 #include "lib/film.h"
26 #include "lib/dcp_content_type.h"
27 #include "lib/image_content.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/ratio.h"
30 #include <dcp/mono_picture_asset.h>
31 #include <dcp/stereo_picture_asset.h>
32 #include <boost/test/unit_test.hpp>
33 #include <iostream>
34
35 using std::cout;
36 using std::string;
37 using boost::shared_ptr;
38
39 static void
40 note (dcp::NoteType t, string n)
41 {
42         if (t == dcp::DCP_ERROR) {
43                 cout << n << "\n";
44         }
45 }
46
47 BOOST_AUTO_TEST_CASE (recover_test_2d)
48 {
49         shared_ptr<Film> film = new_test_film ("recover_test_2d");
50         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
51         film->set_container (Ratio::from_id ("185"));
52         film->set_name ("recover_test");
53
54         shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd24.m2ts"));
55         film->examine_and_add_content (content);
56         wait_for_jobs ();
57
58         film->make_dcp ();
59         wait_for_jobs ();
60
61         boost::filesystem::path const video = "build/test/recover_test_2d/video/185_2K_d2b23c22cff43b0247c7108dcd32323c_24_100000000_P_S_0_1200000.mxf";
62
63         boost::filesystem::copy_file (
64                 video,
65                 "build/test/recover_test_2d/original.mxf"
66                 );
67
68         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
69
70         film->make_dcp ();
71         wait_for_jobs ();
72
73         shared_ptr<dcp::MonoPictureAsset> A (new dcp::MonoPictureAsset ("build/test/recover_test_2d/original.mxf"));
74         shared_ptr<dcp::MonoPictureAsset> B (new dcp::MonoPictureAsset (video));
75
76         dcp::EqualityOptions eq;
77         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
78 }
79
80 BOOST_AUTO_TEST_CASE (recover_test_3d)
81 {
82         shared_ptr<Film> film = new_test_film ("recover_test_3d");
83         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
84         film->set_container (Ratio::from_id ("185"));
85         film->set_name ("recover_test");
86         film->set_three_d (true);
87
88         shared_ptr<ImageContent> content (new ImageContent (film, "test/data/3d_test"));
89         content->set_video_frame_type (VIDEO_FRAME_TYPE_3D_LEFT_RIGHT);
90         film->examine_and_add_content (content);
91         wait_for_jobs ();
92
93         film->make_dcp ();
94         wait_for_jobs ();
95
96         boost::filesystem::path const video = "build/test/recover_test_3d/video/185_2K_961f053444e90c5ddbf978eb0ebfa772_24_100000000_P_S_3D_0_96000.mxf";
97
98         boost::filesystem::copy_file (
99                 video,
100                 "build/test/recover_test_3d/original.mxf"
101                 );
102
103         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
104
105         film->make_dcp ();
106         wait_for_jobs ();
107
108         shared_ptr<dcp::StereoPictureAsset> A (new dcp::StereoPictureAsset ("build/test/recover_test_3d/original.mxf"));
109         shared_ptr<dcp::StereoPictureAsset> B (new dcp::StereoPictureAsset (video));
110
111         dcp::EqualityOptions eq;
112         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
113 }