summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/platform/android/tst_android.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/platform/android/tst_android.cpp')
-rw-r--r--tests/auto/corelib/platform/android/tst_android.cpp96
1 files changed, 89 insertions, 7 deletions
diff --git a/tests/auto/corelib/platform/android/tst_android.cpp b/tests/auto/corelib/platform/android/tst_android.cpp
index bb1fdcae1c..76811a31ad 100644
--- a/tests/auto/corelib/platform/android/tst_android.cpp
+++ b/tests/auto/corelib/platform/android/tst_android.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <jni.h>
@@ -12,6 +12,10 @@
#include <qpa/qplatformscreen.h>
#include <qpa/qplatformnativeinterface.h>
#include <QtCore/qdiriterator.h>
+#include <QWidget>
+#include <QSignalSpy>
+
+using namespace Qt::StringLiterals;
class tst_Android : public QObject
{
@@ -24,6 +28,8 @@ private slots:
void testAndroidActivity();
void testRunOnAndroidMainThread();
void testFullScreenDimensions();
+ void orientationChange_data();
+ void orientationChange();
};
void tst_Android::assetsRead()
@@ -64,10 +70,14 @@ void tst_Android::assetsIterating()
QDirIterator it("assets:/top_level_dir", QDirIterator::Subdirectories);
QStringList iteratorAssets;
- while (it.hasNext())
- iteratorAssets.append(it.next());
+ while (it.hasNext())
+ iteratorAssets.append(it.next());
+
+ QVERIFY(assets == iteratorAssets);
- QVERIFY(assets == iteratorAssets);
+ auto entryList = QDir{"assets:/"_L1}.entryList(QStringList{"*.txt"_L1});
+ QCOMPARE(entryList.size(), 1);
+ QCOMPARE(entryList[0], "test.txt"_L1);
}
void tst_Android::testAndroidSdkVersion()
@@ -193,11 +203,14 @@ void tst_Android::testRunOnAndroidMainThread()
}
}
+Q_DECLARE_JNI_CLASS(QtActivityDelegateBase, "org/qtproject/qt/android/QtActivityDelegateBase")
+
void setSystemUiVisibility(int visibility)
{
QNativeInterface::QAndroidApplication::runOnAndroidMainThread([visibility] {
- QJniObject::callStaticMethod<void>("org/qtproject/qt/android/QtNative",
- "setSystemUiVisibility", "(I)V", visibility);
+ auto context = QNativeInterface::QAndroidApplication::context();
+ auto activityDelegate = context.callMethod<QtJniTypes::QtActivityDelegateBase>("getActivityDelegate");
+ activityDelegate.callMethod<void>("setSystemUiVisibility", jint(visibility));
}).waitForFinished();
}
@@ -290,6 +303,75 @@ void tst_Android::testFullScreenDimensions()
}
}
+void tst_Android::orientationChange_data()
+{
+ QTest::addColumn<int>("nativeOrientation");
+ QTest::addColumn<Qt::ScreenOrientation>("expected");
+ QTest::addColumn<QSize>("screenSize");
+
+ const QSize portraitSize = QGuiApplication::primaryScreen()->size();
+ const QSize landscapeSize = QSize(portraitSize.height(), portraitSize.width());
+
+ // Rotations without 180 degree or inverted portrait, assuming that the device is in portrait
+ // position. These are ok for Android 6(API 23), 8 (API 27) and 14 (API 34)
+ QTest::newRow("InvertedLandscape") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize;
+ QTest::newRow("Portrait") << 1 << Qt::PortraitOrientation << portraitSize;
+ QTest::newRow("Landscape") << 0 << Qt::LandscapeOrientation << landscapeSize;
+ QTest::newRow("Portrait2") << 1 << Qt::PortraitOrientation << portraitSize;
+
+ // Rotations over inverted portrait doing only 90 degree turns.
+ QTest::newRow("InvertedLandscape2") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize;
+ QTest::newRow("InvertedPortrait") << 9 << Qt::InvertedPortraitOrientation << portraitSize;
+ QTest::newRow("Landscape2") << 0 << Qt::LandscapeOrientation << landscapeSize;
+ QTest::newRow("InvertedPortrait2") << 9 << Qt::InvertedPortraitOrientation << portraitSize;
+ QTest::newRow("InvertedLandscape3") << 8 << Qt::InvertedLandscapeOrientation << landscapeSize;
+
+ // Rotations with 180 degree turns.
+ // Android 6 (API23) Does not understand these transitions.
+ if (QNativeInterface::QAndroidApplication::sdkVersion() > __ANDROID_API_M__) {
+ QTest::newRow("Landscape3") << 0 << Qt::LandscapeOrientation << landscapeSize;
+ QTest::newRow("InvertedLandscape4")
+ << 8 << Qt::InvertedLandscapeOrientation << landscapeSize;
+ QTest::newRow("Portrait3") << 1 << Qt::PortraitOrientation << portraitSize;
+ } else {
+ qWarning() << "180 degree turn rotation test cases are not run on Android 6 (API 23) and "
+ "below.";
+ }
+ // Android 8 (API 27) does not understand portrait-'inverted portrait'-portrait transition.
+ if (QNativeInterface::QAndroidApplication::sdkVersion() > __ANDROID_API_O_MR1__) {
+ QTest::newRow("InvertedPortrait3") << 9 << Qt::InvertedPortraitOrientation << portraitSize;
+ QTest::newRow("Portrait4") << 1 << Qt::PortraitOrientation << portraitSize;
+ } else {
+ qWarning() << "Portrait-'Inverted portrait'-Portrait rotation test cases are not run on "
+ "Android 8 (API 27) and below.";
+ }
+}
+
+void tst_Android::orientationChange()
+{
+ QFETCH(int, nativeOrientation);
+ QFETCH(Qt::ScreenOrientation, expected);
+ QFETCH(QSize, screenSize);
+
+ if (QNativeInterface::QAndroidApplication::sdkVersion() == __ANDROID_API_P__)
+ QSKIP("Android 9 orientation changes callbacks are buggy (QTBUG-124890).");
+
+ // For QTBUG-94459 to check that the widget size are consistent after orientation changes
+ QWidget widget;
+ widget.show();
+
+ QScreen *screen = QGuiApplication::primaryScreen();
+ QSignalSpy orientationSpy(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)));
+
+ auto context = QNativeInterface::QAndroidApplication::context();
+ context.callMethod<void>("setRequestedOrientation", nativeOrientation);
+
+ orientationSpy.wait();
+ QTRY_COMPARE(screen->orientation(), expected);
+ QCOMPARE(orientationSpy.size(), 1);
+ QCOMPARE(screen->size(), screenSize);
+ QCOMPARE(widget.size(), screen->availableSize());
+}
+
QTEST_MAIN(tst_Android)
#include "tst_android.moc"
-