From ae6dbbe61cb934ecdaca0513845c4e0b46e9f312 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 23 Aug 2021 12:58:22 +1000 Subject: [PATCH] test: move the unhandled event type assertion out of the switch All the switch cases return early, moving it here means we can drop the default case and have the compiler warn us about missing cases. Signed-off-by: Peter Hutterer --- src/libei-proto.c | 8 +++++--- src/libeis-event.c | 9 +++++++-- test/eierpecken.c | 6 ++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libei-proto.c b/src/libei-proto.c index 77a15fe..598a67b 100644 --- a/src/libei-proto.c +++ b/src/libei-proto.c @@ -134,6 +134,8 @@ log_wire_message(struct ei *ei, const ClientMessage *msg, int error) case CLIENT_MESSAGE__MSG_##_name: message = #_name; break; switch (msg->msg_case) { + case _CLIENT_MESSAGE__MSG_IS_INT_SIZE: /* protobuf-internal thing */ + return; case CLIENT_MESSAGE__MSG__NOT_SET: abort(); MSG_STRING_CASE(CONNECT); @@ -152,10 +154,10 @@ log_wire_message(struct ei *ei, const ClientMessage *msg, int error) MSG_STRING_CASE(TOUCH_UP); MSG_STRING_CASE(CONFIGURE_NAME); MSG_STRING_CASE(CONFIGURE_CAPS); - default: - assert(!"Unimplemented message type"); - break; } + if (message == NULL) + assert(!"Unimplemented message type"); + log_debug(ei, "sending wire message %s (%s)\n", message, strerror(-error)); diff --git a/src/libeis-event.c b/src/libeis-event.c index c588ec5..f78a063 100644 --- a/src/libeis-event.c +++ b/src/libeis-event.c @@ -34,6 +34,8 @@ static void eis_event_destroy(struct eis_event *event) { + bool handled = false; + switch (event->type) { case EIS_EVENT_CLIENT_CONNECT: case EIS_EVENT_CLIENT_DISCONNECT: @@ -49,10 +51,13 @@ eis_event_destroy(struct eis_event *event) case EIS_EVENT_TOUCH_DOWN: case EIS_EVENT_TOUCH_MOTION: case EIS_EVENT_TOUCH_UP: + handled = true; break; - default: - abort(); /* not yet implemented */ } + + if (!handled) + abort(); /* not yet implemented */ + event->device = eis_device_unref(event->device); event->seat = eis_seat_unref(event->seat); event->client = eis_client_unref(event->client); diff --git a/test/eierpecken.c b/test/eierpecken.c index 6b53474..b148a4c 100644 --- a/test/eierpecken.c +++ b/test/eierpecken.c @@ -943,10 +943,9 @@ peck_ei_event_type_name(enum ei_event_type type) CASE_STRING(DEVICE_REMOVED); CASE_STRING(DEVICE_PAUSED); CASE_STRING(DEVICE_RESUMED); - default: - assert(!"Unhandled ei event type"); } #undef CASE_STRING + assert(!"Unhandled ei event type"); } const char * @@ -974,8 +973,7 @@ peck_eis_event_type_name(enum eis_event_type type) CASE_STRING(TOUCH_DOWN); CASE_STRING(TOUCH_UP); CASE_STRING(TOUCH_MOTION); - default: - assert(!"Unhandled EIS event type"); } #undef CASE_STRING + assert(!"Unhandled EIS event type"); }