From f2aa64f18a44ad6343a3da42288a604fad8579f4 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 12 Dec 2012 14:26:41 +0200 Subject: [PATCH] tests: check wl_display_roundtrip() for errors Add a macro that wraps wl_display_roundtrip() and check for errors. It is a macro, so that the assert would show the relevant file and line number. This will also catch protocol errors, that would go unnoticed otherwise. All roundtrips in tests are replaced with the check. Signed-off-by: Pekka Paalanen --- tests/button-test.c | 6 +++--- tests/event-test.c | 2 +- tests/keyboard-test.c | 2 +- tests/text-test.c | 10 +++++----- tests/weston-test-client-helper.h | 3 +++ 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/button-test.c b/tests/button-test.c index ac75ee0..dc02fd4 100644 --- a/tests/button-test.c +++ b/tests/button-test.c @@ -37,19 +37,19 @@ TEST(simple_button_test) assert(pointer->state == 0); wl_test_move_pointer(client->test->wl_test, 150, 150); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(pointer->x == 50); assert(pointer->y == 50); wl_test_send_button(client->test->wl_test, BTN_LEFT, WL_POINTER_BUTTON_STATE_PRESSED); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(pointer->button == BTN_LEFT); assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED); wl_test_send_button(client->test->wl_test, BTN_LEFT, WL_POINTER_BUTTON_STATE_RELEASED); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(pointer->button == BTN_LEFT); assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED); } diff --git a/tests/event-test.c b/tests/event-test.c index ba22f3f..254517d 100644 --- a/tests/event-test.c +++ b/tests/event-test.c @@ -57,7 +57,7 @@ static void check_pointer_move(struct client *client, int x, int y) { wl_test_move_pointer(client->test->wl_test, x, y); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); check_pointer(client, x, y); } diff --git a/tests/keyboard-test.c b/tests/keyboard-test.c index 3d5d6e3..542bf4e 100644 --- a/tests/keyboard-test.c +++ b/tests/keyboard-test.c @@ -60,6 +60,6 @@ TEST(simple_keyboard_test) break; } - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); } } diff --git a/tests/text-test.c b/tests/text-test.c index 9492bd2..8994d10 100644 --- a/tests/text-test.c +++ b/tests/text-test.c @@ -161,28 +161,28 @@ TEST(text_test) /* Make sure our test surface has keyboard focus. */ wl_test_activate_surface(client->test->wl_test, client->surface->wl_surface); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(client->input->keyboard->focus == client->surface); /* Activate test model and make sure we get enter event. */ text_model_activate(text_model, client->input->wl_seat, client->surface->wl_surface); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(state.activated == 1 && state.deactivated == 0); /* Deactivate test model and make sure we get leave event. */ text_model_deactivate(text_model, client->input->wl_seat); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(state.activated == 1 && state.deactivated == 1); /* Activate test model again. */ text_model_activate(text_model, client->input->wl_seat, client->surface->wl_surface); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(state.activated == 2 && state.deactivated == 1); /* Take keyboard focus away and verify we get leave event. */ wl_test_activate_surface(client->test->wl_test, NULL); - wl_display_roundtrip(client->wl_display); + client_roundtrip(client); assert(state.activated == 2 && state.deactivated == 2); } diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index e84d3b2..27042b2 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -107,5 +107,8 @@ surface_contains(struct surface *surface, int x, int y); void move_client(struct client *client, int x, int y); +#define client_roundtrip(c) do { \ + assert(wl_display_roundtrip((c)->wl_display) >= 0); \ +} while (0) #endif -- 2.7.4