From 12be69065329a6e4ba464c244b5bcb9d9bec0adc Mon Sep 17 00:00:00 2001 From: Philipp Kaeser Date: Wed, 11 Dec 2024 21:59:44 +0100 Subject: [PATCH] Makes wlmtk_window_t tests use wlmtk_util_test_listener_t. --- src/toolkit/window.c | 90 ++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 57 deletions(-) diff --git a/src/toolkit/window.c b/src/toolkit/window.c index 9f1372f..a18454d 100644 --- a/src/toolkit/window.c +++ b/src/toolkit/window.c @@ -1253,13 +1253,6 @@ const bs_test_case_t wlmtk_window_test_cases[] = { { 0, NULL, NULL } }; -/** For testing: Tracks whether handle_state_change was called. */ -static bool _wlmtk_window_test_handle_state_changed_called; - -static void _wlmtk_window_test_handle_state_changed( - struct wl_listener *listener_ptr, - void *data_ptr); - /* ------------------------------------------------------------------------- */ /** Tests setup and teardown. */ void test_create_destroy(bs_test_t *test_ptr) @@ -1428,17 +1421,15 @@ void test_server_side_decorated_properties(bs_test_t *test_ptr) void test_maximize(bs_test_t *test_ptr) { struct wlr_box box; - struct wl_listener listener; + wlmtk_util_test_listener_t l; wlmtk_workspace_t *ws_ptr = wlmtk_workspace_create_for_test(1024, 768, 0); BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, ws_ptr); wlmtk_fake_window_t *fw_ptr = wlmtk_fake_window_create(); BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, fw_ptr); - wlmtk_util_connect_listener_signal( - &wlmtk_window_events(fw_ptr->window_ptr)->state_changed, - &listener, - _wlmtk_window_test_handle_state_changed); + wlmtk_util_connect_test_listener( + &wlmtk_window_events(fw_ptr->window_ptr)->state_changed, &l); // Window must be mapped to get maximized: Need workspace dimensions. wlmtk_workspace_map_window(ws_ptr, fw_ptr->window_ptr); @@ -1470,11 +1461,10 @@ void test_maximize(bs_test_t *test_ptr) BS_TEST_VERIFY_EQ(test_ptr, 100, box.height); // Maximize. - _wlmtk_window_test_handle_state_changed_called = false; wlmtk_window_request_maximized(fw_ptr->window_ptr, true); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_maximized(fw_ptr->window_ptr)); wlmtk_fake_window_commit_size(fw_ptr); - BS_TEST_VERIFY_FALSE(test_ptr, _wlmtk_window_test_handle_state_changed_called); + BS_TEST_VERIFY_EQ(test_ptr, 0, l.calls); wlmtk_window_commit_maximized(fw_ptr->window_ptr, true); box = wlmtk_window_get_position_and_size(fw_ptr->window_ptr); BS_TEST_VERIFY_EQ(test_ptr, 0, box.x); @@ -1482,8 +1472,8 @@ void test_maximize(bs_test_t *test_ptr) BS_TEST_VERIFY_EQ(test_ptr, 960, box.width); BS_TEST_VERIFY_EQ(test_ptr, 704, box.height); BS_TEST_VERIFY_TRUE(test_ptr, wlmtk_window_is_maximized(fw_ptr->window_ptr)); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); + wlmtk_util_clear_test_listener(&l); // A second commit: should not overwrite the organic dimension. wlmtk_fake_window_commit_size(fw_ptr); @@ -1492,7 +1482,7 @@ void test_maximize(bs_test_t *test_ptr) wlmtk_window_request_maximized(fw_ptr->window_ptr, false); BS_TEST_VERIFY_TRUE(test_ptr, wlmtk_window_is_maximized(fw_ptr->window_ptr)); wlmtk_fake_window_commit_size(fw_ptr); - BS_TEST_VERIFY_FALSE(test_ptr, _wlmtk_window_test_handle_state_changed_called); + BS_TEST_VERIFY_EQ(test_ptr, 0, l.calls); wlmtk_window_commit_maximized(fw_ptr->window_ptr, false); box = wlmtk_window_get_position_and_size(fw_ptr->window_ptr); BS_TEST_VERIFY_EQ(test_ptr, 50, box.x); @@ -1500,7 +1490,7 @@ void test_maximize(bs_test_t *test_ptr) BS_TEST_VERIFY_EQ(test_ptr, 200, box.width); BS_TEST_VERIFY_EQ(test_ptr, 100, box.height); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_maximized(fw_ptr->window_ptr)); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); // TODO(kaeser@gubbe.ch): Define what should happen when a maximized // window is moved. Should it lose maximization? Should it not move? @@ -1508,7 +1498,7 @@ void test_maximize(bs_test_t *test_ptr) // Window Maker keeps maximization, but it's ... odd. wlmtk_workspace_unmap_window(ws_ptr, fw_ptr->window_ptr); - wlmtk_util_disconnect_listener(&listener); + wlmtk_util_disconnect_test_listener(&l); wlmtk_fake_window_destroy(fw_ptr); wlmtk_workspace_destroy(ws_ptr); } @@ -1518,17 +1508,15 @@ void test_maximize(bs_test_t *test_ptr) void test_fullscreen(bs_test_t *test_ptr) { struct wlr_box box; - struct wl_listener listener; + wlmtk_util_test_listener_t l; wlmtk_workspace_t *ws_ptr = wlmtk_workspace_create_for_test(1024, 768, 0); BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, ws_ptr); wlmtk_fake_window_t *fw_ptr = wlmtk_fake_window_create(); BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, fw_ptr); - wlmtk_util_connect_listener_signal( - &wlmtk_window_events(fw_ptr->window_ptr)->state_changed, - &listener, - _wlmtk_window_test_handle_state_changed); + wlmtk_util_connect_test_listener( + &wlmtk_window_events(fw_ptr->window_ptr)->state_changed, &l); wlmtk_window_set_server_side_decorated(fw_ptr->window_ptr, true); wlmtk_workspace_map_window(ws_ptr, fw_ptr->window_ptr); @@ -1550,13 +1538,13 @@ void test_fullscreen(bs_test_t *test_ptr) BS_TEST_VERIFY_FALSE(test_ptr, fw_ptr->window_ptr->inorganic_sizing); // Request fullscreen. Does not take immediate effect. - _wlmtk_window_test_handle_state_changed_called = false; + wlmtk_window_request_fullscreen(fw_ptr->window_ptr, true); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_fullscreen(fw_ptr->window_ptr)); BS_TEST_VERIFY_TRUE( test_ptr, wlmtk_titlebar_is_activated(fw_ptr->window_ptr->titlebar_ptr)); - BS_TEST_VERIFY_FALSE(test_ptr, _wlmtk_window_test_handle_state_changed_called); + BS_TEST_VERIFY_EQ(test_ptr, 0, l.calls); // Only after "commit", it will take effect. wlmtk_fake_window_commit_size(fw_ptr); @@ -1567,8 +1555,8 @@ void test_fullscreen(bs_test_t *test_ptr) BS_TEST_VERIFY_EQ(test_ptr, 0, box.y); BS_TEST_VERIFY_EQ(test_ptr, 1024, box.width); BS_TEST_VERIFY_EQ(test_ptr, 768, box.height); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); + wlmtk_util_clear_test_listener(&l); BS_TEST_VERIFY_TRUE(test_ptr, fw_ptr->fake_content_ptr->activated); BS_TEST_VERIFY_EQ( @@ -1583,7 +1571,7 @@ void test_fullscreen(bs_test_t *test_ptr) // Request to end fullscreen. Not taking immediate effect. wlmtk_window_request_fullscreen(fw_ptr->window_ptr, false); BS_TEST_VERIFY_TRUE(test_ptr, wlmtk_window_is_fullscreen(fw_ptr->window_ptr)); - BS_TEST_VERIFY_FALSE(test_ptr, _wlmtk_window_test_handle_state_changed_called); + BS_TEST_VERIFY_EQ(test_ptr, 0, l.calls); // Takes effect after commit. We'll want the same position as before. wlmtk_fake_window_commit_size(fw_ptr); @@ -1603,15 +1591,14 @@ void test_fullscreen(bs_test_t *test_ptr) test_ptr, fw_ptr->window_ptr, wlmtk_workspace_get_activated_window(ws_ptr)); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); BS_TEST_VERIFY_TRUE(test_ptr, fw_ptr->window_ptr->server_side_decorated); BS_TEST_VERIFY_NEQ(test_ptr, NULL, fw_ptr->window_ptr->titlebar_ptr); BS_TEST_VERIFY_NEQ(test_ptr, NULL, fw_ptr->window_ptr->resizebar_ptr); wlmtk_workspace_unmap_window(ws_ptr, fw_ptr->window_ptr); - wlmtk_util_disconnect_listener(&listener); + wlmtk_util_disconnect_test_listener(&l); wlmtk_fake_window_destroy(fw_ptr); wlmtk_workspace_destroy(ws_ptr); } @@ -1665,17 +1652,15 @@ void test_fullscreen_unmap(bs_test_t *test_ptr) /** Verifies that window shading hides the element and raises signal. */ void test_shade(bs_test_t *test_ptr) { - struct wl_listener listener; + wlmtk_util_test_listener_t l; wlmtk_fake_window_t *fw_ptr = wlmtk_fake_window_create(); BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, fw_ptr); - wlmtk_util_connect_listener_signal( - &wlmtk_window_events(fw_ptr->window_ptr)->state_changed, - &listener, - _wlmtk_window_test_handle_state_changed); + wlmtk_util_connect_test_listener( + &wlmtk_window_events(fw_ptr->window_ptr)->state_changed, &l); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_shaded(fw_ptr->window_ptr)); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 0, l.calls); // Shading only works on server-side-decorated windows. wlmtk_window_set_server_side_decorated(fw_ptr->window_ptr, true); @@ -1685,32 +1670,32 @@ void test_shade(bs_test_t *test_ptr) BS_TEST_VERIFY_FALSE( test_ptr, wlmtk_content_element(&fw_ptr->fake_content_ptr->content)->visible); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); + wlmtk_util_clear_test_listener(&l); wlmtk_window_request_shaded(fw_ptr->window_ptr, false); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_shaded(fw_ptr->window_ptr)); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); + wlmtk_util_clear_test_listener(&l); // Shading not supported on client-side decoration. Must be disabled. wlmtk_window_request_shaded(fw_ptr->window_ptr, true); BS_TEST_VERIFY_TRUE(test_ptr, wlmtk_window_is_shaded(fw_ptr->window_ptr)); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); + wlmtk_util_clear_test_listener(&l); wlmtk_window_set_server_side_decorated(fw_ptr->window_ptr, false); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_shaded(fw_ptr->window_ptr)); - BS_TEST_VERIFY_TRUE(test_ptr, _wlmtk_window_test_handle_state_changed_called); - _wlmtk_window_test_handle_state_changed_called = false; + BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls); + wlmtk_util_clear_test_listener(&l); // Verify that 'shading' on client decorations does not do anything. wlmtk_window_set_server_side_decorated(fw_ptr->window_ptr, false); wlmtk_window_request_shaded(fw_ptr->window_ptr, true); BS_TEST_VERIFY_FALSE(test_ptr, wlmtk_window_is_shaded(fw_ptr->window_ptr)); - BS_TEST_VERIFY_FALSE(test_ptr, _wlmtk_window_test_handle_state_changed_called); + BS_TEST_VERIFY_EQ(test_ptr, 0, l.calls); - wlmtk_util_disconnect_listener(&listener); + wlmtk_util_disconnect_test_listener(&l); wlmtk_fake_window_destroy(fw_ptr); } @@ -1723,13 +1708,4 @@ void test_fake(bs_test_t *test_ptr) wlmtk_fake_window_destroy(fake_window_ptr); } -/* ------------------------------------------------------------------------- */ -/** Reports a state change. */ -void _wlmtk_window_test_handle_state_changed( - __UNUSED__ struct wl_listener *listener_ptr, - __UNUSED__ void *data_ptr) -{ - _wlmtk_window_test_handle_state_changed_called = true; -} - /* == End of window.c ====================================================== */