From c97c409c50a021c2ef1d4f58f8e13a8ed9a8ee72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 2 Apr 2020 19:12:39 +0200 Subject: [PATCH] tests/test-runner: Add 'move' and 'assert_position' Make it possible for tests to move the windows, and check their positions. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1171 --- src/tests/test-runner.c | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index 7d7c3f6e5..f1c605ad6 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -592,6 +592,22 @@ test_case_do (TestCase *test, argv[2], argv[3], NULL)) return FALSE; } + else if (strcmp (argv[0], "move") == 0) + { + if (argc != 4) + BAD_COMMAND("usage: %s / x y", argv[0]); + + TestClient *client; + const char *window_id; + if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) + return FALSE; + + MetaWindow *window = test_client_find_window (client, window_id, error); + if (!window) + return FALSE; + + meta_window_move_frame (window, TRUE, atoi (argv[2]), atoi (argv[3])); + } else if (strcmp (argv[0], "tile") == 0) { if (argc != 3) @@ -785,6 +801,37 @@ test_case_do (TestCase *test, error)) return FALSE; } + else if (strcmp (argv[0], "assert_position") == 0) + { + if (argc != 4) + { + BAD_COMMAND("usage: %s / ", + argv[0]); + } + + TestClient *client; + const char *window_id; + if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) + return FALSE; + + MetaWindow *window = test_client_find_window (client, window_id, error); + if (!window) + return FALSE; + + MetaRectangle frame_rect; + meta_window_get_frame_rect (window, &frame_rect); + int x = atoi (argv[2]); + int y = atoi (argv[3]); + if (frame_rect.x != x || frame_rect.y != y) + { + g_set_error (error, + TEST_RUNNER_ERROR, + TEST_RUNNER_ERROR_ASSERTION_FAILED, + "Expected window position (%d, %d) doesn't match (%d, %d)", + x, y, frame_rect.x, frame_rect.y); + return FALSE; + } + } else { BAD_COMMAND("Unknown command %s", argv[0]);