summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-03-08 00:12:29 +0100
committerCarl Hetherington <cth@carlh.net>2025-03-08 00:12:29 +0100
commit182a0b48fb456355a139c21533a7d6ca0bbe42eb (patch)
tree19722a22f8667a1fe029af2ec34efbbddea3c851 /test
parentd4bb9572785a19c394cff3242e2b9ebab7c5d31c (diff)
parent42b92cbe4518a170b217ab54a26b51f56246a50f (diff)
Merge branch '2981-headless-grok'
This makes it possible to configure Grok for encoding from the command line.
Diffstat (limited to 'test')
-rw-r--r--test/config_test.cc9
m---------test/data0
-rw-r--r--test/encode_cli_test.cc163
-rwxr-xr-xtest/gpu_lister6
-rw-r--r--test/grok_util_test.cc43
-rw-r--r--test/wscript2
6 files changed, 221 insertions, 2 deletions
diff --git a/test/config_test.cc b/test/config_test.cc
index a9b95bedf..8fd19b693 100644
--- a/test/config_test.cc
+++ b/test/config_test.cc
@@ -182,9 +182,11 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test1)
check_xml (dir / "config.xml", "test/data/2.14.config.xml", {});
check_xml (dir / "cinemas.xml", "test/data/2.14.cinemas.xml", {});
-#ifdef DCPOMATIC_WINDOWS
+#if defined(DCPOMATIC_WINDOWS)
/* This file has the windows path for dkdm_recipients.xml (with backslashes) */
check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.windows.sqlite.xml", {});
+#elif defined(DCPOMATIC_GROK)
+ check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.sqlite.grok.xml", {});
#else
check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.sqlite.xml", {});
#endif
@@ -215,10 +217,13 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test2)
Config::instance()->write();
check_xml(dir / "cinemas.xml", "test/data/2.14.cinemas.xml", {});
-#ifdef DCPOMATIC_WINDOWS
+#if defined(DCPOMATIC_WINDOWS)
/* This file has the windows path for dkdm_recipients.xml (with backslashes) */
check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.windows.xml", {});
check_xml(dir / "config.xml", "test/data/2.16.config.windows.xml", {});
+#elif defined(DCPOMATIC_GROK)
+ check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.grok.xml", {});
+ check_xml(dir / "config.xml", "test/data/2.16.config.xml", {});
#else
check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.xml", {});
check_xml(dir / "config.xml", "test/data/2.16.config.xml", {});
diff --git a/test/data b/test/data
-Subproject df601f1580d852de043c2eca6acc4cfc9a2446b
+Subproject 7d2ed165d8e65d92a02a20e22c1caedd15db82b
diff --git a/test/encode_cli_test.cc b/test/encode_cli_test.cc
new file mode 100644
index 000000000..0a0a17e3a
--- /dev/null
+++ b/test/encode_cli_test.cc
@@ -0,0 +1,163 @@
+/*
+ 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");
+}
+
+
+BOOST_AUTO_TEST_CASE(encode_cli_enable_grok)
+{
+ boost::filesystem::path config = "build/encode_cli_enable_grok";
+ boost::filesystem::remove_all(config);
+ boost::filesystem::create_directories(config);
+ ConfigRestorer cr(config);
+
+ for (auto value: vector<string>{ "1", "0"}) {
+ vector<string> output;
+ auto error = run({ "cli", "config", "grok-enable", value }, 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("Enable"), value);
+ }
+}
+
+
+BOOST_AUTO_TEST_CASE(encode_cli_set_grok_binary_location)
+{
+ boost::filesystem::path config = "build/encode_cli_set_grok_binary_location";
+ boost::filesystem::remove_all(config);
+ boost::filesystem::create_directories(config);
+ ConfigRestorer cr(config);
+
+ vector<string> output;
+ auto error = run({ "cli", "config", "grok-binary-location", "foo/bar/baz" }, 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("BinaryLocation"), "foo/bar/baz");
+}
+#endif
+
diff --git a/test/gpu_lister b/test/gpu_lister
new file mode 100755
index 000000000..6dcb750de
--- /dev/null
+++ b/test/gpu_lister
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+echo "Foo bar baz"
+echo "Spondoolix Mega Kompute 2000"
+echo "Energy Sink-o-matic"
+
diff --git a/test/grok_util_test.cc b/test/grok_util_test.cc
new file mode 100644
index 000000000..2a84fe2a4
--- /dev/null
+++ b/test/grok_util_test.cc
@@ -0,0 +1,43 @@
+/*
+ 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/config.h"
+#include "lib/grok/util.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+
+#ifdef DCPOMATIC_GROK
+BOOST_AUTO_TEST_CASE(get_gpu_names_test)
+{
+ ConfigRestorer cr;
+
+ Config::Grok grok;
+ grok.binary_location = "test";
+ Config::instance()->set_grok(grok);
+
+ auto names = get_gpu_names();
+ BOOST_REQUIRE_EQUAL(names.size(), 3U);
+ BOOST_CHECK_EQUAL(names[0], "Foo bar baz");
+ BOOST_CHECK_EQUAL(names[1], "Spondoolix Mega Kompute 2000");
+ BOOST_CHECK_EQUAL(names[2], "Energy Sink-o-matic");
+}
+#endif
diff --git a/test/wscript b/test/wscript
index 85bfccf56..7e53dfb02 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
@@ -109,6 +110,7 @@ def build(bld):
font_id_allocator_test.cc
frame_interval_checker_test.cc
frame_rate_test.cc
+ grok_util_test.cc
guess_crop_test.cc
hints_test.cc
image_content_fade_test.cc