[mutter/wip/3v1n0/run-tests-in-ci: 7/14] test-runner: Add assert_focused command
- From: Marco Trevisan <marcotrevi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/3v1n0/run-tests-in-ci: 7/14] test-runner: Add assert_focused command
- Date: Wed, 14 Nov 2018 08:20:29 +0000 (UTC)
commit ef3ea0a59c253d9f27b508d13b231c9c29fec121
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Tue Nov 13 01:37:14 2018 -0600
test-runner: Add assert_focused command
This allows to verify which window should have the focus, which might not
be the same as the top of the stack.
src/tests/test-runner.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
---
diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c
index 612d54cc5..feeb7466f 100644
--- a/src/tests/test-runner.c
+++ b/src/tests/test-runner.c
@@ -237,6 +237,38 @@ test_case_assert_stacking (TestCase *test,
return *error == NULL;
}
+static gboolean
+test_case_assert_focused (TestCase *test,
+ const char *expected_window,
+ GError **error)
+{
+ MetaDisplay *display = meta_get_display ();
+
+ if (!display->focus_window)
+ {
+ if (g_ascii_strcasecmp (expected_window, "null") != 0 &&
+ g_ascii_strcasecmp (expected_window, "none") != 0 &&
+ g_strcmp0 (expected_window, "0") != 0)
+ {
+ g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED,
+ "focus: expected='%s', actual='NONE'", expected_window);
+ }
+ }
+ else
+ {
+ const char *focused = display->focus_window->title;
+ if (g_str_has_prefix (focused, "test/"))
+ focused += 5;
+
+ if (g_strcmp0 (focused, expected_window) != 0)
+ g_set_error (error, TEST_RUNNER_ERROR, TEST_RUNNER_ERROR_ASSERTION_FAILED,
+ "stacking: expected='%s', actual='%s'",
+ expected_window, focused);
+ }
+
+ return *error == NULL;
+}
+
static gboolean
test_case_check_xserver_stacking (TestCase *test,
GError **error)
@@ -523,6 +555,11 @@ test_case_do (TestCase *test,
if (!test_case_check_xserver_stacking (test, error))
return FALSE;
}
+ else if (strcmp (argv[0], "assert_focused") == 0)
+ {
+ if (!test_case_assert_focused (test, argv[1], error))
+ return FALSE;
+ }
else
{
BAD_COMMAND("Unknown command %s", argv[0]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]