2 Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "lib/config.h"
23 #include "lib/create_cli.h"
25 #include "lib/ratio.h"
26 #include "lib/dcp_content_type.h"
28 #include <boost/test/unit_test.hpp>
29 #include <boost/tokenizer.hpp>
30 #include <boost/algorithm/string/predicate.hpp>
40 /* This approximates the logic which splits command lines up into argc/argv */
42 boost::escaped_list_separator<char> els ("", " ", "\"\'");
43 boost::tokenizer<boost::escaped_list_separator<char> > tok (cmd, els);
45 std::vector<char*> argv(256);
48 for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i) {
49 argv[argc++] = strdup (i->c_str());
52 CreateCLI cc (argc, argv.data());
54 for (int i = 0; i < argc; ++i) {
61 BOOST_AUTO_TEST_CASE (create_cli_test)
63 CreateCLI cc = run ("dcpomatic2_create --version");
64 BOOST_CHECK (!cc.error);
65 BOOST_CHECK (cc.version);
67 cc = run ("dcpomatic2_create --versionX");
68 BOOST_REQUIRE (cc.error);
69 BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: unrecognised option '--versionX'"));
71 cc = run ("dcpomatic2_create --help");
72 BOOST_REQUIRE (cc.error);
74 cc = run ("dcpomatic2_create -h");
75 BOOST_REQUIRE (cc.error);
77 cc = run ("dcpomatic2_create x --name frobozz --template bar");
78 BOOST_CHECK (!cc.error);
79 BOOST_CHECK_EQUAL(cc._name, "frobozz");
80 BOOST_REQUIRE(cc._template_name);
81 BOOST_CHECK_EQUAL(*cc._template_name, "bar");
83 cc = run ("dcpomatic2_create x --dcp-content-type FTR");
84 BOOST_CHECK (!cc.error);
85 BOOST_CHECK_EQUAL(cc._dcp_content_type, DCPContentType::from_isdcf_name("FTR"));
87 cc = run ("dcpomatic2_create x --dcp-frame-rate 30");
88 BOOST_CHECK (!cc.error);
89 BOOST_REQUIRE (cc.dcp_frame_rate);
90 BOOST_CHECK_EQUAL (*cc.dcp_frame_rate, 30);
92 cc = run ("dcpomatic2_create x --container-ratio 185");
93 BOOST_CHECK (!cc.error);
94 BOOST_CHECK_EQUAL(cc._container_ratio, Ratio::from_id("185"));
96 cc = run ("dcpomatic2_create x --container-ratio XXX");
97 BOOST_CHECK (cc.error);
99 cc = run ("dcpomatic2_create x --still-length 42");
100 BOOST_CHECK (!cc.error);
101 BOOST_CHECK_EQUAL(cc.still_length.get_value_or(0), 42);
103 cc = run ("dcpomatic2_create x --standard SMPTE");
104 BOOST_CHECK (!cc.error);
105 BOOST_REQUIRE(cc._standard);
106 BOOST_CHECK_EQUAL(*cc._standard, dcp::Standard::SMPTE);
108 cc = run ("dcpomatic2_create x --standard interop");
109 BOOST_CHECK (!cc.error);
110 BOOST_REQUIRE(cc._standard);
111 BOOST_CHECK_EQUAL(*cc._standard, dcp::Standard::INTEROP);
113 cc = run ("dcpomatic2_create x --standard SMPTEX");
114 BOOST_CHECK (cc.error);
116 cc = run("dcpomatic2_create x --no-encrypt");
117 BOOST_CHECK(cc._no_encrypt);
119 cc = run("dcpomatic2_create x --encrypt");
120 BOOST_CHECK(cc._encrypt);
122 cc = run("dcpomatic2_create x --no-encrypt --encrypt");
123 BOOST_CHECK(cc.error);
125 cc = run("dcpomatic2_create x --twod");
126 BOOST_CHECK(cc._twod);
128 cc = run("dcpomatic2_create x --threed");
129 BOOST_CHECK(cc._threed);
131 cc = run("dcpomatic2_create x --twod --threed");
132 BOOST_CHECK(cc.error);
134 cc = run ("dcpomatic2_create x --config foo/bar");
135 BOOST_CHECK (!cc.error);
136 BOOST_REQUIRE (cc.config_dir);
137 BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
139 cc = run ("dcpomatic2_create x --output fred/jim");
140 BOOST_CHECK (!cc.error);
141 BOOST_REQUIRE (cc.output_dir);
142 BOOST_CHECK_EQUAL (*cc.output_dir, "fred/jim");
144 cc = run ("dcpomatic2_create x --outputX fred/jim");
145 BOOST_CHECK (cc.error);
147 cc = run ("dcpomatic2_create --config foo/bar --still-length 42 --output flaps fred jim sheila");
148 BOOST_CHECK (!cc.error);
149 BOOST_REQUIRE (cc.config_dir);
150 BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
151 BOOST_CHECK_EQUAL(cc.still_length.get_value_or(0), 42);
152 BOOST_REQUIRE (cc.output_dir);
153 BOOST_CHECK_EQUAL (*cc.output_dir, "flaps");
154 BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
155 BOOST_CHECK_EQUAL (cc.content[0].path, "fred");
156 BOOST_CHECK_EQUAL (cc.content[0].frame_type, VideoFrameType::TWO_D);
157 BOOST_CHECK_EQUAL (cc.content[1].path, "jim");
158 BOOST_CHECK_EQUAL (cc.content[1].frame_type, VideoFrameType::TWO_D);
159 BOOST_CHECK_EQUAL (cc.content[2].path, "sheila");
160 BOOST_CHECK_EQUAL (cc.content[2].frame_type, VideoFrameType::TWO_D);
162 cc = run ("dcpomatic2_create --left-eye left.mp4 --right-eye right.mp4");
163 BOOST_REQUIRE_EQUAL (cc.content.size(), 2U);
164 BOOST_CHECK_EQUAL (cc.content[0].path, "left.mp4");
165 BOOST_CHECK_EQUAL (cc.content[0].frame_type, VideoFrameType::THREE_D_LEFT);
166 BOOST_CHECK_EQUAL (cc.content[1].path, "right.mp4");
167 BOOST_CHECK_EQUAL (cc.content[1].frame_type, VideoFrameType::THREE_D_RIGHT);
168 BOOST_CHECK_EQUAL(cc._fourk, false);
170 cc = run ("dcpomatic2_create --twok foo.mp4");
171 BOOST_REQUIRE_EQUAL (cc.content.size(), 1U);
172 BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
173 BOOST_CHECK_EQUAL(cc._twok, true);
174 BOOST_CHECK (!cc.error);
176 cc = run ("dcpomatic2_create --fourk foo.mp4");
177 BOOST_REQUIRE_EQUAL (cc.content.size(), 1U);
178 BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
179 BOOST_CHECK_EQUAL(cc._fourk, true);
180 BOOST_CHECK (!cc.error);
182 cc = run ("dcpomatic2_create --video-bit-rate 120 foo.mp4");
183 BOOST_REQUIRE_EQUAL (cc.content.size(), 1U);
184 BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
185 BOOST_REQUIRE(cc._video_bit_rate);
186 BOOST_CHECK_EQUAL(*cc._video_bit_rate, 120000000);
187 BOOST_CHECK (!cc.error);
189 cc = run ("dcpomatic2_create --channel L fred.wav --channel R jim.wav sheila.wav");
190 BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
191 BOOST_CHECK_EQUAL (cc.content[0].path, "fred.wav");
192 BOOST_CHECK (cc.content[0].channel);
193 BOOST_CHECK (*cc.content[0].channel == dcp::Channel::LEFT);
194 BOOST_CHECK_EQUAL (cc.content[1].path, "jim.wav");
195 BOOST_CHECK (cc.content[1].channel);
196 BOOST_CHECK (*cc.content[1].channel == dcp::Channel::RIGHT);
197 BOOST_CHECK_EQUAL (cc.content[2].path, "sheila.wav");
198 BOOST_CHECK (!cc.content[2].channel);
200 cc = run ("dcpomatic2_create --channel foo fred.wav");
201 BOOST_REQUIRE (cc.error);
202 BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: foo is not valid for --channel"));
204 cc = run ("dcpomatic2_create fred.wav --gain -6 jim.wav --gain 2 sheila.wav");
205 BOOST_REQUIRE_EQUAL (cc.content.size(), 3U);
206 BOOST_CHECK_EQUAL (cc.content[0].path, "fred.wav");
207 BOOST_CHECK (!cc.content[0].gain);
208 BOOST_CHECK_EQUAL (cc.content[1].path, "jim.wav");
209 BOOST_CHECK_CLOSE (*cc.content[1].gain, -6, 0.001);
210 BOOST_CHECK_EQUAL (cc.content[2].path, "sheila.wav");
211 BOOST_CHECK_CLOSE (*cc.content[2].gain, 2, 0.001);
213 cc = run("dcpomatic2_create --cpl 123456-789-0 dcp");
214 BOOST_REQUIRE_EQUAL(cc.content.size(), 1U);
215 BOOST_CHECK_EQUAL(cc.content[0].path, "dcp");
216 BOOST_REQUIRE(static_cast<bool>(cc.content[0].cpl));
217 BOOST_CHECK_EQUAL(*cc.content[0].cpl, "123456-789-0");
219 cc = run("dcpomatic2_create -s SMPTE sheila.wav");
220 BOOST_CHECK(!cc.still_length);
221 BOOST_CHECK(cc.error);
225 BOOST_AUTO_TEST_CASE(create_cli_template_test)
229 Config::override_path = "test/data";
231 auto cc = run("dcpomatic2_create test/data/flat_red.png");
232 auto film = cc.make_film();
233 BOOST_CHECK(!film->three_d());
235 cc = run("dcpomatic2_create test/data/flat_red.png --template 2d");
236 film = cc.make_film();
237 BOOST_CHECK(!film->three_d());
239 cc = run("dcpomatic2_create test/data/flat_red.png --template 2d --threed");
240 film = cc.make_film();
241 BOOST_CHECK(film->three_d());
243 cc = run("dcpomatic2_create test/data/flat_red.png --template 3d");
244 film = cc.make_film();
245 BOOST_CHECK(film->three_d());
247 cc = run("dcpomatic2_create test/data/flat_red.png --template 3d --twod");
248 film = cc.make_film();
249 BOOST_CHECK(!film->three_d());
251 cc = run("dcpomatic2_create test/data/flat_red.png");
252 film = cc.make_film();
253 BOOST_CHECK(!film->encrypted());
255 cc = run("dcpomatic2_create test/data/flat_red.png --template unencrypted");
256 film = cc.make_film();
257 BOOST_CHECK(!film->encrypted());
259 cc = run("dcpomatic2_create test/data/flat_red.png --template unencrypted --encrypt");
260 film = cc.make_film();
261 BOOST_CHECK(film->encrypted());
263 cc = run("dcpomatic2_create test/data/flat_red.png --template encrypted");
264 film = cc.make_film();
265 BOOST_CHECK(film->encrypted());
267 cc = run("dcpomatic2_create test/data/flat_red.png --template encrypted --no-encrypt");
268 film = cc.make_film();
269 BOOST_CHECK(!film->encrypted());
271 cc = run("dcpomatic2_create test/data/flat_red.png");
272 film = cc.make_film();
273 BOOST_CHECK(!film->interop());
275 cc = run("dcpomatic2_create test/data/flat_red.png --template interop");
276 film = cc.make_film();
277 BOOST_CHECK(film->interop());
279 cc = run("dcpomatic2_create test/data/flat_red.png --template interop --standard SMPTE");
280 film = cc.make_film();
281 BOOST_CHECK(!film->interop());
283 cc = run("dcpomatic2_create test/data/flat_red.png --template smpte");
284 film = cc.make_film();
285 BOOST_CHECK(!film->interop());
287 cc = run("dcpomatic2_create test/data/flat_red.png --template smpte --standard interop");
288 film = cc.make_film();
289 BOOST_CHECK(film->interop());
293 BOOST_AUTO_TEST_CASE(create_cli_defaults_test)
297 /* I think on balance dcpomatic2_create should not use the defaults from Config;
298 * it seems a bit surprising that settings from a GUI tool can change the behaviour of
299 * a CLI tool, and at some point we're probably going to remove all the default config
300 * options from the main DoM anyway (in favour of a default template).
302 Config::instance()->set_default_interop(true);
303 auto cc = run("dcpomatic2_create test/data/flat_red.png");
304 auto film = cc.make_film();
305 BOOST_CHECK(!film->interop());
307 Config::instance()->set_default_dcp_content_type(DCPContentType::from_isdcf_name("FT"));
308 cc = run("dcpomatic2_create test/data/flat_red.png");
309 film = cc.make_film();
310 BOOST_CHECK_EQUAL(film->dcp_content_type()->isdcf_name(), "TST");