Change video content scaling so that it either:
[dcpomatic.git] / test / create_cli_test.cc
1 /*
2     Copyright (C) 2019 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 #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>
27 #include <iostream>
28
29 using std::string;
30
31 static CreateCLI
32 run (string cmd)
33 {
34         /* This approximates the logic which splits command lines up into argc/argv */
35
36         boost::escaped_list_separator<char> els ("", " ", "\"\'");
37         boost::tokenizer<boost::escaped_list_separator<char> > tok (cmd, els);
38
39         char** argv = new char*[256];
40         int argc = 0;
41
42         for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i) {
43                 argv[argc++] = strdup (i->c_str());
44         }
45
46         CreateCLI cc (argc, argv);
47
48         for (int i = 0; i < argc; ++i) {
49                 free (argv[i]);
50         }
51
52         delete[] argv;
53
54         return cc;
55 }
56
57 BOOST_AUTO_TEST_CASE (create_cli_test)
58 {
59         CreateCLI cc = run ("dcpomatic2_create --version");
60         BOOST_CHECK (!cc.error);
61         BOOST_CHECK (cc.version);
62
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'"));
66
67         cc = run ("dcpomatic2_create --help");
68         BOOST_REQUIRE (cc.error);
69
70         cc = run ("dcpomatic2_create -h");
71         BOOST_REQUIRE (cc.error);
72
73         cc = run ("dcpomatic2_create x --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");
78
79         cc = run ("dcpomatic2_create x --dcp-content-type FTR");
80         BOOST_CHECK (!cc.error);
81         BOOST_CHECK_EQUAL (cc.dcp_content_type, DCPContentType::from_isdcf_name("FTR"));
82
83         cc = run ("dcpomatic2_create x --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);
87
88         cc = run ("dcpomatic2_create x --container-ratio 185");
89         BOOST_CHECK (!cc.error);
90         BOOST_CHECK_EQUAL (cc.container_ratio, Ratio::from_id("185"));
91
92         cc = run ("dcpomatic2_create x --container-ratio XXX");
93         BOOST_CHECK (cc.error);
94
95         cc = run ("dcpomatic2_create x --still-length 42");
96         BOOST_CHECK (!cc.error);
97         BOOST_CHECK_EQUAL (cc.still_length, 42);
98
99         cc = run ("dcpomatic2_create x --standard SMPTE");
100         BOOST_CHECK (!cc.error);
101         BOOST_CHECK_EQUAL (cc.standard, dcp::SMPTE);
102
103         cc = run ("dcpomatic2_create x --standard SMPTEX");
104         BOOST_CHECK (cc.error);
105
106         cc = run ("dcpomatic2_create x --config foo/bar");
107         BOOST_CHECK (!cc.error);
108         BOOST_REQUIRE (cc.config_dir);
109         BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
110
111         cc = run ("dcpomatic2_create x --output fred/jim");
112         BOOST_CHECK (!cc.error);
113         BOOST_REQUIRE (cc.output_dir);
114         BOOST_CHECK_EQUAL (*cc.output_dir, "fred/jim");
115
116         cc = run ("dcpomatic2_create x --outputX fred/jim");
117         BOOST_CHECK (cc.error);
118
119         cc = run ("dcpomatic2_create --config foo/bar --still-length 42 --output flaps fred jim sheila");
120         BOOST_CHECK (!cc.error);
121         BOOST_REQUIRE (cc.config_dir);
122         BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
123         BOOST_CHECK_EQUAL (cc.still_length, 42);
124         BOOST_REQUIRE (cc.output_dir);
125         BOOST_CHECK_EQUAL (*cc.output_dir, "flaps");
126         BOOST_REQUIRE_EQUAL (cc.content.size(), 3);
127         BOOST_CHECK_EQUAL (cc.content[0].path, "fred");
128         BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_2D);
129         BOOST_CHECK_EQUAL (cc.content[1].path, "jim");
130         BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_2D);
131         BOOST_CHECK_EQUAL (cc.content[2].path, "sheila");
132         BOOST_CHECK_EQUAL (cc.content[2].frame_type, VIDEO_FRAME_TYPE_2D);
133
134         cc = run ("dcpomatic2_create --left-eye left.mp4 --right-eye right.mp4");
135         BOOST_REQUIRE_EQUAL (cc.content.size(), 2);
136         BOOST_CHECK_EQUAL (cc.content[0].path, "left.mp4");
137         BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_3D_LEFT);
138         BOOST_CHECK_EQUAL (cc.content[1].path, "right.mp4");
139         BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_3D_RIGHT);
140         BOOST_CHECK_EQUAL (cc.fourk, false);
141
142         cc = run ("dcpomatic2_create --fourk foo.mp4");
143         BOOST_REQUIRE_EQUAL (cc.content.size(), 1);
144         BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
145         BOOST_CHECK_EQUAL (cc.fourk, true);
146         BOOST_CHECK (!cc.error);
147
148         cc = run ("dcpomatic2_create --j2k-bandwidth 120 foo.mp4");
149         BOOST_REQUIRE_EQUAL (cc.content.size(), 1);
150         BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
151         BOOST_REQUIRE (cc.j2k_bandwidth);
152         BOOST_CHECK_EQUAL (*cc.j2k_bandwidth, 120000000);
153         BOOST_CHECK (!cc.error);
154 }