summaryrefslogtreecommitdiff
path: root/tests/lib/test-thread-helper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/test-thread-helper.cpp')
-rw-r--r--tests/lib/test-thread-helper.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/lib/test-thread-helper.cpp b/tests/lib/test-thread-helper.cpp
new file mode 100644
index 00000000..a977c7a5
--- /dev/null
+++ b/tests/lib/test-thread-helper.cpp
@@ -0,0 +1,37 @@
+#include "tests/lib/test-thread-helper.h"
+#include <QEventLoop>
+#include <QTimer>
+
+TestThreadHelperBase::TestThreadHelperBase(ThreadObjectBase *threadObject)
+{
+ Q_ASSERT(threadObject);
+
+ mThread = new QThread;
+ mThreadObject = threadObject;
+ mThreadObject->moveToThread(mThread);
+
+ QEventLoop loop;
+ QObject::connect(mThread, SIGNAL(started()), &loop, SLOT(quit()));
+ QTimer::singleShot(0, mThread, SLOT(start()));
+ loop.exec();
+}
+
+TestThreadHelperBase::~TestThreadHelperBase()
+{
+ QMetaObject::invokeMethod(mThreadObject, "deleteLater");
+ mThread->quit();
+ mThread->wait();
+ mThread->deleteLater();
+ QCoreApplication::processEvents();
+}
+
+void TestThreadHelperBase::executeCallback()
+{
+ QEventLoop loop;
+ QObject::connect(mThreadObject, SIGNAL(callbackExecutionFinished()),
+ &loop, SLOT(quit()));
+ QMetaObject::invokeMethod(mThreadObject, "executeCallback");
+ loop.exec();
+}
+
+#include "_gen/test-thread-helper.h.moc.hpp"