Change the API to pass an "void *" argument to the client main
function, allowing the caller to call the same main function with
different input.

A helper (client_create_noarg) is added for when no argument is passed,
and the existing test cases are changed to use this function instead.

Signed-off-by: Jonas Ådahl <[email protected]>
---
 tests/connection-test.c |  4 ++--
 tests/display-test.c    | 24 ++++++++++++------------
 tests/queue-test.c      |  6 +++---
 tests/sanity-test.c     | 20 ++++++++++----------
 tests/test-compositor.c | 17 +++++++++++------
 tests/test-compositor.h | 11 +++++++----
 6 files changed, 45 insertions(+), 37 deletions(-)

diff --git a/tests/connection-test.c b/tests/connection-test.c
index e9832b7..5d97fd9 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -614,7 +614,7 @@ TEST(closure_leaks)
 {
        struct display *d = display_create();
 
-       client_create(d, leak_closure);
+       client_create_noarg(d, leak_closure);
        display_run(d);
 
        display_destroy(d);
@@ -645,7 +645,7 @@ TEST(closure_leaks_after_error)
        struct display *d = display_create();
        struct client_info *cl;
 
-       cl = client_create(d, leak_after_error);
+       cl = client_create_noarg(d, leak_after_error);
        display_run(d);
 
        wl_client_post_no_memory(cl->wl_client);
diff --git a/tests/display-test.c b/tests/display-test.c
index 161a402..f931c13 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -95,7 +95,7 @@ empty_client(void)
 TEST(tc_leaks_tests)
 {
        struct display *d = display_create();
-       client_create(d, empty_client);
+       client_create_noarg(d, empty_client);
        display_run(d);
        display_destroy(d);
 }
@@ -209,7 +209,7 @@ TEST(post_error_to_one_client)
        wl_global_create(d->wl_display, &wl_seat_interface,
                         1, d, bind_seat);
 
-       cl = client_create(d, post_error_main);
+       cl = client_create_noarg(d, post_error_main);
        display_run(d);
 
        /* the display was stopped by client, so it can
@@ -264,8 +264,8 @@ TEST(post_error_to_one_from_two_clients)
        wl_global_create(d->wl_display, &wl_seat_interface,
                         1, d, bind_seat);
 
-       client_create(d, post_error_main2);
-       cl = client_create(d, post_error_main3);
+       client_create_noarg(d, post_error_main2);
+       cl = client_create_noarg(d, post_error_main3);
        display_run(d);
 
        /* post error only to the second client */
@@ -289,8 +289,8 @@ TEST(post_error_to_two_clients)
        wl_global_create(d->wl_display, &wl_seat_interface,
                         1, d, bind_seat);
 
-       cl = client_create(d, post_error_main3);
-       cl2 = client_create(d, post_error_main3);
+       cl = client_create_noarg(d, post_error_main3);
+       cl2 = client_create_noarg(d, post_error_main3);
 
        display_run(d);
 
@@ -331,7 +331,7 @@ TEST(post_nomem_tst)
        wl_global_create(d->wl_display, &wl_seat_interface,
                         1, d, bind_seat);
 
-       cl = client_create(d, post_nomem_main);
+       cl = client_create_noarg(d, post_nomem_main);
        display_run(d);
 
        assert(cl->data);
@@ -340,7 +340,7 @@ TEST(post_nomem_tst)
 
        /* first client terminated. Run it again,
         * but post no memory to client */
-       cl = client_create(d, post_nomem_main);
+       cl = client_create_noarg(d, post_nomem_main);
        display_run(d);
 
        assert(cl->data);
@@ -447,7 +447,7 @@ TEST(threading_errors_tst)
 {
        struct display *d = display_create();
 
-       client_create(d, threading_post_err);
+       client_create_noarg(d, threading_post_err);
        display_run(d);
 
        display_destroy(d);
@@ -502,7 +502,7 @@ TEST(threading_cancel_read_tst)
 {
        struct display *d = display_create();
 
-       client_create(d, threading_cancel_read);
+       client_create_noarg(d, threading_cancel_read);
        display_run(d);
 
        display_destroy(d);
@@ -542,7 +542,7 @@ threading_read_eagain(void)
 TEST(threading_read_eagain_tst)
 {
        struct display *d = display_create();
-       client_create(d, threading_read_eagain);
+       client_create_noarg(d, threading_read_eagain);
 
        display_run(d);
 
@@ -604,7 +604,7 @@ TEST(threading_read_after_error_tst)
 {
        struct display *d = display_create();
 
-       client_create(d, threading_read_after_error);
+       client_create_noarg(d, threading_read_after_error);
        display_run(d);
 
        display_destroy(d);
diff --git a/tests/queue-test.c b/tests/queue-test.c
index dc1a01d..02865ae 100644
--- a/tests/queue-test.c
+++ b/tests/queue-test.c
@@ -230,7 +230,7 @@ TEST(queue_proxy_destroy)
 
        test_set_timeout(2);
 
-       client_create(d, client_test_proxy_destroy);
+       client_create_noarg(d, client_test_proxy_destroy);
        display_run(d);
 
        display_destroy(d);
@@ -242,7 +242,7 @@ TEST(queue_multiple_queues)
 
        test_set_timeout(2);
 
-       client_create(d, client_test_multiple_queues);
+       client_create_noarg(d, client_test_multiple_queues);
        display_run(d);
 
        display_destroy(d);
@@ -254,7 +254,7 @@ TEST(queue_roundtrip)
 
        test_set_timeout(2);
 
-       client_create(d, client_test_queue_roundtrip);
+       client_create_noarg(d, client_test_queue_roundtrip);
        display_run(d);
 
        display_destroy(d);
diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index 65d986d..7a93da3 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -119,7 +119,7 @@ FAIL_TEST(sanity_malloc_indirect)
 FAIL_TEST(tc_client_memory_leaks)
 {
        struct display *d = display_create();
-       client_create(d, sanity_malloc_direct);
+       client_create_noarg(d, sanity_malloc_direct);
        display_run(d);
        display_destroy(d);
 }
@@ -127,7 +127,7 @@ FAIL_TEST(tc_client_memory_leaks)
 FAIL_TEST(tc_client_memory_leaks2)
 {
        struct display *d = display_create();
-       client_create(d, sanity_malloc_indirect);
+       client_create_noarg(d, sanity_malloc_indirect);
        display_run(d);
        display_destroy(d);
 }
@@ -195,11 +195,11 @@ TEST(tc_client_no_fd_leaks)
        struct display *d = display_create();
 
        /* Client which does not consume the WAYLAND_DISPLAY socket. */
-       client_create(d, sanity_fd_no_leak);
+       client_create_noarg(d, sanity_fd_no_leak);
        display_run(d);
 
        /* Client which does consume the WAYLAND_DISPLAY socket. */
-       client_create(d, sanity_client_no_leak);
+       client_create_noarg(d, sanity_client_no_leak);
        display_run(d);
 
        display_destroy(d);
@@ -209,7 +209,7 @@ FAIL_TEST(tc_client_fd_leaks)
 {
        struct display *d = display_create();
 
-       client_create(d, sanity_fd_leak);
+       client_create_noarg(d, sanity_fd_leak);
        display_run(d);
 
        display_destroy(d);
@@ -219,7 +219,7 @@ FAIL_TEST(tc_client_fd_leaks_exec)
 {
        struct display *d = display_create();
 
-       client_create(d, sanity_fd_leak);
+       client_create_noarg(d, sanity_fd_leak);
        display_run(d);
 
        display_destroy(d);
@@ -263,7 +263,7 @@ TEST(timeout_turnoff)
 FAIL_TEST(tc_timeout_tst)
 {
        struct display *d = display_create();
-       client_create(d, timeout_tst);
+       client_create_noarg(d, timeout_tst);
        display_run(d);
        display_destroy(d);
 }
@@ -271,7 +271,7 @@ FAIL_TEST(tc_timeout_tst)
 FAIL_TEST(tc_timeout2_tst)
 {
        struct display *d = display_create();
-       client_create(d, timeout_reset_tst);
+       client_create_noarg(d, timeout_reset_tst);
        display_run(d);
        display_destroy(d);
 }
@@ -280,10 +280,10 @@ TEST(tc_timeout3_tst)
 {
        struct display *d = display_create();
 
-       client_create(d, timeout2_tst);
+       client_create_noarg(d, timeout2_tst);
        display_run(d);
 
-       client_create(d, timeout_turnoff);
+       client_create_noarg(d, timeout_turnoff);
        display_run(d);
 
        display_destroy(d);
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 965074b..b01e8af 100644
--- a/tests/test-compositor.c
+++ b/tests/test-compositor.c
@@ -151,7 +151,8 @@ client_destroyed(struct wl_listener *listener, void *data)
 }
 
 static void
-run_client(void (*client_main)(void), int wayland_sock, int client_pipe)
+run_client(void (*client_main)(void *data), void *data,
+          int wayland_sock, int client_pipe)
 {
        char s[8];
        int cur_alloc, cur_fds;
@@ -170,7 +171,7 @@ run_client(void (*client_main)(void), int wayland_sock, int 
client_pipe)
        cur_alloc = get_current_alloc_num();
        cur_fds = count_open_fds();
 
-       client_main();
+       client_main(data);
 
        /* Clients using wl_display_connect() will end up closing the socket
         * passed in through the WAYLAND_SOCKET environment variable. When
@@ -185,7 +186,8 @@ run_client(void (*client_main)(void), int wayland_sock, int 
client_pipe)
 
 static struct client_info *
 display_create_client(struct display *d,
-                     void (*client_main)(void),
+                     void (*client_main)(void *data),
+                     void *data,
                      const char *name)
 {
        int pipe_cli[2];
@@ -205,7 +207,7 @@ display_create_client(struct display *d,
                close(sock_wayl[1]);
                close(pipe_cli[1]);
 
-               run_client(client_main, sock_wayl[0], pipe_cli[0]);
+               run_client(client_main, data, sock_wayl[0], pipe_cli[0]);
 
                close(sock_wayl[0]);
                close(pipe_cli[0]);
@@ -246,11 +248,14 @@ display_create_client(struct display *d,
 }
 
 struct client_info *
-client_create_with_name(struct display *d, void (*client_main)(void),
+client_create_with_name(struct display *d,
+                       void (*client_main)(void *data), void *data,
                        const char *name)
 {
        int can_continue = 1;
-       struct client_info *cl = display_create_client(d, client_main, name);
+       struct client_info *cl = display_create_client(d,
+                                                      client_main, data,
+                                                      name);
 
        /* let the show begin! */
        assert(write(cl->pipe, &can_continue, sizeof(int)) == sizeof(int));
diff --git a/tests/test-compositor.h b/tests/test-compositor.h
index c97eb96..526e912 100644
--- a/tests/test-compositor.h
+++ b/tests/test-compositor.h
@@ -78,8 +78,8 @@ int stop_display(struct client *, int);
  *    wl_global_create(d->wl_display, ...);
  *    ... other setups ...
  *
- *    client_create(d, client_main);
- *    client_create(d, client_main2);
+ *    client_create(d, client_main, data);
+ *    client_create(d, client_main2, data);
  *
  *    display_run(d);
  *    display_destroy(d);
@@ -95,6 +95,9 @@ void display_run(struct display *d);
 void display_resume(struct display *d);
 
 struct client_info *client_create_with_name(struct display *d,
-                                           void (*client_main)(void),
+                                           void (*client_main)(void *data),
+                                           void *data,
                                            const char *name);
-#define client_create(d, c) client_create_with_name((d), (c), (#c))
+#define client_create(d, c, data) client_create_with_name((d), (c), data, (#c))
+#define client_create_noarg(d, c) \
+       client_create_with_name((d), (void(*)(void *)) (c), NULL, (#c))
-- 
2.4.3

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to