From b462f2bfd6c5672a7e2f108bd2fcd4b419f1b25b Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 11 Jul 2019 13:08:40 +0300 Subject: test: signal: Extend Signal test with multi-inheritance reeiver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tests that exercises the Object-related signal code paths (in particular automatic disconnection on Signal deletion) when the receiver inherits from multiple base classes, with Object being the second base. This tests the casts to and from Object * in the signal implementation. The new tests segfault due bugs in the signal/slot implementation. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- test/signal.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 3 deletions(-) (limited to 'test/signal.cpp') diff --git a/test/signal.cpp b/test/signal.cpp index 79668b42..9d8f985d 100644 --- a/test/signal.cpp +++ b/test/signal.cpp @@ -32,6 +32,29 @@ public: } }; +class BaseClass +{ +public: + /* + * A virtual method is required in the base class, otherwise the compiler + * will always store Object before BaseClass in memory. + */ + virtual ~BaseClass() + { + } + + unsigned int data_[32]; +}; + +class SlotMulti : public BaseClass, public Object +{ +public: + void slot() + { + valueStatic_ = 1; + } +}; + class SignalTest : public Test { protected: @@ -69,6 +92,8 @@ protected: int run() { + /* ----------------- Signal -> !Object tests ---------------- */ + /* Test signal emission and reception. */ called_ = false; signalVoid_.connect(this, &SignalTest::slotVoid); @@ -149,6 +174,8 @@ protected: return TestFail; } + /* ----------------- Signal -> Object tests ----------------- */ + /* * Test automatic disconnection on object deletion. Connect the * slot twice to ensure all instances are disconnected. @@ -170,10 +197,10 @@ protected: * Test that signal deletion disconnects objects. This shall * not generate any valgrind warning. */ - Signal<> *signal = new Signal<>(); + Signal<> *dynamicSignal = new Signal<>(); slotObject = new SlotObject(); - signal->connect(slotObject, &SlotObject::slot); - delete signal; + dynamicSignal->connect(slotObject, &SlotObject::slot); + delete dynamicSignal; delete slotObject; /* Exercise the Object slot code paths. */ @@ -188,6 +215,47 @@ protected: delete slotObject; + /* --------- Signal -> Object (multiple inheritance) -------- */ + + /* + * Test automatic disconnection on object deletion. Connect the + * slot twice to ensure all instances are disconnected. + */ + signalVoid_.disconnect(); + + SlotMulti *slotMulti = new SlotMulti(); + signalVoid_.connect(slotMulti, &SlotMulti::slot); + signalVoid_.connect(slotMulti, &SlotMulti::slot); + delete slotMulti; + valueStatic_ = 0; + signalVoid_.emit(); + if (valueStatic_ != 0) { + cout << "Signal disconnection on object deletion test failed" << endl; + return TestFail; + } + + /* + * Test that signal deletion disconnects objects. This shall + * not generate any valgrind warning. + */ + dynamicSignal = new Signal<>(); + slotMulti = new SlotMulti(); + dynamicSignal->connect(slotMulti, &SlotMulti::slot); + delete dynamicSignal; + delete slotMulti; + + /* Exercise the Object slot code paths. */ + slotMulti = new SlotMulti(); + signalVoid_.connect(slotMulti, &SlotMulti::slot); + valueStatic_ = 0; + signalVoid_.emit(); + if (valueStatic_ == 0) { + cout << "Signal delivery for Object test failed" << endl; + return TestFail; + } + + delete slotMulti; + return TestPass; } -- cgit v1.2.1