summaryrefslogtreecommitdiff
path: root/test/timer-thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/timer-thread.cpp')
-rw-r--r--test/timer-thread.cpp37
1 files changed, 11 insertions, 26 deletions
diff --git a/test/timer-thread.cpp b/test/timer-thread.cpp
index 61821753..8675e248 100644
--- a/test/timer-thread.cpp
+++ b/test/timer-thread.cpp
@@ -9,6 +9,7 @@
#include <iostream>
#include <libcamera/base/event_dispatcher.h>
+#include <libcamera/base/object.h>
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>
@@ -28,12 +29,6 @@ public:
timer_.start(100ms);
}
- void restart()
- {
- timeout_ = false;
- timer_.start(100ms);
- }
-
bool timeout() const
{
return timeout_;
@@ -55,7 +50,9 @@ protected:
int init()
{
thread_.start();
- timeout_.moveToThread(&thread_);
+
+ timeout_ = new TimeoutHandler();
+ timeout_->moveToThread(&thread_);
return TestPass;
}
@@ -68,39 +65,27 @@ protected:
*/
this_thread::sleep_for(chrono::milliseconds(200));
- if (!timeout_.timeout()) {
+ if (!timeout_->timeout()) {
cout << "Timer expiration test failed" << endl;
return TestFail;
}
- /*
- * Test that starting the timer from another thread fails. We
- * need to interrupt the event dispatcher to make sure we don't
- * succeed simply because the event dispatcher hasn't noticed
- * the timer restart.
- */
- timeout_.restart();
- thread_.eventDispatcher()->interrupt();
-
- this_thread::sleep_for(chrono::milliseconds(200));
-
- if (timeout_.timeout()) {
- cout << "Timer restart test failed" << endl;
- return TestFail;
- }
-
return TestPass;
}
void cleanup()
{
- /* Must stop thread before destroying timeout. */
+ /*
+ * Object class instances must be destroyed from the thread
+ * they live in.
+ */
+ timeout_->deleteLater();
thread_.exit(0);
thread_.wait();
}
private:
- TimeoutHandler timeout_;
+ TimeoutHandler *timeout_;
Thread thread_;
};