Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
quickforandroidtest.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"quickforandroidtest_p.h"
6
#
include
"androidtestutils_p.h"
7
8
#
include
<
QtQuickTest
/
private
/
quicktest_p
.
h
>
9
#
include
<
QtQuickTest
/
private
/
quicktestresult_p
.
h
>
10
#
include
<
QtTest
/
private
/
qtestcrashhandler_p
.
h
>
11
#
include
<
QtCore
/
QTimer
>
12
13
QT_BEGIN_NAMESPACE
14
15
/*
16
* For testing Qt Quick for Android (QQ4A) applications with QuickTest
17
* Usage:
18
* QUICK_FOR_ANDROID_TEST_MAIN(test_name)
19
*
20
* This function does the same steps as the regular QtQuickTest macro, with one
21
* exception: it does not parse tests from QML files. This is because in the
22
* QQ4A context, the QML content is loaded by the hosting Android Activity,
23
* via QtQuickView.java (QQuickView internally)
24
*
25
* So in order to execute tests, we need to just spin the event loop and wait
26
* for the application to be manually quit by the tests. This is done via
27
* QGuiApplication::exec(), which allows the QML to be loaded and the tests to
28
* be run.
29
*
30
* Once there are no more testcases to run or the program has been aborted, we
31
* continue the regular QtQuickTest routine, finishing up the QuickTestResult
32
* logging and writing the Android exit code file, before returning out of the
33
* function.
34
*/
35
int
quick_for_android_test_main
(
int
argc,
char
**argv,
const
char
*name)
36
{
37
// Allow exit() once we quit the Qt application.
38
if
(qEnvironmentVariableIsSet(
"QT_ANDROID_NO_EXIT_CALL"
))
39
::unsetenv(
"QT_ANDROID_NO_EXIT_CALL"
);
40
41
QScopedPointer<QCoreApplication> app;
42
if
(!QCoreApplication::instance())
43
app.reset(
new
QGuiApplication(argc, argv));
44
45
clearAndroidExitCode
(
)
;
46
47
QuickTestResult::setCurrentAppname(argv[0]);
48
QuickTestResult::setProgramName(name);
49
QuickTestResult::parseArgs(argc, argv);
50
51
std::optional<QTest::CrashHandler::FatalSignalHandler> handler;
52
QTest::CrashHandler::prepareStackTrace();
53
if
(!QTest::Internal::noCrashHandler)
54
handler.emplace();
55
56
qputenv(
"QT_QTESTLIB_RUNNING"
,
"1"
);
57
58
QTestRootObject::instance()->init();
59
60
// To support "windowShown" property, set it to true once the event loop has started
61
// (windows are always visible in the QQ4A context)
62
QTimer::singleShot(0, [] { QTestRootObject::instance()->setWindowShown(
true
); });
63
64
// Wait for TestCase.qml to call quit() once tests are done, till then just spin
65
// TestSchedule.qml
66
if
(!QTestRootObject::instance()->hasQuit)
67
app->exec();
68
69
QuickTestResult::setProgramName(
nullptr
);
70
app.reset();
71
72
const
int
exitCode = QuickTestResult::exitCode();
73
writeAndroidExitCode
(
exitCode
)
;
74
75
return
exitCode;
76
}
77
78
QT_END_NAMESPACE
writeAndroidExitCode
static void writeAndroidExitCode(int code)
Definition
androidtestutils_p.h:31
clearAndroidExitCode
static void clearAndroidExitCode()
Definition
androidtestutils_p.h:42
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
quick_for_android_test_main
QT_BEGIN_NAMESPACE int quick_for_android_test_main(int argc, char **argv, const char *name)
Definition
quickforandroidtest.cpp:35
qtdeclarative
src
qmltest
android
quickforandroidtest.cpp
Generated on
for Qt by
1.18.0