summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-07-11 13:08:40 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-07-11 16:38:18 +0300
commitb462f2bfd6c5672a7e2f108bd2fcd4b419f1b25b (patch)
tree36a7471dd601969498867592d7c0c6ef7e54d992
parenta1b1551446f26e942f7784406c6ea824b3914a53 (diff)
test: signal: Extend Signal test with multi-inheritance reeiver
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
-rw-r--r--test/signal.cpp74
1 files changed, 71 insertions, 3 deletions
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;
}