summaryrefslogtreecommitdiff
path: root/features
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-01-26 02:18:21 +0100
committerCarl Hetherington <cth@carlh.net>2025-01-26 02:21:16 +0100
commit69fabac6d2219c07cfdcd9a8fe6e92bf4669be46 (patch)
tree1627020b59fb7380f6e7a4d5ba42de8f1955242c /features
parent811e70bdd09a618f8b0a512950a7f3254c591614 (diff)
Add a simple cucumber test.
Diffstat (limited to 'features')
-rw-r--r--features/add_still_image.feature11
-rw-r--r--features/step_definitions/cucumber.wire3
-rw-r--r--features/step_definitions/dcpomatic.cc146
-rw-r--r--features/support/env.rb0
-rw-r--r--features/wscript40
5 files changed, 200 insertions, 0 deletions
diff --git a/features/add_still_image.feature b/features/add_still_image.feature
new file mode 100644
index 000000000..6e3c48a47
--- /dev/null
+++ b/features/add_still_image.feature
@@ -0,0 +1,11 @@
+Feature: Add still image
+
+Scenario Outline: Add some content
+ Given I have created a new film
+ When I add file <file> as content
+ Then the result should be only <display> in the content list
+
+Examples:
+ | file | display |
+ | /home/carl/DCP/bbc405.png | bbc405.png [still] |
+
diff --git a/features/step_definitions/cucumber.wire b/features/step_definitions/cucumber.wire
new file mode 100644
index 000000000..aa2b7b19a
--- /dev/null
+++ b/features/step_definitions/cucumber.wire
@@ -0,0 +1,3 @@
+host: localhost
+port: 3902
+
diff --git a/features/step_definitions/dcpomatic.cc b/features/step_definitions/dcpomatic.cc
new file mode 100644
index 000000000..98570b6b3
--- /dev/null
+++ b/features/step_definitions/dcpomatic.cc
@@ -0,0 +1,146 @@
+/*
+ Copyright (C) 2020 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 "wx/cucumber_bridge.h"
+#include "lib/nanomsg.h"
+#include <fmt/format.h>
+#include <boost/test/unit_test.hpp>
+
+#include <cucumber-cpp/autodetect.hpp>
+
+
+using std::getline;
+using std::string;
+using std::stringstream;
+using std::vector;
+using cucumber::ScenarioScope;
+
+
+auto constexpr TIMEOUT = 200;
+
+
+struct Context
+{
+ Context()
+ : _nanomsg(false, "cucumber")
+ {
+
+ }
+
+ void click_button(string id)
+ {
+ general_delay();
+ send(CUCUMBER_BRIDGE_CLICK_REGISTERED_BUTTON);
+ send(id);
+ }
+
+ /* Click a button in the focussed dialog */
+ void click_button(wxStandardID id)
+ {
+ general_delay();
+ send(CUCUMBER_BRIDGE_CLICK_BUTTON_ID);
+ send(fmt::to_string(id));
+ }
+
+ void select_menu(string id)
+ {
+ general_delay();
+ send(CUCUMBER_BRIDGE_SELECT_MENU);
+ send(id);
+ }
+
+ void type(std::string text)
+ {
+ general_delay();
+ send(CUCUMBER_BRIDGE_TYPE);
+ send(text);
+ }
+
+ void add_content_file(string filename)
+ {
+ general_delay();
+ send(CUCUMBER_BRIDGE_ADD_CONTENT_FILE);
+ send(filename);
+ }
+
+ vector<string> content_list()
+ {
+ general_delay();
+ send(CUCUMBER_BRIDGE_GET_CONTENT_LIST);
+ stringstream all(receive());
+ vector<string> split;
+ string one;
+ while (getline(all, one, '\n')) {
+ split.push_back(one);
+ }
+ return split;
+ }
+
+private:
+ void send(string m)
+ {
+ BOOST_REQUIRE(_nanomsg.send(m + "\n", TIMEOUT));
+ }
+
+ std::string receive()
+ {
+ auto reply = _nanomsg.receive(TIMEOUT);
+ BOOST_REQUIRE(static_cast<bool>(reply));
+ return *reply;
+ }
+
+ void general_delay()
+ {
+ sleep(2);
+ }
+
+ Nanomsg _nanomsg;
+};
+
+
+GIVEN("^I have created a new film$")
+{
+ ScenarioScope<Context> context;
+ context->select_menu(CUCUMBER_MENU_FILE_NEW);
+ context->type("test");
+ context->click_button(wxID_OK);
+}
+
+
+WHEN("^I add file (.+) as content$")
+{
+ REGEX_PARAM(string, filename);
+ ScenarioScope<Context> context;
+ /* I could not find a way to reliably enter text into a open file dialogue, so
+ * there's a custom method here.
+ */
+ context->add_content_file(filename);
+}
+
+THEN("^the result should be only (.+) in the content list$")
+{
+ REGEX_PARAM(string, entry);
+ ScenarioScope<Context> context;
+ auto content = context->content_list();
+ BOOST_REQUIRE_EQUAL(content.size(), 1);
+ BOOST_CHECK_EQUAL(content.front(), entry);
+}
+
diff --git a/features/support/env.rb b/features/support/env.rb
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/features/support/env.rb
diff --git a/features/wscript b/features/wscript
new file mode 100644
index 000000000..4b2d0b283
--- /dev/null
+++ b/features/wscript
@@ -0,0 +1,40 @@
+#
+# 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/>.
+#
+
+
+def configure(conf):
+ conf.env['LIB_CUCUMBER'] = 'cucumber-cpp'
+
+ conf.check_cxx(fragment="""
+ #include <cucumber-cpp/generic.hpp>\n
+ #include <cucumber-cpp/autodetect.hpp>\n
+ int main() { return 0; }\n
+ """,
+ msg='Checking for cucumber-cpp library',
+ uselib_store='CUCUMBER_CPP')
+
+
+def build(bld):
+ obj = bld(features='cxx cxxprogram')
+ obj.name = 'dcpomatic_cucumber'
+ obj.uselib = 'CUCUMBER CUCUMBER_CPP BOOST_FILESYSTEM BOOST_THREAD BOOST_REGEX BOOST_THREAD BOOST_TEST WXWIDGETS DCP '
+ obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE SWRESAMPLE '
+ obj.use = 'libdcpomatic2'
+ obj.source = 'step_definitions/dcpomatic.cc'
+ obj.target = obj.name