Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtesthelpers_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 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
4#ifndef QTESTHELPERS_P_H
5#define QTESTHELPERS_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/QFile>
19#include <QtCore/QString>
20#include <QtCore/QChar>
21#include <QtCore/QPoint>
22#include <QtCore/private/qglobal_p.h>
23
24#ifdef QT_GUI_LIB
25#include <QtGui/QGuiApplication>
26#include <QtGui/QScreen>
27#include <QtGui/QWindow>
28#endif
29
30#ifdef QT_WIDGETS_LIB
31#include <QtWidgets/QWidget>
32#endif
33
34#ifdef QT_NETWORK_LIB
35#if QT_CONFIG(ssl)
36#include <QtCore/qoperatingsystemversion.h>
37#include <QtCore/qsystemdetection.h>
38#include <QtNetwork/qsslsocket.h>
39#endif // QT_CONFIG(ssl)
40#endif // QT_NETWORK_LIB
41
42QT_BEGIN_NAMESPACE
43
44namespace QTestPrivate {
45
46static inline bool canHandleUnicodeFileNames()
47{
48#if defined(Q_OS_WIN)
49 return true;
50#else
51 // Check for UTF-8 by converting the Euro symbol (see tst_utf8)
52 return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
53#endif
54}
55
56#ifdef QT_WIDGETS_LIB
57static inline void centerOnScreen(QWidget *w, const QSize &size)
58{
59 const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
61}
62
63static inline void centerOnScreen(QWidget *w)
64{
66}
67
68/*! \internal
69
70 Make a widget frameless to prevent size constraints of title bars from interfering (Windows).
71*/
72static inline void setFrameless(QWidget *w)
73{
79}
80
81static inline void androidCompatibleShow(QWidget *widget)
82{
83 // On Android QWidget::show() shows the widget maximized, so if we need
84 // to move or resize the widget, we need to explicitly call
85 // QWidget::setVisible(true) instead, because that's what show() actually
86 // does on desktop platforms.
87#ifdef Q_OS_ANDROID
88 widget->setVisible(true);
89#else
90 widget->show();
91#endif
92}
93#endif // QT_WIDGETS_LIB
94
95#ifdef QT_GUI_LIB
96static inline bool ensurePositionTopLeft(QWindow *window)
97{
98 // Wayland: QQuickWindow::setPos() and QQuickWindow::setFramePosition() doesn't work.
100 return true;
101
104#ifdef Q_OS_ANDROID
105 return true; // Android QPA handles the position change synchronously
106#endif
107 bool positionCorrect = true;
108
111
112 const bool positionUpdated = QTest::qWaitFor([&]{ return window->framePosition() == availableTopLeft ;});
113 if (!positionUpdated)
114 positionCorrect = false;
115
116 return positionCorrect;
117}
118
119inline static bool moveCursorAway()
120{
121#if !QT_CONFIG(cursor)
122 // QCursor disabled, skipping cursor move
123 return true;
124#endif
126 safePos -= QPoint(50, 50);
128
129 if (QTest::qWaitFor([&]{ return QCursor::pos() == safePos;}))
130 return true;
131
132 return false;
133}
134#endif
135
136#ifdef QT_NETWORK_LIB
138{
139#ifdef Q_OS_MACOS
140#if QT_CONFIG(ssl)
141 if (QSslSocket::activeBackend() == QLatin1String("securetransport")) {
142#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000, 180000)
143 // Starting from macOS 15 our temporary keychain is ignored.
144 // We have to use kSecImportToMemoryOnly/kCFBooleanTrue key/value
145 // instead. This way we don't have to use QT_SSL_USE_TEMPORARY_KEYCHAIN anymore.
146 return false;
147#else
149 // We were built with SDK below 15, and running on/above 15, but file-based
150 // keychains are not working anymore on macOS 15, blocking the test execution.
151 return true;
152 }
153#endif // Platform SDK.
154 }
155#endif // QT_CONFIG(ssl)
156#endif // Q_OS_MACOS
157 return false;
158}
159#endif // QT_NETWORK_LIB
160
161} // namespace QTestPrivate
162
163QT_END_NAMESPACE
164
165#endif // QTESTHELPERS_P_H
static bool canHandleUnicodeFileNames()