Fill test disk partitions with random noise to expose more bugs.
[dcpomatic.git] / test / scaling_test.cc
1 /*
2     Copyright (C) 2013-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 /** @file test/scaling_test.cc
23  *  @brief Test scaling and black-padding of images from a still-image source.
24  *  @ingroup feature
25  */
26
27
28 #include <boost/test/unit_test.hpp>
29 #include "lib/image_content.h"
30 #include "lib/ratio.h"
31 #include "lib/film.h"
32 #include "lib/dcp_content_type.h"
33 #include "lib/video_content.h"
34 #include "test.h"
35
36
37 using std::string;
38 using std::shared_ptr;
39 using std::make_shared;
40
41
42 static void scaling_test_for (shared_ptr<Film> film, shared_ptr<Content> content, float ratio, std::string image, string container)
43 {
44         content->video->set_custom_ratio (ratio);
45         film->set_container (Ratio::from_id (container));
46         film->set_interop (false);
47         make_and_verify_dcp (
48                 film,
49                 {
50                         dcp::VerificationNote::Code::MISSING_FFMC_IN_FEATURE,
51                         dcp::VerificationNote::Code::MISSING_FFEC_IN_FEATURE
52                 });
53
54         boost::filesystem::path ref;
55         ref = "test";
56         ref /= "data";
57         ref /= "scaling_test_" + image + "_" + container;
58
59         boost::filesystem::path check;
60         check = "build";
61         check /= "test";
62         check /= "scaling_test";
63         check /= film->dcp_name();
64
65         check_dcp (ref.string(), check.string());
66 }
67
68
69 BOOST_AUTO_TEST_CASE (scaling_test)
70 {
71         auto film = new_test_film ("scaling_test");
72         film->set_dcp_content_type (DCPContentType::from_isdcf_name("FTR"));
73         film->set_name ("scaling_test");
74         auto imc = make_shared<ImageContent>("test/data/simple_testcard_640x480.png");
75
76         film->examine_and_add_content (imc);
77
78         BOOST_REQUIRE (!wait_for_jobs());
79
80         imc->video->set_length (1);
81
82         /* F-133: 133 image in a flat container */
83         scaling_test_for (film, imc, 4.0 / 3, "133", "185");
84         /* F: flat image in a flat container */
85         scaling_test_for (film, imc, 1.85, "185", "185");
86         /* F-S: scope image in a flat container */
87         scaling_test_for (film, imc, 2.38695, "239", "185");
88
89         /* S-133: 133 image in a scope container */
90         scaling_test_for (film, imc, 4.0 / 3, "133", "239");
91         /* S-F: flat image in a scope container */
92         scaling_test_for (film, imc, 1.85, "185", "239");
93         /* S: scope image in a scope container */
94         scaling_test_for (film, imc, 2.38695, "239", "239");
95 }