2c2f2ed17dcb323a458cb3540a5ed76aecf7af12
[dcpomatic.git] / test / required_disk_space_test.cc
1 /*
2     Copyright (C) 2016 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 #include "lib/content_factory.h"
21 #include "lib/film.h"
22 #include "lib/dcp_content.h"
23 #include "test.h"
24 #include <boost/test/unit_test.hpp>
25
26 using boost::shared_ptr;
27 using boost::dynamic_pointer_cast;
28
29 void check_within_n (int64_t a, int64_t b, int64_t n)
30 {
31         BOOST_CHECK (abs (a - b) <= n);
32 }
33
34
35 BOOST_AUTO_TEST_CASE (required_disk_space_test)
36 {
37         shared_ptr<Film> film = new_test_film ("required_disk_space_test");
38         film->set_j2k_bandwidth (100000000);
39         film->set_audio_channels (6);
40         shared_ptr<Content> content_a = content_factory (film, "test/data/flat_blue.png");
41         film->examine_and_add_content (content_a);
42         shared_ptr<DCPContent> content_b = dynamic_pointer_cast<DCPContent> (content_factory (film, "test/data/burnt_subtitle_test_dcp"));
43         film->examine_and_add_content (content_b);
44         wait_for_jobs ();
45         film->write_metadata ();
46
47         check_within_n (
48                 film->required_disk_space(),
49                 289LL * (100000000 / 8) / 24 +  // video
50                 289LL * 48000 * 6 * 3 / 24 +    // audio
51                 65536,                          // extra
52                 16
53                 );
54
55         content_b->set_reference_video (true);
56
57         check_within_n (
58                 film->required_disk_space(),
59                 240LL * (100000000 / 8) / 24 +  // video
60                 289LL * 48000 * 6 * 3 / 24 +    // audio
61                 65536,                          // extra
62                 16
63                 );
64
65         content_b->set_reference_audio (true);
66
67         check_within_n (
68                 film->required_disk_space(),
69                 240LL * (100000000 / 8) / 24 +  // video
70                 240LL * 48000 * 6 * 3 / 24 +    // audio
71                 65536,                          // extra
72                 16
73                 );
74 }