summaryrefslogtreecommitdiff
path: root/test/signal-threads.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/signal-threads.cpp')
-rw-r--r--test/signal-threads.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/test/signal-threads.cpp b/test/signal-threads.cpp
index d5e2eb66..8c212b6f 100644
--- a/test/signal-threads.cpp
+++ b/test/signal-threads.cpp
@@ -10,6 +10,7 @@
#include <thread>
#include <libcamera/base/message.h>
+#include <libcamera/base/object.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/utils.h>
@@ -58,15 +59,20 @@ private:
class SignalThreadsTest : public Test
{
protected:
- int run()
+ int init()
{
- SignalReceiver receiver;
- signal_.connect(&receiver, &SignalReceiver::slot);
+ receiver_ = new SignalReceiver();
+ signal_.connect(receiver_, &SignalReceiver::slot);
+
+ return TestPass;
+ }
+ int run()
+ {
/* Test that a signal is received in the main thread. */
signal_.emit(0);
- switch (receiver.status()) {
+ switch (receiver_->status()) {
case SignalReceiver::NoSignal:
cout << "No signal received for direct connection" << endl;
return TestFail;
@@ -82,8 +88,8 @@ protected:
* Move the object to a thread and verify that the signal is
* correctly delivered, with the correct data.
*/
- receiver.reset();
- receiver.moveToThread(&thread_);
+ receiver_->reset();
+ receiver_->moveToThread(&thread_);
thread_.start();
@@ -91,7 +97,7 @@ protected:
this_thread::sleep_for(chrono::milliseconds(100));
- switch (receiver.status()) {
+ switch (receiver_->status()) {
case SignalReceiver::NoSignal:
cout << "No signal received for message connection" << endl;
return TestFail;
@@ -103,7 +109,7 @@ protected:
break;
}
- if (receiver.value() != 42) {
+ if (receiver_->value() != 42) {
cout << "Signal received with incorrect value" << endl;
return TestFail;
}
@@ -113,11 +119,13 @@ protected:
void cleanup()
{
+ receiver_->deleteLater();
thread_.exit(0);
thread_.wait();
}
private:
+ SignalReceiver *receiver_;
Thread thread_;
Signal<int> signal_;