summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/image/qimagereader/tst_qimagereader.cpp2
-rw-r--r--tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp10
-rw-r--r--tests/auto/gui/kernel/kernel.pro2
-rw-r--r--tests/auto/gui/kernel/noqteventloop/noqteventloop.pro8
-rw-r--r--tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp271
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp16
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp3
-rw-r--r--tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp6
-rw-r--r--tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp12
-rw-r--r--tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp5
10 files changed, 323 insertions, 12 deletions
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
index 3f846d25d5..fbe9669cbb 100644
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
@@ -194,7 +194,7 @@ void tst_QImageReader::initTestCase()
prefix = QFINDTESTDATA("images/");
if (prefix.isEmpty())
QFAIL("Can't find images directory!");
- QVERIFY(m_temporaryDir.isValid());
+ QVERIFY2(m_temporaryDir.isValid(), qPrintable(m_temporaryDir.errorString()));
}
void tst_QImageReader::cleanupTestCase()
diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
index fe6d7493e4..51dfe66090 100644
--- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
+++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
@@ -416,7 +416,7 @@ void tst_QImageWriter::testCanWrite()
{
// check if canWrite won't leave an empty file
QTemporaryDir dir;
- QVERIFY(dir.isValid());
+ QVERIFY2(dir.isValid(), qPrintable(dir.errorString()));
QString fileName(dir.path() + QLatin1String("/001.garble"));
QVERIFY(!QFileInfo(fileName).exists());
QImageWriter writer(fileName);
@@ -524,7 +524,7 @@ void tst_QImageWriter::saveToTemporaryFile()
{
// 1) Via QImageWriter's API, with a standard temp file name
QTemporaryFile file;
- QVERIFY(file.open());
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
QImageWriter writer(&file, "PNG");
if (writer.canWrite())
QVERIFY(writer.write(image));
@@ -538,7 +538,7 @@ void tst_QImageWriter::saveToTemporaryFile()
{
// 2) Via QImage's API, with a standard temp file name
QTemporaryFile file;
- QVERIFY(file.open());
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
QVERIFY(image.save(&file, "PNG"));
file.reset();
QImage tmp;
@@ -548,7 +548,7 @@ void tst_QImageWriter::saveToTemporaryFile()
{
// 3) Via QImageWriter's API, with a named temp file
QTemporaryFile file("tempXXXXXX");
- QVERIFY(file.open());
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
QImageWriter writer(&file, "PNG");
QVERIFY(writer.write(image));
#if defined(Q_OS_WINCE)
@@ -559,7 +559,7 @@ void tst_QImageWriter::saveToTemporaryFile()
{
// 4) Via QImage's API, with a named temp file
QTemporaryFile file("tempXXXXXX");
- QVERIFY(file.open());
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
QVERIFY(image.save(&file, "PNG"));
file.reset();
QImage tmp;
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro
index 7d47a4167d..b03a117f83 100644
--- a/tests/auto/gui/kernel/kernel.pro
+++ b/tests/auto/gui/kernel/kernel.pro
@@ -24,6 +24,8 @@ SUBDIRS=\
qopenglwindow \
qrasterwindow
+win32:!wince*:!winrt: SUBDIRS += noqteventloop
+
!qtHaveModule(widgets): SUBDIRS -= \
qmouseevent_modal \
qtouchevent
diff --git a/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro
new file mode 100644
index 0000000000..de5715e147
--- /dev/null
+++ b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro
@@ -0,0 +1,8 @@
+CONFIG += testcase
+TARGET = tst_noqteventloop
+
+QT += core-private gui-private testlib
+
+SOURCES += tst_noqteventloop.cpp
+
+contains(QT_CONFIG,dynamicgl):win32:!wince*:!winrt: LIBS += -luser32
diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp
new file mode 100644
index 0000000000..d21569dcc0
--- /dev/null
+++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp
@@ -0,0 +1,271 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QEvent>
+#include <QtCore/qthread.h>
+#include <QtGui/qguiapplication.h>
+
+#include <QtCore/qt_windows.h>
+
+class tst_NoQtEventLoop : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void cleanup();
+ void consumeMouseEvents();
+
+};
+
+void tst_NoQtEventLoop::initTestCase()
+{
+}
+
+void tst_NoQtEventLoop::cleanup()
+{
+}
+
+class Window : public QWindow
+{
+public:
+ Window(QWindow *parentWindow = 0) : QWindow(parentWindow)
+ {
+ }
+
+ void reset()
+ {
+ m_received.clear();
+ }
+
+ bool event(QEvent *event)
+ {
+ m_received[event->type()]++;
+ return QWindow::event(event);
+ }
+
+ int received(QEvent::Type type)
+ {
+ return m_received.value(type, 0);
+ }
+
+
+ QHash<QEvent::Type, int> m_received;
+};
+
+bool g_exit = false;
+
+extern "C" LRESULT QT_WIN_CALLBACK wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ if (message == WM_SHOWWINDOW && wParam == 0)
+ g_exit = true;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+}
+
+class TestThread : public QThread
+{
+ Q_OBJECT
+public:
+ TestThread(HWND parentWnd, Window *childWindow) : QThread(), m_hwnd(parentWnd), m_childWindow(childWindow) {
+ m_screenW = ::GetSystemMetrics(SM_CXSCREEN);
+ m_screenH = ::GetSystemMetrics(SM_CYSCREEN);
+ }
+
+ enum {
+ MouseClick,
+ MouseMove
+ };
+
+ void mouseInput(int command, const QPoint &p = QPoint())
+ {
+ INPUT mouseEvent;
+ mouseEvent.type = INPUT_MOUSE;
+ MOUSEINPUT &mi = mouseEvent.mi;
+ mi.mouseData = 0;
+ mi.time = 0;
+ mi.dwExtraInfo = 0;
+ mi.dx = 0;
+ mi.dy = 0;
+ switch (command) {
+ case MouseClick:
+ mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
+ ::SendInput(1, &mouseEvent, sizeof(INPUT));
+ ::Sleep(50);
+ mi.dwFlags = MOUSEEVENTF_LEFTUP;
+ ::SendInput(1, &mouseEvent, sizeof(INPUT));
+ break;
+ case MouseMove:
+ mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
+ mi.dx = p.x() * 65536 / m_screenW;
+ mi.dy = p.y() * 65536 / m_screenH;
+ ::SendInput(1, &mouseEvent, sizeof(INPUT));
+ break;
+ }
+ }
+
+ void mouseClick()
+ {
+ mouseInput(MouseClick);
+ }
+
+ void mouseMove(const QPoint &pt)
+ {
+ mouseInput(MouseMove, pt);
+ }
+
+
+ void run() {
+ struct ScopedCleanup
+ {
+ /* This is in order to ensure that the window is hidden when returning from run(),
+ regardless of the return point (e.g. with QTRY_COMPARE) */
+ ScopedCleanup(HWND hwnd) : m_hwnd(hwnd) { }
+ ~ScopedCleanup() {
+ ::ShowWindow(m_hwnd, SW_HIDE);
+ }
+ HWND m_hwnd;
+ } cleanup(m_hwnd);
+
+ m_testPassed = false;
+ POINT pt;
+ pt.x = 0;
+ pt.y = 0;
+ if (!::ClientToScreen(m_hwnd, &pt))
+ return;
+ m_windowPos = QPoint(pt.x, pt.y);
+
+
+ // First activate the parent window (which will also activate the child window)
+ m_windowPos += QPoint(5,5);
+ mouseMove(m_windowPos);
+ ::Sleep(150);
+ mouseClick();
+
+
+
+ // At this point the windows are activated, no further events will be send to the QWindow
+ // if we click on the native parent HWND
+ m_childWindow->reset();
+ ::Sleep(150);
+ mouseClick();
+ ::Sleep(150);
+
+ QTRY_COMPARE(m_childWindow->received(QEvent::MouseButtonPress) + m_childWindow->received(QEvent::MouseButtonRelease), 0);
+
+ // Now click in the QWindow. The QWindow should receive those events.
+ m_windowPos.ry() += 50;
+ mouseMove(m_windowPos);
+ ::Sleep(150);
+ mouseClick();
+ QTRY_COMPARE(m_childWindow->received(QEvent::MouseButtonPress), 1);
+ QTRY_COMPARE(m_childWindow->received(QEvent::MouseButtonRelease), 1);
+
+ m_testPassed = true;
+
+ // ScopedCleanup will hide the window here
+ // Once the native window is hidden, it will exit the event loop.
+ }
+
+ bool passed() const { return m_testPassed; }
+
+private:
+ int m_screenW;
+ int m_screenH;
+ bool m_testPassed;
+ HWND m_hwnd;
+ Window *m_childWindow;
+ QPoint m_windowPos;
+
+};
+
+
+void tst_NoQtEventLoop::consumeMouseEvents()
+{
+ int argc = 1;
+ char *argv[] = {const_cast<char*>("test")};
+ QGuiApplication app(argc, argv);
+ QString clsName(QStringLiteral("tst_NoQtEventLoop_WINDOW"));
+ const HINSTANCE appInstance = (HINSTANCE)GetModuleHandle(0);
+ WNDCLASSEX wc;
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.style = CS_DBLCLKS | CS_OWNDC; // CS_SAVEBITS
+ wc.lpfnWndProc = wndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = appInstance;
+ wc.hIcon = 0;
+ wc.hIconSm = 0;
+ wc.hCursor = 0;
+ wc.hbrBackground = ::GetSysColorBrush(COLOR_BTNFACE /*COLOR_WINDOW*/);
+ wc.lpszMenuName = 0;
+ wc.lpszClassName = (wchar_t*)clsName.utf16();
+
+ ATOM atom = ::RegisterClassEx(&wc);
+ QVERIFY2(atom, "RegisterClassEx failed");
+
+ DWORD dwExStyle = WS_EX_APPWINDOW;
+ DWORD dwStyle = WS_CAPTION | WS_HSCROLL | WS_TABSTOP | WS_VISIBLE;
+
+ HWND mainWnd = ::CreateWindowEx(dwExStyle, (wchar_t*)clsName.utf16(), TEXT("tst_NoQtEventLoop"), dwStyle, 100, 100, 300, 300, 0, NULL, appInstance, NULL);
+ QVERIFY2(mainWnd, "CreateWindowEx failed");
+
+ ::ShowWindow(mainWnd, SW_SHOW);
+
+ Window *childWindow = new Window;
+ childWindow->setParent(QWindow::fromWinId((WId)mainWnd));
+ childWindow->setGeometry(0, 50, 200, 200);
+ childWindow->show();
+
+ TestThread *testThread = new TestThread(mainWnd, childWindow);
+ connect(testThread, SIGNAL(finished()), testThread, SLOT(deleteLater()));
+ testThread->start();
+
+ // Our own message loop...
+ MSG msg;
+ while (::GetMessage(&msg, NULL, 0, 0) > 0) {
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
+ if (g_exit)
+ break;
+ }
+
+ QCOMPARE(testThread->passed(), true);
+
+}
+
+#include <tst_noqteventloop.moc>
+
+QTEST_APPLESS_MAIN(tst_NoQtEventLoop)
+
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index 2c363e3d69..ea8f594f9c 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -60,6 +60,7 @@ class tst_QGuiApplication: public tst_QCoreApplication
Q_OBJECT
private slots:
+ void initTestCase();
void cleanup();
void displayName();
void desktopFileName();
@@ -85,6 +86,21 @@ private slots:
void settableStyleHints(); // Needs to run last as it changes style hints.
};
+void tst_QGuiApplication::initTestCase()
+{
+#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
+ if ((QString::compare(QStringLiteral(QT_QPA_DEFAULT_PLATFORM_NAME),
+ QStringLiteral("eglfs"), Qt::CaseInsensitive) == 0) ||
+ (QString::compare(QString::fromLatin1(qgetenv("QT_QPA_PLATFORM")),
+ QStringLiteral("eglfs"), Qt::CaseInsensitive) == 0)) {
+ // Set env variables to disable input and cursor because eglfs is single fullscreen window
+ // and trying to initialize input and cursor will crash test.
+ qputenv("QT_QPA_EGLFS_DISABLE_INPUT", "1");
+ qputenv("QT_QPA_EGLFS_HIDECURSOR", "1");
+ }
+#endif
+}
+
void tst_QGuiApplication::cleanup()
{
QVERIFY(QGuiApplication::allWindows().isEmpty());
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 210939c7f0..1e7e858bed 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -5025,6 +5025,7 @@ void tst_QPainter::drawPolyline_data()
QTest::newRow("basic") << (QVector<QPointF>() << QPointF(10, 10) << QPointF(20, 10) << QPointF(20, 20) << QPointF(10, 20));
QTest::newRow("clipped") << (QVector<QPointF>() << QPoint(-10, 100) << QPoint(-1, 100) << QPoint(-1, -2) << QPoint(100, -2) << QPoint(100, 40)); // QTBUG-31579
QTest::newRow("shortsegment") << (QVector<QPointF>() << QPoint(20, 100) << QPoint(20, 99) << QPoint(21, 99) << QPoint(21, 104)); // QTBUG-42398
+ QTest::newRow("edge") << (QVector<QPointF>() << QPointF(4.5, 121.6) << QPointF(9.4, 150.9) << QPointF(14.2, 184.8) << QPointF(19.1, 130.4));
}
void tst_QPainter::drawPolyline()
@@ -5034,7 +5035,7 @@ void tst_QPainter::drawPolyline()
for (int r = 0; r < 2; r++) {
images[r] = QImage(150, 150, QImage::Format_ARGB32);
- images[r].fill(Qt::transparent);
+ images[r].fill(Qt::white);
QPainter p(images + r);
QPen pen(Qt::red, 0, Qt::SolidLine, Qt::FlatCap);
p.setPen(pen);
diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
index 4bc31baba8..5eaee1192a 100644
--- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
+++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
@@ -50,8 +50,7 @@ private slots:
void tst_QPdfWriter::basics()
{
QTemporaryFile file;
- if (!file.open())
- QSKIP("Couldn't open temp file!");
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
QPdfWriter writer(file.fileName());
QCOMPARE(writer.title(), QString());
@@ -150,8 +149,7 @@ void tst_QPdfWriter::testPageMetrics()
QSizeF sizeMMf = QSizeF(widthMMf, heightMMf);
QTemporaryFile file;
- if (!file.open())
- QSKIP("Couldn't open temp file!");
+ QVERIFY2(file.open(), qPrintable(file.errorString()));
QPdfWriter writer(file.fileName());
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
index d8e9836112..ec62bafd6c 100644
--- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
+++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
@@ -65,6 +65,7 @@ private slots:
void inFontUcs4();
void lineWidth();
void mnemonicTextWidth();
+ void leadingBelowLine();
};
tst_QFontMetrics::tst_QFontMetrics()
@@ -343,5 +344,16 @@ void tst_QFontMetrics::mnemonicTextWidth()
QCOMPARE(fm.size(Qt::TextShowMnemonic, f1), fm.size(Qt::TextShowMnemonic, f2));
QCOMPARE(fm.size(Qt::TextHideMnemonic, f1), fm.size(Qt::TextHideMnemonic, f2));
}
+
+void tst_QFontMetrics::leadingBelowLine()
+{
+ QScriptLine line;
+ line.leading = 10;
+ line.leadingIncluded = true;
+ line.ascent = 5;
+ QCOMPARE(line.height(), line.ascent + line.descent + line.leading);
+ QCOMPARE(line.base(), line.ascent);
+}
+
QTEST_MAIN(tst_QFontMetrics)
#include "tst_qfontmetrics.moc"
diff --git a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp
index c8964eb02c..db4b15530c 100644
--- a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp
+++ b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp
@@ -35,6 +35,7 @@
#include <QtTest/QtTest>
#include <qdebug.h>
#include <qdesktopservices.h>
+#include <qregularexpression.h>
class tst_qdesktopservices : public QObject
{
@@ -74,7 +75,9 @@ void tst_qdesktopservices::openUrl()
QCOMPARE(QDesktopServices::openUrl(QUrl()), false);
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
// this test is only valid on windows on other systems it might mean open a new document in the application handling .file
- QTest::ignoreMessage(QtWarningMsg, "ShellExecute 'file://invalid.file' failed (error 3).");
+ const QRegularExpression messagePattern("ShellExecute 'file://invalid\\.file' failed \\(error \\d+\\)\\.");
+ QVERIFY(messagePattern.isValid());
+ QTest::ignoreMessage(QtWarningMsg, messagePattern);
QCOMPARE(QDesktopServices::openUrl(QUrl("file://invalid.file")), false);
#endif
}