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
|
/*
Copyright (C) 2025 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/content_factory.h"
#include "lib/encode_cli.h"
#include "lib/film.h"
#include "test.h"
#include <boost/optional.hpp>
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <string>
#include <vector>
using std::cout;
using std::string;
using std::vector;
using boost::optional;
static
optional<string>
run(vector<string> const& args, vector<string>& output)
{
vector<char*> argv(args.size() + 1);
for (auto i = 0U; i < args.size(); ++i) {
argv[i] = const_cast<char*>(args[i].c_str());
}
argv[args.size()] = nullptr;
auto error = encode_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); }, []() { });
for (auto i: output) {
std::cout << "O:" << i;
}
if (error) {
std::cout << "E:" << *error << "\n";
}
return error;
}
static
bool
find_in_order(vector<string> const& output, vector<string> const& check)
{
BOOST_REQUIRE(!check.empty());
auto next = check.begin();
for (auto line: output) {
if (line.find(*next) != string::npos) {
++next;
if (next == check.end()) {
return true;
}
}
}
return false;
}
BOOST_AUTO_TEST_CASE(basic_encode_cli_test)
{
auto content = content_factory("test/data/flat_red.png");
auto film = new_test_film("basic_encode_cli_test", content);
film->write_metadata();
vector<string> output;
run({ "cli", "build/test/basic_encode_cli_test" }, output);
BOOST_CHECK(find_in_order(output, { "Making DCP for", "Examining content", "OK", "Transcoding DCP", "OK" }));
}
BOOST_AUTO_TEST_CASE(encode_cli_with_explicit_encode_command_test)
{
auto content = content_factory("test/data/flat_red.png");
auto film = new_test_film("basic_encode_cli_test", content);
film->write_metadata();
vector<string> output;
run({ "cli", "make-dcp", "build/test/basic_encode_cli_test" }, output);
BOOST_CHECK(find_in_order(output, { "Making DCP for", "Examining content", "OK", "Transcoding DCP", "OK" }));
}
#ifdef DCPOMATIC_GROK
BOOST_AUTO_TEST_CASE(encode_cli_set_grok_licence)
{
boost::filesystem::path config = "build/encode_cli_set_grok_licence";
boost::filesystem::remove_all(config);
boost::filesystem::create_directories(config);
ConfigRestorer cr(config);
vector<string> output;
auto error = run({ "cli", "config", "grok-licence", "12345678ABC" }, output);
BOOST_CHECK(output.empty());
BOOST_CHECK(!error);
cxml::Document check("Config");
check.read_file(config / "2.18" / "config.xml");
BOOST_CHECK_EQUAL(check.node_child("Grok")->string_child("Licence"), "12345678ABC");
}
#endif
|