test: expand the ei tests

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-19 11:09:55 +10:00
parent 76e5b30451
commit 8bddc3008f

View file

@ -36,9 +36,8 @@ MUNIT_TEST(test_ei_disconnect_immediately)
/* Expect the client to get a disconnect event */
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *e = ei_get_event(ei);
munit_assert_ptr_not_null(e);
munit_assert_int(ei_event_get_type(e), ==, EI_EVENT_DISCONNECT);
_cleanup_ei_event_ struct ei_event *disconnect =
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
}
return MUNIT_OK;
@ -51,6 +50,83 @@ MUNIT_TEST(test_ei_disconnect_after_connect)
peck_dispatch_until_stable(peck);
with_server(peck) {
eis_dispatch(eis);
_cleanup_eis_event_ struct eis_event *e =
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
client = eis_client_ref(eis_event_get_client(e));
eis_client_connect(client);
}
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *e =
peck_ei_next_event(ei, EI_EVENT_CONNECT);
}
with_server(peck) {
eis_client_disconnect(client);
}
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *e =
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
}
return MUNIT_OK;
}
MUNIT_TEST(test_ei_disconnect_after_add_before_received)
{
_cleanup_peck_ struct peck *peck = peck_new();
_cleanup_eis_client_ struct eis_client *client = NULL;
peck_dispatch_until_stable(peck);
with_server(peck) {
eis_dispatch(eis);
_cleanup_eis_event_ struct eis_event *e =
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
client = eis_client_ref(eis_event_get_client(e));
eis_client_connect(client);
}
peck_dispatch_until_stable(peck);
with_client(peck) {
_cleanup_ei_device_ struct ei_device *device = ei_device_new(ei);
ei_device_configure_name(device, __func__);
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
ei_device_add(device);
}
/* We have *not* called eis_dispatch, so the device add hasn't been
* processed by the server yet */
with_server(peck) {
eis_client_disconnect(client);
}
/* But from the POV of the client we have added our devices, so we
* must receive a Removed event. */
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *removed =
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
_cleanup_ei_event_ struct ei_event *disconnect =
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
}
return MUNIT_OK;
}
MUNIT_TEST(test_ei_disconnect_after_add_after_received)
{
_cleanup_peck_ struct peck *peck = peck_new();
_cleanup_eis_client_ struct eis_client *client = NULL;
peck_dispatch_until_stable(peck);
with_server(peck) {
eis_dispatch(eis);
_cleanup_eis_event_ struct eis_event *e = eis_get_event(eis);
@ -60,22 +136,135 @@ MUNIT_TEST(test_ei_disconnect_after_connect)
eis_client_connect(client);
}
peck_dispatch_until_stable(peck);
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *e = ei_get_event(ei);
munit_assert_ptr_not_null(e);
munit_assert_int(ei_event_get_type(e), ==, EI_EVENT_CONNECT);
_cleanup_ei_device_ struct ei_device *device = ei_device_new(ei);
ei_device_configure_name(device, __func__);
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
ei_device_add(device);
}
/* Receive the Added event but don't actually add the device */
peck_dispatch_eis(peck);
with_server(peck) {
eis_client_disconnect(client);
}
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *e = ei_get_event(ei);
_cleanup_ei_event_ struct ei_event *removed =
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
_cleanup_ei_event_ struct ei_event *disconnect =
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
}
return MUNIT_OK;
}
MUNIT_TEST(test_ei_disconnect_after_remove_before_received)
{
_cleanup_peck_ struct peck *peck = peck_new();
_cleanup_eis_client_ struct eis_client *client = NULL;
_cleanup_ei_device_ struct ei_device *device = NULL;
peck_dispatch_until_stable(peck);
with_server(peck) {
eis_dispatch(eis);
_cleanup_eis_event_ struct eis_event *e = eis_get_event(eis);
munit_assert_ptr_not_null(e);
munit_assert_int(ei_event_get_type(e), ==, EI_EVENT_DISCONNECT);
munit_assert_int(eis_event_get_type(e), ==, EIS_EVENT_CLIENT_CONNECT);
client = eis_client_ref(eis_event_get_client(e));
eis_client_connect(client);
}
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
peck_dispatch_until_stable(peck);
with_client(peck) {
device = ei_device_new(ei);
ei_device_configure_name(device, __func__);
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
ei_device_add(device);
}
/* server has the device now */
peck_dispatch_until_stable(peck);
with_client(peck) {
_cleanup_ei_event_ struct ei_event *added =
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
ei_device_remove(device);
}
/* Disconnect before the server processed the Removed message. This
* does **not** trigger a EI_EVENT_REMOVED, the device has already
* been removed by the client.
*/
with_server(peck) {
eis_client_disconnect(client);
}
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *disconnect =
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
}
return MUNIT_OK;
}
MUNIT_TEST(test_ei_disconnect_after_remove_after_received)
{
_cleanup_peck_ struct peck *peck = peck_new();
_cleanup_eis_client_ struct eis_client *client = NULL;
_cleanup_ei_device_ struct ei_device *device = NULL;
peck_dispatch_until_stable(peck);
with_server(peck) {
eis_dispatch(eis);
_cleanup_eis_event_ struct eis_event *e = eis_get_event(eis);
munit_assert_ptr_not_null(e);
munit_assert_int(eis_event_get_type(e), ==, EIS_EVENT_CLIENT_CONNECT);
client = eis_client_ref(eis_event_get_client(e));
eis_client_connect(client);
}
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
peck_dispatch_until_stable(peck);
with_client(peck) {
device = ei_device_new(ei);
ei_device_configure_name(device, __func__);
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
ei_device_add(device);
}
/* server has the device now */
peck_dispatch_until_stable(peck);
with_client(peck) {
_cleanup_ei_event_ struct ei_event *added =
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
ei_device_remove(device);
}
/* Disconnect after the server processed the Removed message. This
* does **not** trigger a EI_EVENT_REMOVED, the device has already
* been removed by the client.
*/
peck_dispatch_eis(peck);
with_server(peck) {
eis_client_disconnect(client);
}
with_client(peck) {
ei_dispatch(ei);
_cleanup_ei_event_ struct ei_event *disconnect =
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
}
return MUNIT_OK;