From 3be10e6264ee8a817c4b6ed744a2a34cf99cecea Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 3 Mar 2025 00:09:01 +0100 Subject: Add a basic test of the encode CLI. --- src/lib/encode_cli.cc | 3 ++ test/encode_cli_test.cc | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ test/wscript | 1 + 3 files changed, 92 insertions(+) create mode 100644 test/encode_cli_test.cc diff --git a/src/lib/encode_cli.cc b/src/lib/encode_cli.cc index 6209d4c01..d7c4541cb 100644 --- a/src/lib/encode_cli.cc +++ b/src/lib/encode_cli.cc @@ -271,6 +271,9 @@ encode_cli(int argc, char* argv[], function out, function export_filename; bool hints = false; + /* This makes it possible to call getopt several times in the same executable, for tests */ + optind = 0; + int option_index = 0; while (true) { static struct option long_options[] = { diff --git a/test/encode_cli_test.cc b/test/encode_cli_test.cc new file mode 100644 index 000000000..fc70c02d5 --- /dev/null +++ b/test/encode_cli_test.cc @@ -0,0 +1,88 @@ +/* + Copyright (C) 2025 Carl Hetherington + + 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 . + +*/ + + +#include "lib/content_factory.h" +#include "lib/encode_cli.h" +#include "lib/film.h" +#include "test.h" +#include +#include +#include +#include +#include + + +using std::cout; +using std::string; +using std::vector; +using boost::optional; + + +static +optional +run(vector const& args, vector& output) +{ + vector argv(args.size() + 1); + for (auto i = 0U; i < args.size(); ++i) { + argv[i] = const_cast(args[i].c_str()); + } + argv[args.size()] = nullptr; + + auto error = encode_cli(args.size(), argv.data(), [&output](string s) { output.push_back(s); }, []() { }); + if (error) { + std::cout << *error << "\n"; + } + + return error; +} + + +static +bool +find_in_order(vector const& output, vector 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 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" })); +} diff --git a/test/wscript b/test/wscript index 85bfccf56..714c237a4 100644 --- a/test/wscript +++ b/test/wscript @@ -85,6 +85,7 @@ def build(bld): email_test.cc empty_caption_test.cc empty_test.cc + encode_cli_test.cc encryption_test.cc file_extension_test.cc ffmpeg_audio_only_test.cc -- cgit v1.2.3