Cleanup: test tidying.
[dcpomatic.git] / test / markers_test.cc
1 /*
2     Copyright (C) 2020-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/markers_test
23  *  @brief Test SMPTE markers.
24  *  @ingroup feature
25  */
26
27
28 #include "lib/content_factory.h"
29 #include "lib/film.h"
30 #include "test.h"
31 #include <dcp/cpl.h>
32 #include <dcp/dcp.h>
33 #include <dcp/reel_markers_asset.h>
34 #include <dcp/reel.h>
35 #include <boost/test/unit_test.hpp>
36
37
38 using std::string;
39 using boost::optional;
40
41
42 /** Check that FFOC and LFOC are automatically added if not specified */
43 BOOST_AUTO_TEST_CASE (automatic_ffoc_lfoc_markers_test1)
44 {
45         string const name = "automatic_ffoc_lfoc_markers_test1";
46         auto film = new_test_film2 (name);
47         film->examine_and_add_content (content_factory("test/data/flat_red.png")[0]);
48         BOOST_REQUIRE (!wait_for_jobs());
49
50         film->set_interop (false);
51         make_and_verify_dcp (film);
52
53         dcp::DCP dcp (String::compose("build/test/%1/%2", name, film->dcp_name()));
54         dcp.read ();
55         BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
56         auto cpl = dcp.cpls().front();
57         BOOST_REQUIRE_EQUAL (cpl->reels().size(), 1U);
58         auto reel = cpl->reels()[0];
59         auto markers = reel->main_markers();
60         BOOST_REQUIRE (markers);
61
62         auto ffoc = markers->get (dcp::Marker::FFOC);
63         BOOST_REQUIRE (ffoc);
64         BOOST_CHECK (*ffoc == dcp::Time(0, 0, 0, 1, 24));
65         auto lfoc = markers->get (dcp::Marker::LFOC);
66         BOOST_REQUIRE (lfoc);
67         BOOST_CHECK (*lfoc == dcp::Time(0, 0, 9, 23, 24));
68 }
69
70
71 /** Check that FFOC and LFOC are not overridden if they are specified */
72 BOOST_AUTO_TEST_CASE (automatic_ffoc_lfoc_markers_test2)
73 {
74         string const name = "automatic_ffoc_lfoc_markers_test2";
75         auto film = new_test_film2 (name);
76         film->examine_and_add_content (content_factory("test/data/flat_red.png")[0]);
77         BOOST_REQUIRE (!wait_for_jobs());
78
79         film->set_interop (false);
80         film->set_marker (dcp::Marker::FFOC, dcpomatic::DCPTime::from_seconds(1));
81         film->set_marker (dcp::Marker::LFOC, dcpomatic::DCPTime::from_seconds(9));
82         make_and_verify_dcp (
83                 film,
84                 {
85                         dcp::VerificationNote::Code::INCORRECT_FFOC,
86                         dcp::VerificationNote::Code::INCORRECT_LFOC
87                 });
88
89         dcp::DCP dcp (String::compose("build/test/%1/%2", name, film->dcp_name()));
90         dcp.read ();
91         BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
92         auto cpl = dcp.cpls().front();
93         BOOST_REQUIRE_EQUAL (cpl->reels().size(), 1U);
94         auto reel = cpl->reels()[0];
95         auto markers = reel->main_markers();
96         BOOST_REQUIRE (markers);
97
98         auto ffoc = markers->get (dcp::Marker::FFOC);
99         BOOST_REQUIRE (ffoc);
100         BOOST_CHECK (*ffoc == dcp::Time (0, 0, 1, 0, 24));
101         auto lfoc = markers->get (dcp::Marker::LFOC);
102         BOOST_REQUIRE (lfoc);
103         BOOST_CHECK (*lfoc == dcp::Time(0, 0, 9, 0, 24));
104 }
105
106
107
108 BOOST_AUTO_TEST_CASE(markers_correct_with_reels)
109 {
110         string const name = "markers_correct_with_reels";
111         auto content1 = content_factory("test/data/flat_red.png")[0];
112         auto content2 = content_factory("test/data/flat_red.png")[0];
113         auto film = new_test_film2(name, { content1, content2});
114
115         film->set_interop(false);
116         film->set_reel_type(ReelType::BY_VIDEO_CONTENT);
117         make_and_verify_dcp(film);
118
119         dcp::DCP dcp(String::compose("build/test/%1/%2", name, film->dcp_name()));
120         dcp.read ();
121         BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
122         auto cpl = dcp.cpls()[0];
123         BOOST_REQUIRE_EQUAL(cpl->reels().size(), 2U);
124
125         auto markers1 = cpl->reels()[0]->main_markers();
126         BOOST_REQUIRE(markers1);
127         auto ffoc = markers1->get(dcp::Marker::FFOC);
128         BOOST_REQUIRE(ffoc);
129         BOOST_CHECK(*ffoc == dcp::Time(0, 0, 0, 1, 24));
130         auto no_lfoc = markers1->get(dcp::Marker::LFOC);
131         BOOST_CHECK(!no_lfoc);
132
133         auto markers2 = cpl->reels()[1]->main_markers();
134         BOOST_REQUIRE(markers2);
135         auto no_ffoc = markers2->get(dcp::Marker::FFOC);
136         BOOST_REQUIRE(!no_ffoc);
137         auto lfoc = markers2->get(dcp::Marker::LFOC);
138         BOOST_REQUIRE(lfoc);
139         BOOST_CHECK(*lfoc == dcp::Time(0, 0, 9, 23, 24));
140 }
141