summaryrefslogtreecommitdiff
path: root/test/create_cli_test.cc
blob: b92cb284b9e8532ba9efbfb16005e67580ad3b71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
    Copyright (C) 2019 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "lib/create_cli.h"
#include "lib/ratio.h"
#include "lib/dcp_content_type.h"
#include <boost/test/unit_test.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <iostream>

using std::string;

static CreateCLI
run (string cmd)
{
	/* This approximates the logic which splits command lines up into argc/argv */

	boost::escaped_list_separator<char> els ("", " ", "\"\'");
	boost::tokenizer<boost::escaped_list_separator<char> > tok (cmd, els);

	char** argv = new char*[256];
	int argc = 0;

	for (boost::tokenizer<boost::escaped_list_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i) {
		argv[argc++] = strdup (i->c_str());
	}

	CreateCLI cc (argc, argv);

	for (int i = 0; i < argc; ++i) {
		free (argv[i]);
	}

	delete[] argv;

	return cc;
}

BOOST_AUTO_TEST_CASE (create_cli_test)
{
	CreateCLI cc = run ("dcpomatic2_create --version");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK (cc.version);

	cc = run ("dcpomatic2_create --versionX");
	BOOST_REQUIRE (cc.error);
	BOOST_CHECK (boost::algorithm::starts_with(*cc.error, "dcpomatic2_create: unrecognised option '--versionX'"));

	cc = run ("dcpomatic2_create --help");
	BOOST_REQUIRE (cc.error);

	cc = run ("dcpomatic2_create -h");
	BOOST_REQUIRE (cc.error);

	cc = run ("dcpomatic2_create x --content-ratio 185 --name frobozz --template bar");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK_EQUAL (cc.name, "frobozz");
	BOOST_REQUIRE (cc.template_name);
	BOOST_CHECK_EQUAL (*cc.template_name, "bar");

	cc = run ("dcpomatic2_create x --content-ratio 185 --dcp-content-type FTR");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK_EQUAL (cc.dcp_content_type, DCPContentType::from_isdcf_name("FTR"));

	cc = run ("dcpomatic2_create x --content-ratio 185 --dcp-frame-rate 30");
	BOOST_CHECK (!cc.error);
	BOOST_REQUIRE (cc.dcp_frame_rate);
	BOOST_CHECK_EQUAL (*cc.dcp_frame_rate, 30);

	cc = run ("dcpomatic2_create x --content-ratio 185 --container-ratio 185");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK_EQUAL (cc.container_ratio, Ratio::from_id("185"));

	cc = run ("dcpomatic2_create x --content-ratio 185 --container-ratio XXX");
	BOOST_CHECK (cc.error);

	cc = run ("dcpomatic2_create x --content-ratio 185 --content-ratio 239");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK_EQUAL (cc.content_ratio, Ratio::from_id("239"));

	cc = run ("dcpomatic2_create x --content-ratio 240");
	BOOST_CHECK (cc.error);

	cc = run ("dcpomatic2_create x --content-ratio 185 --still-length 42");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK_EQUAL (cc.still_length, 42);

	cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTE");
	BOOST_CHECK (!cc.error);
	BOOST_CHECK_EQUAL (cc.standard, dcp::SMPTE);

	cc = run ("dcpomatic2_create x --content-ratio 185 --standard SMPTEX");
	BOOST_CHECK (cc.error);

	cc = run ("dcpomatic2_create x --content-ratio 185 --config foo/bar");
	BOOST_CHECK (!cc.error);
	BOOST_REQUIRE (cc.config_dir);
	BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");

	cc = run ("dcpomatic2_create x --content-ratio 185 --output fred/jim");
	BOOST_CHECK (!cc.error);
	BOOST_REQUIRE (cc.output_dir);
	BOOST_CHECK_EQUAL (*cc.output_dir, "fred/jim");

	cc = run ("dcpomatic2_create x --content-ratio 185 --outputX fred/jim");
	BOOST_CHECK (cc.error);

	cc = run ("dcpomatic2_create --content-ratio 185 --config foo/bar --still-length 42 --output flaps fred jim sheila");
	BOOST_CHECK (!cc.error);
	BOOST_REQUIRE (cc.config_dir);
	BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar");
	BOOST_CHECK_EQUAL (cc.still_length, 42);
	BOOST_REQUIRE (cc.output_dir);
	BOOST_CHECK_EQUAL (*cc.output_dir, "flaps");
	BOOST_REQUIRE_EQUAL (cc.content.size(), 3);
	BOOST_CHECK_EQUAL (cc.content[0].path, "fred");
	BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_2D);
	BOOST_CHECK_EQUAL (cc.content[1].path, "jim");
	BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_2D);
	BOOST_CHECK_EQUAL (cc.content[2].path, "sheila");
	BOOST_CHECK_EQUAL (cc.content[2].frame_type, VIDEO_FRAME_TYPE_2D);

	cc = run ("dcpomatic2_create --content-ratio 185 --left-eye left.mp4 --right-eye right.mp4");
	BOOST_REQUIRE_EQUAL (cc.content.size(), 2);
	BOOST_CHECK_EQUAL (cc.content[0].path, "left.mp4");
	BOOST_CHECK_EQUAL (cc.content[0].frame_type, VIDEO_FRAME_TYPE_3D_LEFT);
	BOOST_CHECK_EQUAL (cc.content[1].path, "right.mp4");
	BOOST_CHECK_EQUAL (cc.content[1].frame_type, VIDEO_FRAME_TYPE_3D_RIGHT);
	BOOST_CHECK_EQUAL (cc.fourk, false);

	cc = run ("dcpomatic2_create --fourk --content-ratio 185 foo.mp4");
	BOOST_REQUIRE_EQUAL (cc.content.size(), 1);
	BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
	BOOST_CHECK_EQUAL (cc.fourk, true);
	BOOST_CHECK (!cc.error);

	cc = run ("dcpomatic2_create --j2k-bandwidth 120 --content-ratio 185 foo.mp4");
	BOOST_REQUIRE_EQUAL (cc.content.size(), 1);
	BOOST_CHECK_EQUAL (cc.content[0].path, "foo.mp4");
	BOOST_REQUIRE (cc.j2k_bandwidth);
	BOOST_CHECK_EQUAL (*cc.j2k_bandwidth, 120000000);
	BOOST_CHECK (!cc.error);
}