From 7653021549583a58660d46e3d160c82f58f22c69 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Wed, 19 Jan 2022 00:17:17 +0000 Subject: libcamera: base: object: Prevent the same signal being connected more than once Objects are not expected to be connected to the same signal more than once. Doing so likely indicates a bug in the code, and can be highlighted in debug builds with an assert that performs a lookup on the signals_ list. While it is possible to allow the implementation to let objects connect to a specific signal multiple times, there are no expected use cases for this in libcamera and this behaviour is restricted to favour defensive programming by raising an error when this occurs. Remove the support in the test framework which uses multiple Signal connections on the same object, and update the test to use a second Signal. Signed-off-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- test/signal.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'test/signal.cpp') diff --git a/test/signal.cpp b/test/signal.cpp index fcf2def1..5c6b304d 100644 --- a/test/signal.cpp +++ b/test/signal.cpp @@ -212,17 +212,19 @@ protected: /* ----------------- Signal -> Object tests ----------------- */ /* - * Test automatic disconnection on object deletion. Connect the - * slot twice to ensure all instances are disconnected. + * Test automatic disconnection on object deletion. Connect two + * signals to ensure all instances are disconnected. */ signalVoid_.disconnect(); + signalVoid2_.disconnect(); SlotObject *slotObject = new SlotObject(); signalVoid_.connect(slotObject, &SlotObject::slot); - signalVoid_.connect(slotObject, &SlotObject::slot); + signalVoid2_.connect(slotObject, &SlotObject::slot); delete slotObject; valueStatic_ = 0; signalVoid_.emit(); + signalVoid2_.emit(); if (valueStatic_ != 0) { cout << "Signal disconnection on object deletion test failed" << endl; return TestFail; @@ -298,17 +300,19 @@ protected: /* --------- Signal -> Object (multiple inheritance) -------- */ /* - * Test automatic disconnection on object deletion. Connect the - * slot twice to ensure all instances are disconnected. + * Test automatic disconnection on object deletion. Connect two + * signals to ensure all instances are disconnected. */ signalVoid_.disconnect(); + signalVoid2_.disconnect(); SlotMulti *slotMulti = new SlotMulti(); signalVoid_.connect(slotMulti, &SlotMulti::slot); - signalVoid_.connect(slotMulti, &SlotMulti::slot); + signalVoid2_.connect(slotMulti, &SlotMulti::slot); delete slotMulti; valueStatic_ = 0; signalVoid_.emit(); + signalVoid2_.emit(); if (valueStatic_ != 0) { cout << "Signal disconnection on object deletion test failed" << endl; return TestFail; @@ -345,6 +349,7 @@ protected: private: Signal<> signalVoid_; + Signal<> signalVoid2_; Signal signalInt_; Signal signalMultiArgs_; -- cgit v1.2.1