2 Copyright (C) 2019 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/>.
21 #include "lib/create_cli.h"
22 #include "lib/ratio.h"
23 #include "lib/dcp_content_type.h"
24 #include <boost/test/unit_test.hpp>
25 #include <boost/tokenizer.hpp>
26 #include <boost/algorithm/string/predicate.hpp>
34 /* This approximates the logic which splits command lines up into argc/argv */
36 boost::escaped_list_separator<char> els ("", " ", "\"\'");
37 boost::tokenizer<boost::escaped_list_separator<char> > tok (cmd, els);
39 char** argv = new char*[256];
42 for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i) {
43 argv[argc++] = strdup (i->c_str());
46 CreateCLI cc (argc, argv);
48 for (int i = 0; i < argc; ++i) {
57 BOOST_AUTO_TEST_CASE (create_cli_test)
59 CreateCLI cc = run ("dcpomatic2_create --version");
60 BOOST_CHECK (!cc.error);
61 BOOST_CHECK (cc.version);
63 cc = run ("dcpomatic2_create --versionX");
64 BOOST_REQUIRE (cc.error);
65 BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: unrecognised option '--versionX'"));
67 cc = run ("dcpomatic2_create --help");
68 BOOST_REQUIRE (cc.error);
70 cc = run ("dcpomatic2_create -h");
71 BOOST_REQUIRE (cc.error);
73 cc = run ("dcpomatic2_create x --content-ratio 185 --name frobozz --template bar");
74 BOOST_CHECK (!cc.error);
75 BOOST_CHECK_EQUAL (cc.name, "frobozz");
76 BOOST_REQUIRE (cc.template_name);
77 BOOST_CHECK_EQUAL (*cc.template_name, "bar");
79 cc = run ("dcpomatic2_create x --content-ratio 185 --dcp-content-type FTR");
80 BOOST_CHECK (!cc.error);
81 BOOST_CHECK_EQUAL (cc.dcp_content_type, DCPContentType::from_isdcf_name("FTR"));
83 cc = run ("dcpomatic2_create x --content-ratio 185 --dcp-frame-rate 30");
84 BOOST_CHECK (!cc.error);
85 BOOST_REQUIRE (cc.dcp_frame_rate);
86 BOOST_CHECK_EQUAL (*cc.dcp_frame_rate, 30);
88 cc = run ("dcpomatic2_create x --content-ratio 185 --container-ratio 185");
89 BOOST_CHECK (!cc.error);
90 BOOST_CHECK_EQUAL (cc.container_ratio, Ratio::from_id("185"));
92 cc = run ("dcpomatic2_create x --content-ratio 185 --container-ratio XXX");
93 BOOST_CHECK (cc.error);
95 cc = run ("dcpomatic2_create x --content-ratio 185 --content-ratio 239");
96 BOOST_CHECK (!cc.error);
97 BOOST_CHECK_EQUAL (cc.content_ratio, Ratio::from_id("239"));
99 cc = run ("dcpomatic2_create x --content-ratio 240");
100 BOOST_CHECK (cc.error);
102 cc = run ("dcpomatic2_create x --content-ratio 185 --still-length 42");
103 BOOST_CHECK (!cc.error);
104 BOOST_CHECK_EQUAL (cc.still_length, 42);
106 cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTE");
107 BOOST_CHECK (!cc.error);
108 BOOST_CHECK_EQUAL (cc.standard, dcp::SMPTE);
110 cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTEX");
111 BOOST_CHECK (cc.error);
113 cc = run ("dcpomatic2_create x --content-ratio 185 --config foo/bar");
114 BOOST_CHECK (!cc.error);
115 BOOST_REQUIRE (cc.config_dir);
116 BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
118 cc = run ("dcpomatic2_create x --content-ratio 185 --output fred/jim");
119 BOOST_CHECK (!cc.error);
120 BOOST_REQUIRE (cc.output_dir);
121 BOOST_CHECK_EQUAL (*cc.output_dir, "fred/jim");
123 cc = run ("dcpomatic2_create x --content-ratio 185 --outputX fred/jim");
124 BOOST_CHECK (cc.error);
126 cc = run ("dcpomatic2_create --content-ratio 185 --config foo/bar --still-length 42 --output flaps fred jim sheila");
127 BOOST_CHECK (!cc.error);
128 BOOST_REQUIRE (cc.config_dir);
129 BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
130 BOOST_CHECK_EQUAL (cc.still_length, 42);
131 BOOST_REQUIRE (cc.output_dir);
132 BOOST_CHECK_EQUAL (*cc.output_dir, "flaps");
133 BOOST_REQUIRE_EQUAL (cc.content.size(), 3);
134 BOOST_CHECK_EQUAL (cc.content[0].path, "fred");
135 BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_2D);
136 BOOST_CHECK_EQUAL (cc.content[1].path, "jim");
137 BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_2D);
138 BOOST_CHECK_EQUAL (cc.content[2].path, "sheila");
139 BOOST_CHECK_EQUAL (cc.content[2].frame_type, VIDEO_FRAME_TYPE_2D);
141 cc = run ("dcpomatic2_create --content-ratio 185 --left-eye left.mp4 --right-eye right.mp4");
142 BOOST_REQUIRE_EQUAL (cc.content.size(), 2);
143 BOOST_CHECK_EQUAL (cc.content[0].path, "left.mp4");
144 BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_3D_LEFT);
145 BOOST_CHECK_EQUAL (cc.content[1].path, "right.mp4");
146 BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_3D_RIGHT);