Android: add an appless test that recreates QGuiApplication

Make sure this works and doesn't cause any QJniEnvironment or other
JNI object lifetime issues.

Change-Id: I08b55982266dfb1821517449f6eb9f2796cea9b7
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-10-25 16:14:54 +02:00
parent beeb531c32
commit f419a8d67f
3 changed files with 73 additions and 0 deletions

View File

@ -3,6 +3,7 @@
if(ANDROID)
add_subdirectory(android)
add_subdirectory(android_appless)
endif()
if(WIN32)
add_subdirectory(windows)

View File

@ -0,0 +1,19 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_android_appless Test:
#####################################################################
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
cmake_minimum_required(VERSION 3.16)
project(tst_android_appless LANGUAGES CXX)
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
endif()
qt_internal_add_test(tst_android_appless
SOURCES
tst_android_appless.cpp
LIBRARIES
Qt::Gui
)

View File

@ -0,0 +1,53 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QTest>
#include <QTimer>
#include <QGuiApplication>
#include <QWindow>
using namespace Qt::StringLiterals;
class tst_AndroidAppless : public QObject
{
Q_OBJECT
private slots:
void app_data();
void app();
};
#define CREATE_DUMMY_ARGC_ARGV() \
int argc = 1; \
char *argv[] = { const_cast<char *>("tst_android_appless") };
void tst_AndroidAppless::app_data()
{
QTest::addColumn<QString>("displayName");
QTest::addRow("one") << "The first QGuiApplication instance";
QTest::addRow("two") << "The second QGuiApplication instance";
}
void tst_AndroidAppless::app()
{
QFETCH(const QString, displayName);
CREATE_DUMMY_ARGC_ARGV()
QGuiApplication app(argc, argv);
app.setApplicationDisplayName(displayName);
QWindow window;
window.show();
QTimer::singleShot(1000, &app, QGuiApplication::quit);
window.show();
app.exec();
}
#undef CREATE_DUMMY_ARGC_ARGV
QTEST_APPLESS_MAIN(tst_AndroidAppless)
#include "tst_android_appless.moc"