Revert "Use make_shared<>."
[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  */
24
25 #include "test.h"
26 #include "lib/film.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/image_content.h"
29 #include "lib/ffmpeg_content.h"
30 #include "lib/video_content.h"
31 #include "lib/ratio.h"
32 #include <dcp/mono_picture_asset.h>
33 #include <dcp/stereo_picture_asset.h>
34 #include <boost/test/unit_test.hpp>
35 #include <iostream>
36
37 using std::cout;
38 using std::string;
39 using boost::shared_ptr;
40
41 static void
42 note (dcp::NoteType t, string n)
43 {
44         if (t == dcp::DCP_ERROR) {
45                 cout << n << "\n";
46         }
47 }
48
49 BOOST_AUTO_TEST_CASE (recover_test_2d)
50 {
51         shared_ptr<Film> film = new_test_film ("recover_test_2d");
52         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
53         film->set_container (Ratio::from_id ("185"));
54         film->set_name ("recover_test");
55
56         shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd24.m2ts"));
57         film->examine_and_add_content (content);
58         wait_for_jobs ();
59
60         film->make_dcp ();
61         wait_for_jobs ();
62
63         boost::filesystem::path const video = "build/test/recover_test_2d/video/185_2K_bf7d9a3ad543b4f048be97e8df309918_24_100000000_P_S_0_1200000.mxf";
64         boost::filesystem::copy_file (
65                 video,
66                 "build/test/recover_test_2d/original.mxf"
67                 );
68
69         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
70
71         film->make_dcp ();
72         wait_for_jobs ();
73
74         shared_ptr<dcp::MonoPictureAsset> A (new dcp::MonoPictureAsset ("build/test/recover_test_2d/original.mxf"));
75         shared_ptr<dcp::MonoPictureAsset> B (new dcp::MonoPictureAsset (video));
76
77         dcp::EqualityOptions eq;
78         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
79 }
80
81 BOOST_AUTO_TEST_CASE (recover_test_3d)
82 {
83         shared_ptr<Film> film = new_test_film ("recover_test_3d");
84         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
85         film->set_container (Ratio::from_id ("185"));
86         film->set_name ("recover_test");
87         film->set_three_d (true);
88
89         shared_ptr<ImageContent> content (new ImageContent (film, "test/data/3d_test"));
90         content->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT_RIGHT);
91         film->examine_and_add_content (content);
92         wait_for_jobs ();
93
94         film->make_dcp ();
95         wait_for_jobs ();
96
97         boost::filesystem::path const video = "build/test/recover_test_3d/video/185_2K_961f053444e90c5ddbf978eb0ebfa772_24_100000000_P_S_3D_0_96000.mxf";
98
99         boost::filesystem::copy_file (
100                 video,
101                 "build/test/recover_test_3d/original.mxf"
102                 );
103
104         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
105
106         film->make_dcp ();
107         wait_for_jobs ();
108
109         shared_ptr<dcp::StereoPictureAsset> A (new dcp::StereoPictureAsset ("build/test/recover_test_3d/original.mxf"));
110         shared_ptr<dcp::StereoPictureAsset> B (new dcp::StereoPictureAsset (video));
111
112         dcp::EqualityOptions eq;
113         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
114 }