Skip to content

Commit

Permalink
signal-slot-connector: assert on programming errors instead of emitti…
Browse files Browse the repository at this point in the history
…ng a runtime warning

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Oct 14, 2023
1 parent f4f13fb commit 8b395da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
12 changes: 6 additions & 6 deletions lib/signal-slot-connector/signal-slot-connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}

Expand Down Expand Up @@ -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_;
}

Expand Down
25 changes: 6 additions & 19 deletions lib/signal-slot-connector/tests/test_signal_slots.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,19 @@ 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;
test_data_init(&test_data);
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) \
Expand Down

0 comments on commit 8b395da

Please sign in to comment.