Skip to content

Commit

Permalink
Makes wlmtk_root_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 be8b56d commit 6b3f874
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions src/toolkit/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,24 +666,6 @@ const bs_test_case_t wlmtk_root_test_cases[] = {
{ 0, NULL, NULL }
};

/** Helper struct for listeners in tests. */
typedef struct {
/** Listener. */
struct wl_listener listener;
/** Will be set to the `data_ptr` arg of the callback. */
wlmtk_workspace_t *workspace_ptr;
} _wlmtk_root_test_workspace_t;

/** Test helper callback for @ref wlmtk_root_events_t::workspace_changed. */
static void _wlmtk_root_test_workspace_changed_handler(
struct wl_listener *listener_ptr,
void *data_ptr)
{
_wlmtk_root_test_workspace_t *test_ws_ptr = BS_CONTAINER_OF(
listener_ptr, _wlmtk_root_test_workspace_t, listener);
test_ws_ptr->workspace_ptr = data_ptr;
}

/* ------------------------------------------------------------------------- */
/** Exercises ctor and dtor. */
void test_create_destroy(bs_test_t *test_ptr)
Expand All @@ -709,18 +691,16 @@ void test_create_destroy(bs_test_t *test_ptr)
/** Exercises workspace adding and removal. */
void test_workspaces(bs_test_t *test_ptr)
{
wlmtk_util_test_listener_t l;
struct wlr_scene *wlr_scene_ptr = wlr_scene_create();
BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, wlr_scene_ptr);
wlmtk_root_t *root_ptr = wlmtk_root_create(wlr_scene_ptr, NULL);
BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, root_ptr);
BS_TEST_VERIFY_EQ(
test_ptr, NULL, wlmtk_root_get_current_workspace(root_ptr));

_wlmtk_root_test_workspace_t test_ws = {};
wlmtk_util_connect_listener_signal(
&wlmtk_root_events(root_ptr)->workspace_changed,
&test_ws.listener,
_wlmtk_root_test_workspace_changed_handler);
wlmtk_util_connect_test_listener(
&wlmtk_root_events(root_ptr)->workspace_changed, &l);

static const wlmtk_tile_style_t tstyle = {};
wlmtk_workspace_t *ws1_ptr = wlmtk_workspace_create("1", &tstyle, NULL);
Expand All @@ -731,8 +711,8 @@ void test_workspaces(bs_test_t *test_ptr)
BS_TEST_VERIFY_TRUE(
test_ptr,
wlmtk_workspace_element(ws1_ptr)->visible);
BS_TEST_VERIFY_EQ(
test_ptr, ws1_ptr, test_ws.workspace_ptr);
BS_TEST_VERIFY_EQ(test_ptr, ws1_ptr, l.last_data_ptr);
BS_TEST_VERIFY_EQ(test_ptr, 1, l.calls);

wlmtk_workspace_t *ws2_ptr = wlmtk_workspace_create("2", &tstyle, NULL);
BS_TEST_VERIFY_NEQ_OR_RETURN(test_ptr, NULL, ws2_ptr);
Expand All @@ -753,17 +733,17 @@ void test_workspaces(bs_test_t *test_ptr)
BS_TEST_VERIFY_TRUE(
test_ptr,
wlmtk_workspace_element(ws2_ptr)->visible);
BS_TEST_VERIFY_EQ(
test_ptr, ws2_ptr, test_ws.workspace_ptr);
BS_TEST_VERIFY_EQ(test_ptr, ws2_ptr, l.last_data_ptr);
BS_TEST_VERIFY_EQ(test_ptr, 2, l.calls);

wlmtk_root_remove_workspace(root_ptr, ws2_ptr);
wlmtk_workspace_destroy(ws2_ptr);
BS_TEST_VERIFY_EQ(
test_ptr, NULL, wlmtk_root_get_current_workspace(root_ptr));
BS_TEST_VERIFY_EQ(
test_ptr, NULL, test_ws.workspace_ptr);
BS_TEST_VERIFY_EQ(test_ptr, NULL, l.last_data_ptr);
BS_TEST_VERIFY_EQ(test_ptr, 3, l.calls);

wlmtk_util_disconnect_listener(&test_ws.listener);
wlmtk_util_disconnect_test_listener(&l);
wlmtk_root_destroy(root_ptr);
wlr_scene_node_destroy(&wlr_scene_ptr->tree.node);
}
Expand Down

0 comments on commit 6b3f874

Please sign in to comment.