testlib: start sharing common helper functions

... by moving them in QTestPrivate namespace (qtesthelpers_p.h). This
header file is a convenient staging area for helper APIs, eventually
some could be moved to public QTest API.

This header file utilizes the same pattern as other qtestlib header
files - wrapping functions with QT_${LIBNAME}_LIB to automatically
enable certain APIs based on what is in the projects dependencies,
e.g. QT += widgets.

Change-Id: Ic0266429939c1f3788912ad8b84fc6e0d5edd68b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Gatis Paeglis 2017-10-30 13:45:18 +01:00
parent 01f5f77c66
commit ad36da8ff4
56 changed files with 223 additions and 275 deletions

View File

@ -0,0 +1,112 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtTest module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTESTHELPERS_P_H
#define QTESTHELPERS_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <QtCore/QFile>
#include <QtCore/QString>
#include <QtCore/QChar>
#include <QtCore/QPoint>
#ifdef QT_GUI_LIB
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
#endif
#ifdef QT_WIDGETS_LIB
#include <QtWidgets/QWidget>
#endif
QT_BEGIN_NAMESPACE
namespace QTestPrivate {
static inline bool canHandleUnicodeFileNames()
{
#if defined(Q_OS_WIN)
return true;
#else
// Check for UTF-8 by converting the Euro symbol (see tst_utf8)
return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
#endif
}
#ifdef QT_WIDGETS_LIB
static inline void centerOnScreen(QWidget *w, const QSize &size)
{
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
static inline void centerOnScreen(QWidget *w)
{
centerOnScreen(w, w->geometry().size());
}
/*! \internal
Make a widget frameless to prevent size constraints of title bars from interfering (Windows).
*/
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint
| Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#endif // QT_WIDGETS_LIB
} // namespace QTestPrivate
QT_END_NAMESPACE
#endif // QTESTHELPERS_P_H

View File

@ -37,7 +37,8 @@ HEADERS = qbenchmark.h \
qtestspontaneevent.h \
qtestsystem.h \
qtesttouch.h \
qtestblacklist_p.h
qtestblacklist_p.h \
qtesthelpers_p.h
SOURCES = qtestcase.cpp \
qtestlog.cpp \

View File

@ -4,4 +4,4 @@ SOURCES += tst_qtemporarydir.cpp
INCLUDEPATH += ../../../../shared/
HEADERS += ../../../../shared/emulationdetector.h
QT = core testlib
QT = core testlib testlib-private

View File

@ -35,6 +35,7 @@
#include <qdir.h>
#include <qset.h>
#include <qtextcodec.h>
#include <QtTest/private/qtesthelpers_p.h>
#ifdef Q_OS_WIN
# include <windows.h>
#endif
@ -112,16 +113,6 @@ void tst_QTemporaryDir::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
static inline bool canHandleUnicodeFileNames()
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
return true;
#else
// Check for UTF-8 by converting the Euro symbol (see tst_utf8)
return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
#endif
}
static QString hanTestText()
{
QString text;
@ -160,7 +151,7 @@ void tst_QTemporaryDir::fileTemplate_data()
QTest::newRow("constructor with XXXX suffix") << "qt_XXXXXX_XXXX" << "qt_";
QTest::newRow("constructor with XXXX prefix") << "qt_XXXX" << "qt_";
QTest::newRow("constructor with XXXXX prefix") << "qt_XXXXX" << "qt_";
if (canHandleUnicodeFileNames()) {
if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();
QTest::newRow("Umlauts") << (prefix + "XXXXXX") << prefix;

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtemporaryfile
QT = core testlib
QT = core testlib testlib-private
SOURCES = tst_qtemporaryfile.cpp
TESTDATA += tst_qtemporaryfile.cpp
RESOURCES += qtemporaryfile.qrc

View File

@ -36,6 +36,8 @@
#include <qset.h>
#include <qtextcodec.h>
#include <QtTest/private/qtesthelpers_p.h>
#if defined(Q_OS_WIN)
# include <windows.h>
#endif
@ -141,16 +143,6 @@ void tst_QTemporaryFile::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
static inline bool canHandleUnicodeFileNames()
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
return true;
#else
// Check for UTF-8 by converting the Euro symbol (see tst_utf8)
return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
#endif
}
static QString hanTestText()
{
QString text;
@ -199,7 +191,7 @@ void tst_QTemporaryFile::fileTemplate_data()
QTest::newRow("set template, with xxx") << "" << "qt_" << ".xxx" << "qt_XXXXXX.xxx";
QTest::newRow("set template, with >6 X's") << "" << "qt_" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx";
QTest::newRow("set template, with >6 X's, no suffix") << "" << "qt_" << "" << "qt_XXXXXXXXXXXXXX";
if (canHandleUnicodeFileNames()) {
if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();
QTest::newRow("Umlauts") << (prefix + "XXXXXX") << prefix << QString() << QString();
@ -761,7 +753,7 @@ void tst_QTemporaryFile::QTBUG_4796_data()
QTest::newRow("XXXXXXbla") << QString() << QString("bla") << true;
QTest::newRow("does-not-exist/qt_temp.XXXXXX") << QString("does-not-exist/qt_temp") << QString() << false;
if (canHandleUnicodeFileNames()) {
if (QTestPrivate::canHandleUnicodeFileNames()) {
QTest::newRow("XXXXXX<unicode>") << QString() << unicode << true;
QTest::newRow("<unicode>XXXXXX") << unicode << QString() << true;
QTest::newRow("<unicode>XXXXXX<unicode>") << unicode << unicode << true;

View File

@ -1,7 +1,7 @@
CONFIG += testcase
TARGET = tst_qaccessibility
requires(qtConfig(accessibility))
QT += testlib core-private gui-private widgets-private
QT += testlib core-private gui-private widgets-private testlib-private
SOURCES += tst_qaccessibility.cpp
HEADERS += accessiblewidgets.h

View File

@ -59,15 +59,9 @@
#include "accessiblewidgets.h"
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface,
int index, const QRect &domain)

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qgraphicsitem
QT += widgets widgets-private testlib
QT += widgets widgets-private testlib testlib-private
QT += core-private gui-private
SOURCES += tst_qgraphicsitem.cpp
DEFINES += QT_NO_CAST_TO_ASCII

View File

@ -28,6 +28,7 @@
#include <QtTest/QtTest>
#include <QtTest/private/qtesthelpers_p.h>
#include <private/qgraphicsitem_p.h>
#include <private/qgraphicsview_p.h>
@ -127,17 +128,6 @@ static void sendKeyClick(QGraphicsScene *scene, Qt::Key key)
sendKeyRelease(scene, key);
}
static inline void centerOnScreen(QWidget *w, const QSize &size)
{
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
static inline void centerOnScreen(QWidget *w)
{
centerOnScreen(w, w->geometry().size());
}
class EventSpy : public QGraphicsWidget
{
Q_OBJECT
@ -4211,7 +4201,7 @@ void tst_QGraphicsItem::cursor()
QWidget topLevel;
topLevel.resize(250, 150);
centerOnScreen(&topLevel);
QTestPrivate::centerOnScreen(&topLevel);
QGraphicsView view(&scene,&topLevel);
view.setFixedSize(200, 100);
topLevel.show();

View File

@ -3,7 +3,7 @@ testcase.timeout = 500 # this test is slow
TARGET = tst_qgraphicsview
QT += widgets widgets-private testlib
QT += core-private gui-private
QT += core-private gui-private testlib-private
SOURCES += tst_qgraphicsview.cpp tst_qgraphicsview_2.cpp
HEADERS += tst_qgraphicsview.h

View File

@ -61,6 +61,10 @@
#include "tst_qgraphicsview.h"
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
Q_DECLARE_METATYPE(ExpectedValueDescription)
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<QRectF>)
@ -130,14 +134,6 @@ class FriendlyGraphicsScene : public QGraphicsScene
};
#endif
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
class tst_QGraphicsView : public QObject
{
Q_OBJECT

View File

@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qabstractitemview
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qabstractitemview.cpp

View File

@ -28,6 +28,7 @@
#include <QtTest/QtTest>
#include <QtTest/private/qtesthelpers_p.h>
#include <qabstractitemview.h>
#include <qstandarditemmodel.h>
@ -57,19 +58,7 @@
Q_DECLARE_METATYPE(Qt::ItemFlags);
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
static inline void centerOnScreen(QWidget *w)
{
const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
using namespace QTestPrivate;
// Move cursor out of widget area to avoid undesired interaction on Mac.
static inline void moveCursorAway(const QWidget *topLevel)

View File

@ -1,6 +1,6 @@
CONFIG += testcase
QT += widgets widgets-private
QT += gui-private core-private testlib
QT += gui-private core-private testlib testlib-private
SOURCES += tst_qcolumnview.cpp
HEADERS += ../../../../shared/fakedirmodel.h

View File

@ -28,6 +28,7 @@
#include "../../../../shared/fakedirmodel.h"
#include <QtTest/QtTest>
#include <QtTest/private/qtesthelpers_p.h>
#include <qitemdelegate.h>
#include <qcolumnview.h>
#include <private/qcolumnviewgrip_p.h>
@ -369,12 +370,6 @@ void tst_QColumnView::scrollTo_data()
QTest::newRow("reverse") << true << false;
}
static inline void centerOnScreen(QWidget *w)
{
const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
void tst_QColumnView::scrollTo()
{
QFETCH(bool, reverse);
@ -386,7 +381,7 @@ void tst_QColumnView::scrollTo()
view.resize(200, 200);
topLevel.show();
topLevel.activateWindow();
centerOnScreen(&topLevel);
QTestPrivate::centerOnScreen(&topLevel);
QVERIFY(QTest::qWaitForWindowActive(&topLevel));
view.scrollTo(QModelIndex(), QAbstractItemView::EnsureVisible);
@ -1004,7 +999,7 @@ void tst_QColumnView::dynamicModelChanges()
ColumnView view;
view.setModel(&model);
view.setItemDelegate(&delegate);
centerOnScreen(&view);
QTestPrivate::centerOnScreen(&view);
view.show();
QStandardItem *item = new QStandardItem(QLatin1String("item"));

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qlistview
QT += widgets gui-private widgets-private core-private testlib
QT += widgets gui-private widgets-private core-private testlib testlib-private
SOURCES += tst_qlistview.cpp
win32:!winrt: LIBS += -luser32
linux*: CONFIG += insignificant_test # Crashes

View File

@ -46,6 +46,10 @@
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QVBoxLayout>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
#if defined(Q_OS_WIN)
# include <windows.h>
# include <QtGui/QGuiApplication>
@ -64,16 +68,6 @@ Q_DECLARE_METATYPE(QAbstractItemView::ScrollMode)
Q_DECLARE_METATYPE(QMargins)
Q_DECLARE_METATYPE(QSize)
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
static QStringList generateList(const QString &prefix, int size)
{
QStringList result;

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtableview
QT += widgets widgets-private testlib
QT += core-private gui-private
QT += core-private gui-private testlib-private
SOURCES += tst_qtableview.cpp

View File

@ -35,6 +35,10 @@
#include <algorithm>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
#ifdef QT_BUILD_INTERNAL
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) \
QVERIFY(static_cast<QTableViewPrivate*>(QObjectPrivate::get(TEST_VIEW_))->spans.checkConsistency())
@ -46,16 +50,6 @@ typedef QList<int> IntList;
typedef QList<bool> BoolList;
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
class tst_QTableView : public QObject
{
Q_OBJECT

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtreeview
QT += widgets testlib
QT += widgets-private gui-private core-private
QT += widgets-private gui-private core-private testlib-private
SOURCES += tst_qtreeview.cpp
HEADERS += ../../../../shared/fakedirmodel.h

View File

@ -33,6 +33,10 @@
#include <QtWidgets/QtWidgets>
#include <private/qtreeview_p.h>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
#ifndef QT_NO_DRAGANDDROP
Q_DECLARE_METATYPE(QAbstractItemView::DragDropMode)
#endif
@ -57,16 +61,6 @@ static void initStandardTreeModel(QStandardItemModel *model)
model->insertRow(2, item);
}
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
class tst_QTreeView : public QObject
{
Q_OBJECT

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qboxlayout
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qboxlayout.cpp

View File

@ -31,13 +31,9 @@
#include <QtGui>
#include <QtWidgets>
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QBoxLayout : public QObject
{

View File

@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qformlayout
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qformlayout.cpp

View File

@ -41,20 +41,16 @@
#include <QStyleFactory>
#include <QSharedPointer>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
#include <qformlayout.h>
// ItemRole has enumerators for numerical values 0..2, thus the only
// valid numerical values for storing into an ItemRole variable are 0..3:
Q_CONSTEXPR QFormLayout::ItemRole invalidRole = QFormLayout::ItemRole(3);
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
struct QFormLayoutTakeRowResultHolder {
QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) Q_DECL_NOTHROW
: labelItem(result.labelItem),

View File

@ -2,7 +2,7 @@ CONFIG += testcase
TARGET = tst_qgridlayout
QT += widgets widgets-private testlib
QT += core-private gui-private
QT += core-private gui-private testlib-private
SOURCES += tst_qgridlayout.cpp
FORMS += sortdialog.ui

View File

@ -41,15 +41,9 @@
#include <QStyleFactory>
#include <QSharedPointer>
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QGridLayout : public QObject
{

View File

@ -1,7 +1,7 @@
CONFIG += testcase
TARGET = tst_qlayout
QT += widgets widgets-private testlib
QT += widgets widgets-private testlib testlib-private
SOURCES += tst_qlayout.cpp
TESTDATA += baseline/*

View File

@ -44,13 +44,9 @@
#include <QRadioButton>
#include <private/qlayoutengine_p.h>
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QLayout : public QObject
{

View File

@ -2,7 +2,7 @@ CONFIG += testcase
testcase.timeout = 600 # this test is slow
TARGET = tst_qwidget
QT += widgets core-private gui-private widgets-private testlib
QT += widgets core-private gui-private widgets-private testlib testlib-private
SOURCES += tst_qwidget.cpp
RESOURCES = qwidget.qrc

View File

@ -72,6 +72,9 @@
#endif
#include <QtTest/QTest>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
# include <QtCore/qt_windows.h>
@ -108,22 +111,6 @@ bool macHasAccessToWindowsServer()
}
#endif
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
static inline void centerOnScreen(QWidget *w)
{
const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
static inline void setWindowsAnimationsEnabled(bool enabled)
{

View File

@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qwidget_window
QT += widgets testlib core-private gui-private
QT += widgets testlib core-private gui-private testlib-private
SOURCES += tst_qwidget_window.cpp

View File

@ -45,13 +45,9 @@
#include <qtoolbar.h>
#include <private/qwindow_p.h>
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QWidget_window : public QObject
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qwidgetaction
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qwidgetaction.cpp

View File

@ -38,13 +38,9 @@
#include <qmainwindow.h>
#include <qmenubar.h>
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QWidgetAction : public QObject
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qstyle
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qstyle.cpp
android {

View File

@ -60,15 +60,9 @@
#include <algorithm>
// Make a widget frameless to prevent size constraints of title bars
// from interfering (Windows).
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QStyle : public QObject
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qstylesheetstyle
QT += widgets widgets-private gui-private testlib
QT += widgets widgets-private gui-private testlib testlib-private
SOURCES += tst_qstylesheetstyle.cpp
RESOURCES += resources.qrc

View File

@ -33,12 +33,9 @@
#include <QMetaObject>
#include <private/qstylesheetstyle_p.h>
#include <QtTest/private/qtesthelpers_p.h>
static inline void centerOnScreen(QWidget *w)
{
const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
using namespace QTestPrivate;
class tst_QStyleSheetStyle : public QObject
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TEMPLATE = app
TARGET = tst_qcompleter
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qcompleter.cpp

View File

@ -34,15 +34,11 @@
#include <QList>
#include <QPointer>
#include <QtTest/private/qtesthelpers_p.h>
#include "../../../../shared/filesystem.h"
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
using namespace QTestPrivate;
class CsvCompleter : public QCompleter
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qabstractslider
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qabstractslider.cpp

View File

@ -36,17 +36,13 @@
#include <QTime>
#include <QDebug>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
// defined to be 120 by the wheel mouse vendors according to the docs
#define WHEEL_DELTA 120
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
class Slider : public QAbstractSlider
{
public:

View File

@ -4,7 +4,7 @@
CONFIG += testcase
TARGET = tst_qabstractspinbox
QT += widgets gui-private core-private testlib
QT += widgets gui-private core-private testlib testlib-private
SOURCES += tst_qabstractspinbox.cpp

View File

@ -28,6 +28,7 @@
#include <QtTest/QtTest>
#include <QtTest/private/qtesthelpers_p.h>
#include <qcoreapplication.h>
#include <qdebug.h>
@ -38,16 +39,6 @@
#include "../../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
static inline void centerOnScreen(QWidget *w, const QSize &size)
{
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
static inline void centerOnScreen(QWidget *w)
{
centerOnScreen(w, w->geometry().size());
}
class tst_QAbstractSpinBox : public QObject
{
@ -182,7 +173,7 @@ void tst_QAbstractSpinBox::inputMethodUpdate()
QSpinBox *testWidget = &box;
testWidget->setRange(0, 1);
centerOnScreen(testWidget);
QTestPrivate::centerOnScreen(testWidget);
testWidget->clear();
testWidget->show();
QVERIFY(QTest::qWaitForWindowExposed(testWidget));

View File

@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qcombobox
QT += widgets widgets-private gui-private core-private testlib
QT += widgets widgets-private gui-private core-private testlib testlib-private
SOURCES += tst_qcombobox.cpp

View File

@ -67,13 +67,9 @@
#include "../../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
flags |= Qt::FramelessWindowHint;
flags &= ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
w->setWindowFlags(flags);
}
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
class tst_QComboBox : public QObject
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qlineedit
QT += gui-private core-private widgets widgets-private testlib
QT += gui-private core-private widgets widgets-private testlib testlib-private
SOURCES += tst_qlineedit.cpp
osx: LIBS += -framework AppKit

View File

@ -28,6 +28,7 @@
#include <QtTest/QtTest>
#include <QtTest/private/qtesthelpers_p.h>
#include "qlineedit.h"
#include "qapplication.h"
#include "qstringlist.h"
@ -74,16 +75,7 @@ QT_BEGIN_NAMESPACE
class QPainter;
QT_END_NAMESPACE
static inline void centerOnScreen(QWidget *w, const QSize &size)
{
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
static inline void centerOnScreen(QWidget *w)
{
centerOnScreen(w, w->geometry().size());
}
using namespace QTestPrivate;
class StyleOptionTestStyle : public QCommonStyle
{

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qmenu
QT += gui-private widgets testlib
QT += gui-private widgets testlib testlib-private
SOURCES += tst_qmenu.cpp
macx:{
OBJECTIVE_SOURCES += tst_qmenu_mac.mm

View File

@ -27,6 +27,7 @@
****************************************************************************/
#include <QtTest/QtTest>
#include <QtTest/private/qtesthelpers_p.h>
#include <qapplication.h>
#include <QPushButton>
#include <QMainWindow>
@ -48,15 +49,11 @@
#include <qpa/qplatformtheme.h>
using namespace QTestPrivate;
Q_DECLARE_METATYPE(Qt::Key);
Q_DECLARE_METATYPE(Qt::KeyboardModifiers);
static inline void centerOnScreen(QWidget *w, const QSize &size)
{
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
struct MenuMetrics {
int fw;
int hmargin;
@ -71,11 +68,6 @@ struct MenuMetrics {
}
};
static inline void centerOnScreen(QWidget *w)
{
centerOnScreen(w, w->geometry().size());
}
class tst_QMenu : public QObject
{
Q_OBJECT

View File

@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qmenubar
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qmenubar.cpp
macos: {

View File

@ -48,6 +48,10 @@ QT_FORWARD_DECLARE_CLASS(QMainWindow)
#include <qmenubar.h>
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
// Helper to calculate the action position in window coordinates
static inline QPoint widgetToWindowPos(const QWidget *w, const QPoint &pos)
{
@ -73,12 +77,6 @@ class Menu : public QMenu
}
};
static inline void centerOnScreen(QWidget *w)
{
const QPoint offset = QPoint(w->width() / 2, w->height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
struct TestMenu
{
QList<QMenu *> menus;

View File

@ -1,4 +1,4 @@
CONFIG += testcase
TARGET = tst_qscrollbar
QT += widgets testlib
QT += widgets testlib testlib-private
SOURCES += tst_qscrollbar.cpp

View File

@ -33,16 +33,9 @@
#include <QScrollArea>
#include <QScreen>
static inline void centerOnScreen(QWidget *w, const QSize &size)
{
const QPoint offset = QPoint(size.width() / 2, size.height() / 2);
w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset);
}
#include <QtTest/private/qtesthelpers_p.h>
static inline void centerOnScreen(QWidget *w)
{
centerOnScreen(w, w->geometry().size());
}
using namespace QTestPrivate;
class tst_QScrollBar : public QObject
{