Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / optimise_stills_test.cc
1 /*
2     Copyright (C) 2017-2021 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
22 #include "lib/dcp_encoder.h"
23 #include "lib/writer.h"
24 #include "lib/transcode_job.h"
25 #include "lib/job_manager.h"
26 #include "lib/film.h"
27 #include "lib/ratio.h"
28 #include "lib/content_factory.h"
29 #include "lib/dcp_content_type.h"
30 #include "lib/content.h"
31 #include "lib/video_content.h"
32 #include "lib/dcpomatic_log.h"
33 #include "test.h"
34 #include <boost/test/unit_test.hpp>
35 #include <boost/algorithm/string.hpp>
36
37
38 using std::getline;
39 using std::ifstream;
40 using std::string;
41 using std::vector;
42 using boost::starts_with;
43 using boost::split;
44 using std::dynamic_pointer_cast;
45 using std::shared_ptr;
46
47
48 static
49 void
50 check (string name, int check_full, int check_repeat)
51 {
52         /* The encoder will have been destroyed so parse the logs */
53         string log_file = "build/test/" + name + "/log";
54         ifstream log (log_file.c_str());
55         string line;
56         int repeat = 0;
57         int full = 0;
58         while (getline (log, line)) {
59                 vector<string> bits;
60                 split (bits, line, boost::is_any_of (":"));
61                 if (bits.size() >= 4 && starts_with (bits[3], " Wrote")) {
62                         split (bits, bits[3], boost::is_any_of (" "));
63                         if (bits.size() >= 7) {
64                                 full = atoi (bits[2].c_str());
65                                 repeat = atoi (bits[6].c_str());
66                         }
67                 }
68
69         }
70
71         BOOST_CHECK_EQUAL (full, check_full);
72         BOOST_CHECK_EQUAL (repeat, check_repeat);
73 }
74
75
76 /** Make a 2D DCP out of a 2D still and check that the J2K encoding is only done once for each frame */
77 BOOST_AUTO_TEST_CASE (optimise_stills_test1)
78 {
79         auto film = new_test_film ("optimise_stills_test1");
80         LogSwitcher ls (film->log());
81         film->set_container (Ratio::from_id ("185"));
82         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
83         film->set_name ("frobozz");
84         auto content = content_factory("test/data/flat_red.png").front ();
85         film->examine_and_add_content (content);
86         BOOST_REQUIRE (!wait_for_jobs ());
87         make_and_verify_dcp (film);
88
89         check ("optimise_stills_test1", 1, 10 * 24 - 1);
90 }
91
92
93 /** Make a 3D DCP out of a 3D L/R still and check that the J2K encoding is only done once for L and R */
94 BOOST_AUTO_TEST_CASE (optimise_stills_test2)
95 {
96         auto film = new_test_film ("optimise_stills_test2");
97         LogSwitcher ls (film->log());
98         film->set_container (Ratio::from_id ("185"));
99         film->set_dcp_content_type (DCPContentType::from_isdcf_name("TLR"));
100         film->set_name ("frobozz");
101         auto content = content_factory("test/data/flat_red.png").front();
102         film->examine_and_add_content (content);
103         BOOST_REQUIRE (!wait_for_jobs ());
104         content->video->set_frame_type (VideoFrameType::THREE_D_LEFT_RIGHT);
105         film->set_three_d (true);
106         make_and_verify_dcp (film);
107
108         check ("optimise_stills_test2", 2, 10 * 48 - 2);
109 }