summaryrefslogtreecommitdiff
path: root/test/signal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/signal.cpp')
-rw-r--r--test/signal.cpp66
1 files changed, 55 insertions, 11 deletions
diff --git a/test/signal.cpp b/test/signal.cpp
index f83ceb05..3f596b22 100644
--- a/test/signal.cpp
+++ b/test/signal.cpp
@@ -2,14 +2,14 @@
/*
* Copyright (C) 2019, Google Inc.
*
- * signal.cpp - Signal test
+ * Signal test
*/
#include <iostream>
#include <string.h>
-#include <libcamera/object.h>
-#include <libcamera/signal.h>
+#include <libcamera/base/object.h>
+#include <libcamera/base/signal.h>
#include "test.h"
@@ -41,8 +41,8 @@ class BaseClass
{
public:
/*
- * A virtual method is required in the base class, otherwise the compiler
- * will always store Object before BaseClass in memory.
+ * A virtual function is required in the base class, otherwise the
+ * compiler will always store Object before BaseClass in memory.
*/
virtual ~BaseClass()
{
@@ -191,20 +191,40 @@ protected:
signalVoid_.connect(slotStaticReturn);
signalVoid_.connect(this, &SignalTest::slotReturn);
+ /* Test signal connection to a lambda. */
+ int value = 0;
+ signalInt_.connect(this, [&](int v) { value = v; });
+ signalInt_.emit(42);
+
+ if (value != 42) {
+ cout << "Signal connection to lambda failed" << endl;
+ return TestFail;
+ }
+
+ signalInt_.disconnect(this);
+ signalInt_.emit(0);
+
+ if (value != 42) {
+ cout << "Signal disconnection from lambda failed" << endl;
+ return TestFail;
+ }
+
/* ----------------- 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;
@@ -256,20 +276,43 @@ protected:
delete slotObject;
+ /* Test signal connection to a lambda. */
+ slotObject = new SlotObject();
+ value = 0;
+ signalInt_.connect(slotObject, [&](int v) { value = v; });
+ signalInt_.emit(42);
+
+ if (value != 42) {
+ cout << "Signal connection to Object lambda failed" << endl;
+ return TestFail;
+ }
+
+ signalInt_.disconnect(slotObject);
+ signalInt_.emit(0);
+
+ if (value != 42) {
+ cout << "Signal disconnection from Object lambda failed" << endl;
+ return TestFail;
+ }
+
+ delete slotObject;
+
/* --------- 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;
@@ -306,6 +349,7 @@ protected:
private:
Signal<> signalVoid_;
+ Signal<> signalVoid2_;
Signal<int> signalInt_;
Signal<int, const std::string &> signalMultiArgs_;