7d85f5d7d9e6c853531c3bb754b3fb94e29ae746
[dcpomatic.git] / test / torture_test.cc
1 /*
2     Copyright (C) 2017 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/torture_test.cc
22  *  @brief Entire projects that are programmatically created and checked.
23  */
24
25 #include "lib/audio_content.h"
26 #include "lib/film.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/ratio.h"
29 #include "lib/content_factory.h"
30 #include "test.h"
31 #include <dcp/cpl.h>
32 #include <dcp/reel.h>
33 #include <dcp/reel_sound_asset.h>
34 #include <dcp/sound_asset.h>
35 #include <boost/test/unit_test.hpp>
36
37 using std::list;
38 using boost::shared_ptr;
39
40 /** Test a fairly complex arrangement of content */
41 BOOST_AUTO_TEST_CASE (torture_test1)
42 {
43         shared_ptr<Film> film = new_test_film ("player_torture_test");
44         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
45         film->set_name ("player_torture_test");
46         film->set_container (Ratio::from_id ("185"));
47         film->set_sequence (false);
48
49         /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of 6dB */
50         shared_ptr<Content> staircase = content_factory(film, "test/data/staircase.mov").front ();
51         film->examine_and_add_content (staircase);
52         wait_for_jobs ();
53         staircase->set_position (DCPTime::from_frames (2000, film->audio_frame_rate()));
54         staircase->set_trim_start (ContentTime::from_frames (12, 48000));
55         staircase->set_trim_end (ContentTime::from_frames (35, 48000));
56 //      staircase->audio->set_gain (20 * log10(2));
57
58         film->set_video_frame_rate (24);
59         film->make_dcp ();
60         wait_for_jobs ();
61
62         dcp::DCP dcp ("build/test/player_torture_test/" + film->dcp_name(false));
63         dcp.read ();
64
65         list<shared_ptr<dcp::CPL> > cpls = dcp.cpls ();
66         BOOST_REQUIRE_EQUAL (cpls.size(), 1);
67         list<shared_ptr<dcp::Reel> > reels = cpls.front()->reels ();
68         BOOST_REQUIRE_EQUAL (reels.size(), 1);
69
70         shared_ptr<dcp::ReelSoundAsset> reel_sound = reels.front()->main_sound();
71         BOOST_REQUIRE (reel_sound);
72         shared_ptr<dcp::SoundAsset> sound = reel_sound->asset();
73         BOOST_REQUIRE (sound);
74
75         shared_ptr<dcp::SoundAssetReader> sound_reader = sound->start_read ();
76
77         /* First frame silent */
78         shared_ptr<const dcp::SoundFrame> fr = sound_reader->get_frame (0);
79         for (int i = 0; i < fr->samples(); ++i) {
80                 for (int j = 0; j < 6; ++j) {
81                         BOOST_CHECK_EQUAL (fr->get(j, i), 0);
82                 }
83         }
84
85         /* The staircase is 4800 - 12 - 35 = 4753 samples.  One frame is 2000 samples, so we span 3 frames */
86
87         BOOST_REQUIRE_EQUAL (fr->samples(), 2000);
88
89         int stair = 12;
90
91         fr = sound_reader->get_frame (1);
92         for (int i = 0; i < fr->samples(); ++i) {
93                 for (int j = 0; j < 6; ++j) {
94                         if (j == 2) {
95                                 BOOST_CHECK_EQUAL (fr->get(j, i) >> 8, stair);
96                                 ++stair;
97                         } else {
98                                 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, 0);
99                         }
100                 }
101         }
102
103         fr = sound_reader->get_frame (2);
104         for (int i = 0; i < fr->samples(); ++i) {
105                 for (int j = 0; j < 6; ++j) {
106                         if (j == 2) {
107                                 BOOST_CHECK_EQUAL (fr->get(j, i) >> 8, stair);
108                                 ++stair;
109                         } else {
110                                 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
111                         }
112                 }
113         }
114
115         fr = sound_reader->get_frame (3);
116         for (int i = 0; i < 4753 - (2000 * 2); ++i) {
117                 for (int j = 0; j < 6; ++j) {
118                         if (j == 2) {
119                                 BOOST_CHECK_EQUAL (fr->get(j, i) >> 8, stair);
120                                 ++stair;
121                         } else {
122                                 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
123                         }
124                 }
125         }
126 }