<div dir="ltr"><div>ping<br><br></div>tests for the patch that were pushed few days ago (<a href="http://cgit.freedesktop.org/wayland/wayland/commit/?id=886b09c9a3a9d8672039f09fe7eaf3f2b2b012ca">886b09c9a3a9d8672039f09fe7eaf3f2b2b012ca</a>)</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On 26 May 2014 17:04, Marek Chalupa <span dir="ltr"><<a href="mailto:mchqwerty@gmail.com" target="_blank">mchqwerty@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Test posting errors to one and more clients.<br>
---<br>
tests/display-test.c | 246 +++++++++++++++++++++++++++++++++++++++++++++++++++<br>
1 file changed, 246 insertions(+)<br>
<br>
diff --git a/tests/display-test.c b/tests/display-test.c<br>
index 844a649..e212942 100644<br>
--- a/tests/display-test.c<br>
+++ b/tests/display-test.c<br>
@@ -34,7 +34,9 @@<br>
<br>
#include "wayland-private.h"<br>
#include "wayland-server.h"<br>
+#include "wayland-client.h"<br>
#include "test-runner.h"<br>
+#include "test-compositor.h"<br>
<br>
struct display_destroy_listener {<br>
struct wl_listener listener;<br>
@@ -77,3 +79,247 @@ TEST(display_destroy_listener)<br>
assert(b.done);<br>
}<br>
<br>
+static void<br>
+registry_handle_globals(void *data, struct wl_registry *registry,<br>
+ uint32_t id, const char *intf, uint32_t ver)<br>
+{<br>
+ struct wl_seat **seat = data;<br>
+<br>
+ if (strcmp(intf, "wl_seat") == 0) {<br>
+ *seat = wl_registry_bind(registry, id,<br>
+ &wl_seat_interface, ver);<br>
+ assert(*seat);<br>
+ }<br>
+}<br>
+<br>
+static const struct wl_registry_listener registry_listener = {<br>
+ registry_handle_globals,<br>
+ NULL<br>
+};<br>
+<br>
+static struct wl_seat *<br>
+client_get_seat(struct client *c)<br>
+{<br>
+ struct wl_seat *seat;<br>
+ struct wl_registry *reg = wl_display_get_registry(c->wl_display);<br>
+ assert(reg);<br>
+<br>
+ wl_registry_add_listener(reg, ®istry_listener, &seat);<br>
+ wl_display_roundtrip(c->wl_display);<br>
+ assert(seat);<br>
+<br>
+ wl_registry_destroy(reg);<br>
+<br>
+ return seat;<br>
+}<br>
+<br>
+static void<br>
+check_for_error(struct client *c, struct wl_proxy *proxy)<br>
+{<br>
+ uint32_t ec, id;<br>
+ int err;<br>
+ const struct wl_interface *intf;<br>
+<br>
+ /* client should be disconnected */<br>
+ assert(wl_display_roundtrip(c->wl_display) == -1);<br>
+<br>
+ err = wl_display_get_error(c->wl_display);<br>
+ assert(err == EPROTO);<br>
+<br>
+ ec = wl_display_get_protocol_error(c->wl_display, &intf, &id);<br>
+ assert(ec == 23);<br>
+ assert(intf == &wl_seat_interface);<br>
+ assert(id == wl_proxy_get_id(proxy));<br>
+}<br>
+<br>
+static void<br>
+bind_seat(struct wl_client *client, void *data,<br>
+ uint32_t vers, uint32_t id)<br>
+{<br>
+ struct display *d = data;<br>
+ struct client_info *ci;<br>
+ struct wl_resource *res;<br>
+<br>
+ /* find the right client_info struct and save the<br>
+ * resource as its data, so that we can use it later */<br>
+ wl_list_for_each(ci, &d->clients, link) {<br>
+ if (ci->wl_client == client)<br>
+ break;<br>
+ }<br>
+<br>
+ res = wl_resource_create(client, &wl_seat_interface, vers, id);<br>
+ assert(res);<br>
+<br>
+ ci->data = res;<br>
+}<br>
+<br>
+static void<br>
+post_error_main(void)<br>
+{<br>
+ struct client *c = client_connect();<br>
+ struct wl_seat *seat = client_get_seat(c);<br>
+<br>
+ /* stop display so that it can post the error.<br>
+ * The function should return -1, because of the posted error */<br>
+ assert(stop_display(c, 1) == -1);<br>
+<br>
+ /* display should have posted error, check it! */<br>
+ check_for_error(c, (struct wl_proxy *) seat);<br>
+<br>
+ /* don't call client_disconnect(c), because then the test would be<br>
+ * aborted due to checks for error in this function */<br>
+ wl_proxy_destroy((struct wl_proxy *) seat);<br>
+ wl_proxy_destroy((struct wl_proxy *) c->tc);<br>
+ wl_display_disconnect(c->wl_display);<br>
+}<br>
+<br>
+TEST(post_error_to_one_client)<br>
+{<br>
+ struct display *d = display_create();<br>
+ struct client_info *cl;<br>
+<br>
+ wl_global_create(d->wl_display, &wl_seat_interface,<br>
+ 1, d, bind_seat);<br>
+<br>
+ cl = client_create(d, post_error_main);<br>
+ display_run(d);<br>
+<br>
+ /* the display was stopped by client, so it can<br>
+ * proceed in the code and post an error */<br>
+ assert(cl->data);<br>
+ wl_resource_post_error((struct wl_resource *) cl->data,<br>
+ 23, "Dummy error");<br>
+<br>
+ /* this one should be ignored */<br>
+ wl_resource_post_error((struct wl_resource *) cl->data,<br>
+ 21, "Dummy error (ignore)");<br>
+<br>
+ display_resume(d);<br>
+ display_destroy(d);<br>
+}<br>
+<br>
+static void<br>
+post_error_main2(void)<br>
+{<br>
+ struct client *c = client_connect();<br>
+ struct wl_seat *seat = client_get_seat(c);<br>
+<br>
+ /* the error should not be posted for this client */<br>
+ assert(stop_display(c, 2) >= 0);<br>
+<br>
+ wl_proxy_destroy((struct wl_proxy *) seat);<br>
+ client_disconnect(c);<br>
+}<br>
+<br>
+static void<br>
+post_error_main3(void)<br>
+{<br>
+ struct client *c = client_connect();<br>
+ struct wl_seat *seat = client_get_seat(c);<br>
+<br>
+ assert(stop_display(c, 2) == -1);<br>
+ check_for_error(c, (struct wl_proxy *) seat);<br>
+<br>
+ /* don't call client_disconnect(c), because then the test would be<br>
+ * aborted due to checks for error in this function */<br>
+ wl_proxy_destroy((struct wl_proxy *) seat);<br>
+ wl_proxy_destroy((struct wl_proxy *) c->tc);<br>
+ wl_display_disconnect(c->wl_display);<br>
+}<br>
+<br>
+/* all the testcases could be in one TEST, but splitting it<br>
+ * apart is better for debugging when the test fails */<br>
+TEST(post_error_to_one_from_two_clients)<br>
+{<br>
+ struct display *d = display_create();<br>
+ struct client_info *cl;<br>
+<br>
+ wl_global_create(d->wl_display, &wl_seat_interface,<br>
+ 1, d, bind_seat);<br>
+<br>
+ client_create(d, post_error_main2);<br>
+ cl = client_create(d, post_error_main3);<br>
+ display_run(d);<br>
+<br>
+ /* post error only to the second client */<br>
+ assert(cl->data);<br>
+ wl_resource_post_error((struct wl_resource *) cl->data,<br>
+ 23, "Dummy error");<br>
+ wl_resource_post_error((struct wl_resource *) cl->data,<br>
+ 21, "Dummy error (ignore)");<br>
+<br>
+ display_resume(d);<br>
+ display_destroy(d);<br>
+}<br>
+<br>
+/* all the testcases could be in one TEST, but splitting it<br>
+ * apart is better for debugging when the test fails */<br>
+TEST(post_error_to_two_clients)<br>
+{<br>
+ struct display *d = display_create();<br>
+ struct client_info *cl, *cl2;<br>
+<br>
+ wl_global_create(d->wl_display, &wl_seat_interface,<br>
+ 1, d, bind_seat);<br>
+<br>
+ cl = client_create(d, post_error_main3);<br>
+ cl2 = client_create(d, post_error_main3);<br>
+<br>
+ display_run(d);<br>
+<br>
+ /* Try to send the error to both clients */<br>
+ assert(cl->data && cl2->data);<br>
+ wl_resource_post_error((struct wl_resource *) cl->data,<br>
+ 23, "Dummy error");<br>
+ wl_resource_post_error((struct wl_resource *) cl->data,<br>
+ 21, "Dummy error (ignore)");<br>
+<br>
+ wl_resource_post_error((struct wl_resource *) cl2->data,<br>
+ 23, "Dummy error");<br>
+ wl_resource_post_error((struct wl_resource *) cl2->data,<br>
+ 21, "Dummy error (ignore)");<br>
+<br>
+ display_resume(d);<br>
+ display_destroy(d);<br>
+}<br>
+<br>
+static void<br>
+post_nomem_main(void)<br>
+{<br>
+ struct client *c = client_connect();<br>
+ struct wl_seat *seat = client_get_seat(c);<br>
+<br>
+ assert(stop_display(c, 1) == -1);<br>
+ assert(wl_display_get_error(c->wl_display) == ENOMEM);<br>
+<br>
+ wl_proxy_destroy((struct wl_proxy *) seat);<br>
+ wl_proxy_destroy((struct wl_proxy *) c->tc);<br>
+ wl_display_disconnect(c->wl_display);<br>
+}<br>
+<br>
+TEST(post_nomem_tst)<br>
+{<br>
+ struct display *d = display_create();<br>
+ struct client_info *cl;<br>
+<br>
+ wl_global_create(d->wl_display, &wl_seat_interface,<br>
+ 1, d, bind_seat);<br>
+<br>
+ cl = client_create(d, post_nomem_main);<br>
+ display_run(d);<br>
+<br>
+ assert(cl->data);<br>
+ wl_resource_post_no_memory((struct wl_resource *) cl->data);<br>
+ display_resume(d);<br>
+<br>
+ /* first client terminated. Run it again,<br>
+ * but post no memory to client */<br>
+ cl = client_create(d, post_nomem_main);<br>
+ display_run(d);<br>
+<br>
+ assert(cl->data);<br>
+ wl_client_post_no_memory(cl->wl_client);<br>
+ display_resume(d);<br>
+<br>
+ display_destroy(d);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
</font></span></blockquote></div><br></div>