Skip to content

Commit

Permalink
Makes wlmtk_window_t tests use wlmtk_util_test_listener_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
phkaeser committed Dec 11, 2024
1 parent b38a330 commit 12be690
Showing 1 changed file with 33 additions and 57 deletions.
90 changes: 33 additions & 57 deletions src/toolkit/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1470,20 +1461,19 @@ 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);
BS_TEST_VERIFY_EQ(test_ptr, 0, box.y);
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);
Expand All @@ -1492,23 +1482,23 @@ 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);
BS_TEST_VERIFY_EQ(test_ptr, 30, box.y);
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([email protected]): Define what should happen when a maximized
// window is moved. Should it lose maximization? Should it not move?
// Or just move on?
// 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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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 ====================================================== */

0 comments on commit 12be690

Please sign in to comment.