From 8b395da958633f5c0fe8f75af337c8cf00bf4a0e Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Sat, 14 Oct 2023 07:41:22 +0200 Subject: [PATCH] signal-slot-connector: assert on programming errors instead of emitting a runtime warning Signed-off-by: Balazs Scheidler --- .../signal-slot-connector.c | 12 ++++----- .../tests/test_signal_slots.c | 25 +++++-------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/lib/signal-slot-connector/signal-slot-connector.c b/lib/signal-slot-connector/signal-slot-connector.c index 68e6b1d3aef..ef989e30c9d 100644 --- a/lib/signal-slot-connector/signal-slot-connector.c +++ b/lib/signal-slot-connector/signal-slot-connector.c @@ -121,9 +121,8 @@ signal_slot_connect(SignalSlotConnector *self, Signal signal, Slot slot, gpointe if (_slot_lookup(slots, slot, object)) { - msg_warning("WARNING: Duplicate inter-plugin communication signal registration, ignoring connection attempt", - evt_tag_slot(self, signal, slot, object)); - goto exit_; + /* Duplicate inter-plugin communication signal registration */ + g_assert_not_reached(); } GList *new_slots = g_list_append(slots, _slot_functor_new(slot, object)); @@ -135,7 +134,6 @@ signal_slot_connect(SignalSlotConnector *self, Signal signal, Slot slot, gpointe msg_trace("Inter-plugin communication signal successfully connected", evt_tag_slot(self, signal, slot, object)); -exit_: g_mutex_unlock(&self->lock); } @@ -172,8 +170,10 @@ signal_slot_disconnect(SignalSlotConnector *self, Signal signal, Slot slot, gpoi GList *slotfunctor_node = g_list_find_custom(slots, &slotfunctor, _slot_functor_cmp); if (!slotfunctor_node) { - msg_warning("WARNING: Inter-plugin communication signal unregistration failed, slot object not found", - evt_tag_slot(self, signal, slot, object)); + /* Inter-plugin communication signal unregistration failed, + * slot object not found */ + + g_assert_not_reached(); goto exit_; } diff --git a/lib/signal-slot-connector/tests/test_signal_slots.c b/lib/signal-slot-connector/tests/test_signal_slots.c index c9c12b30408..925ecfa9136 100644 --- a/lib/signal-slot-connector/tests/test_signal_slots.c +++ b/lib/signal-slot-connector/tests/test_signal_slots.c @@ -100,7 +100,7 @@ Test(basic_signal_slots, when_the_signal_is_emitted_then_the_connected_slot_is_e signal_slot_connector_free(ssc); } -Test(basic_signal_slots, when_trying_to_connect_multiple_times_the_same_connection_then_connect_only_the_first) +Test(basic_signal_slots, abort_when_trying_to_connect_multiple_times_the_same_connection, .signal = SIGABRT) { SignalSlotConnector *ssc = signal_slot_connector_new(); TestData test_data; @@ -108,18 +108,11 @@ Test(basic_signal_slots, when_trying_to_connect_multiple_times_the_same_connecti SlotObj slot_obj; slot_obj_init(&slot_obj); - for (gint i = 0; i < 5; i++) - CONNECT(ssc, signal_test1, test1_slot, &slot_obj); - - EMIT(ssc, signal_test1, &test_data); - - cr_expect_eq(test_data.slot_ctr, 1); - cr_expect_eq(slot_obj.ctr, 1); - - signal_slot_connector_free(ssc); + CONNECT(ssc, signal_test1, test1_slot, &slot_obj); + CONNECT(ssc, signal_test1, test1_slot, &slot_obj); } -Test(basic_signal_slots, when_trying_to_disconnect_multiple_times_the_same_connection_disconnect_only_the_first) +Test(basic_signal_slots, abort_when_trying_to_disconnect_multiple_times_the_same_connection, .signal = SIGABRT) { SignalSlotConnector *ssc = signal_slot_connector_new(); TestData test_data; @@ -189,7 +182,8 @@ Test(basic_signal_slots, when_disconnect_the_connected_slot_from_a_signal_then_t } Test(basic_signal_slots, - when_trying_to_disconnect_a_connected_slot_with_different_slot_object_then_slot_is_not_disconnected) + abort_when_trying_to_disconnect_a_connected_slot_with_different_slot_object_then_slot_is_not_disconnected, + .signal = SIGABRT) { SignalSlotConnector *ssc = signal_slot_connector_new(); TestData test_data; @@ -201,13 +195,6 @@ Test(basic_signal_slots, CONNECT(ssc, signal_test1, test1_slot, &slot_obj); DISCONNECT(ssc, signal_test1, test1_slot, &slot_obj_another); - EMIT(ssc, signal_test1, &test_data); - - cr_expect_eq(test_data.slot_ctr, 1); - cr_expect_eq(slot_obj.ctr, 1); - cr_expect_eq(slot_obj_another.ctr, 0); - - signal_slot_connector_free(ssc); } #define DEFINE_TEST_SLOT(func_name) \