aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
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"