summaryrefslogtreecommitdiff
path: root/test/event-thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/event-thread.cpp')
-rw-r--r--test/event-thread.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/test/event-thread.cpp b/test/event-thread.cpp
index ef8a52c3..d6e5d27a 100644
--- a/test/event-thread.cpp
+++ b/test/event-thread.cpp
@@ -11,6 +11,7 @@
#include <unistd.h>
#include <libcamera/base/event_notifier.h>
+#include <libcamera/base/object.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>
@@ -84,10 +85,17 @@ private:
class EventThreadTest : public Test
{
protected:
+ int init()
+ {
+ thread_.start();
+
+ handler_ = new EventHandler();
+
+ return TestPass;
+ }
+
int run()
{
- Thread thread;
- thread.start();
/*
* Fire the event notifier and then move the notifier to a
@@ -97,23 +105,33 @@ protected:
* different thread will correctly process already pending
* events in the new thread.
*/
- EventHandler handler;
- handler.notify();
- handler.moveToThread(&thread);
+ handler_->notify();
+ handler_->moveToThread(&thread_);
this_thread::sleep_for(chrono::milliseconds(100));
- /* Must stop thread before destroying the handler. */
- thread.exit(0);
- thread.wait();
-
- if (!handler.notified()) {
+ if (!handler_->notified()) {
cout << "Thread event handling test failed" << endl;
return TestFail;
}
return TestPass;
}
+
+ void cleanup()
+ {
+ /*
+ * Object class instances must be destroyed from the thread
+ * they live in.
+ */
+ handler_->deleteLater();
+ thread_.exit(0);
+ thread_.wait();
+ }
+
+private:
+ EventHandler *handler_;
+ Thread thread_;
};
TEST_REGISTER(EventThreadTest)