aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kdab.com>2016-02-04 17:16:05 +0200
committerBogDan Vatra <bogdan@kdab.com>2016-02-05 06:21:30 +0000
commitf0fefa8766cb3cec38f39c31bb01860bea88dcbc (patch)
tree98ba6d4a9156f68e29538eca9115df7a9d010573 /tests
parent023d83792cd3f4cdffb9ae3a5464e4e8b654ddab (diff)
Helper functions needed to run Runnables on Android UI thread easily.
Add two function to allow the users to easily run (a)synchronously Runnables from any thread directly to Andoroid UI thread. These functions are useful to create java controls and to access their methods, which must done on Android UI thread. Change-Id: Iec5437321e6136cc90268cc7ecf091f82fc4cdd3 Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qandroidfunctions/tst_qandroidfunctions.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qandroidfunctions/tst_qandroidfunctions.cpp b/tests/auto/qandroidfunctions/tst_qandroidfunctions.cpp
index 36c86df..f6bfc2b 100644
--- a/tests/auto/qandroidfunctions/tst_qandroidfunctions.cpp
+++ b/tests/auto/qandroidfunctions/tst_qandroidfunctions.cpp
@@ -35,6 +35,7 @@ class tst_QAndroidFunctions : public QObject
private slots:
void testAndroidSdkVersion();
void testAndroidActivity();
+ void testRunOnAndroidThread();
};
void tst_QAndroidFunctions::testAndroidSdkVersion()
@@ -49,6 +50,56 @@ void tst_QAndroidFunctions::testAndroidActivity()
QVERIFY(activity.callMethod<jboolean>("isTaskRoot"));
}
+void tst_QAndroidFunctions::testRunOnAndroidThread()
+{
+ int a = 0;
+
+ // test async operation
+ QtAndroid::runOnAndroidThread([&a]{
+ a = 1;
+ });
+ QTRY_COMPARE(a, 1); // wait for async op. to finish
+
+ // test sync operation
+ QtAndroid::runOnAndroidThreadSync([&a]{
+ a = 2;
+ });
+ QCOMPARE(a, 2);
+
+ // test async/async lock
+ QtAndroid::runOnAndroidThread([&a]{
+ QtAndroid::runOnAndroidThread([&a]{
+ a = 3;
+ });
+ });
+ QTRY_COMPARE(a, 3); // wait for async op. to finish
+
+ // test async/sync lock
+ QtAndroid::runOnAndroidThread([&a]{
+ QtAndroid::runOnAndroidThreadSync([&a]{
+ a = 5;
+ });
+ });
+ QTRY_COMPARE(a, 5);
+
+ // test sync/sync lock
+ QtAndroid::runOnAndroidThreadSync([&a]{
+ QtAndroid::runOnAndroidThreadSync([&a]{
+ a = 4;
+ });
+ });
+ QCOMPARE(a, 4);
+
+
+ // test sync/async lock
+ QtAndroid::runOnAndroidThreadSync([&a]{
+ QtAndroid::runOnAndroidThread([&a]{
+ a = 6;
+ });
+ });
+ QCOMPARE(a, 6);
+}
+
QTEST_APPLESS_MAIN(tst_QAndroidFunctions)
#include "tst_qandroidfunctions.moc"