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 <ppaalanen@gmail.com>
dev
Pekka Paalanen 12 years ago committed by Kristian Høgsberg
parent 07921d791a
commit f2aa64f18a
  1. 6
      tests/button-test.c
  2. 2
      tests/event-test.c
  3. 2
      tests/keyboard-test.c
  4. 10
      tests/text-test.c
  5. 3
      tests/weston-test-client-helper.h

@ -37,19 +37,19 @@ TEST(simple_button_test)
assert(pointer->state == 0); assert(pointer->state == 0);
wl_test_move_pointer(client->test->wl_test, 150, 150); 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->x == 50);
assert(pointer->y == 50); assert(pointer->y == 50);
wl_test_send_button(client->test->wl_test, BTN_LEFT, wl_test_send_button(client->test->wl_test, BTN_LEFT,
WL_POINTER_BUTTON_STATE_PRESSED); WL_POINTER_BUTTON_STATE_PRESSED);
wl_display_roundtrip(client->wl_display); client_roundtrip(client);
assert(pointer->button == BTN_LEFT); assert(pointer->button == BTN_LEFT);
assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED); assert(pointer->state == WL_POINTER_BUTTON_STATE_PRESSED);
wl_test_send_button(client->test->wl_test, BTN_LEFT, wl_test_send_button(client->test->wl_test, BTN_LEFT,
WL_POINTER_BUTTON_STATE_RELEASED); WL_POINTER_BUTTON_STATE_RELEASED);
wl_display_roundtrip(client->wl_display); client_roundtrip(client);
assert(pointer->button == BTN_LEFT); assert(pointer->button == BTN_LEFT);
assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED); assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
} }

@ -57,7 +57,7 @@ static void
check_pointer_move(struct client *client, int x, int y) check_pointer_move(struct client *client, int x, int y)
{ {
wl_test_move_pointer(client->test->wl_test, x, 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); check_pointer(client, x, y);
} }

@ -60,6 +60,6 @@ TEST(simple_keyboard_test)
break; break;
} }
wl_display_roundtrip(client->wl_display); client_roundtrip(client);
} }
} }

@ -161,28 +161,28 @@ TEST(text_test)
/* Make sure our test surface has keyboard focus. */ /* Make sure our test surface has keyboard focus. */
wl_test_activate_surface(client->test->wl_test, wl_test_activate_surface(client->test->wl_test,
client->surface->wl_surface); client->surface->wl_surface);
wl_display_roundtrip(client->wl_display); client_roundtrip(client);
assert(client->input->keyboard->focus == client->surface); assert(client->input->keyboard->focus == client->surface);
/* Activate test model and make sure we get enter event. */ /* Activate test model and make sure we get enter event. */
text_model_activate(text_model, client->input->wl_seat, text_model_activate(text_model, client->input->wl_seat,
client->surface->wl_surface); client->surface->wl_surface);
wl_display_roundtrip(client->wl_display); client_roundtrip(client);
assert(state.activated == 1 && state.deactivated == 0); assert(state.activated == 1 && state.deactivated == 0);
/* Deactivate test model and make sure we get leave event. */ /* Deactivate test model and make sure we get leave event. */
text_model_deactivate(text_model, client->input->wl_seat); 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); assert(state.activated == 1 && state.deactivated == 1);
/* Activate test model again. */ /* Activate test model again. */
text_model_activate(text_model, client->input->wl_seat, text_model_activate(text_model, client->input->wl_seat,
client->surface->wl_surface); client->surface->wl_surface);
wl_display_roundtrip(client->wl_display); client_roundtrip(client);
assert(state.activated == 2 && state.deactivated == 1); assert(state.activated == 2 && state.deactivated == 1);
/* Take keyboard focus away and verify we get leave event. */ /* Take keyboard focus away and verify we get leave event. */
wl_test_activate_surface(client->test->wl_test, NULL); 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); assert(state.activated == 2 && state.deactivated == 2);
} }

@ -107,5 +107,8 @@ surface_contains(struct surface *surface, int x, int y);
void void
move_client(struct client *client, int x, int y); 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 #endif

Loading…
Cancel
Save