diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-26 16:08:55 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-26 16:14:54 +0200 |
commit | aadfe7d634de04519102c5827ca885dc2e2199c9 (patch) | |
tree | d92db346ca95332b177036a53f1f6beb2e24fb74 /tests/auto | |
parent | 4b6c1448047362b8c38d265e6414f0e3e59b8d37 (diff) | |
parent | a732e16d5fd9dbf8a0289fec9f948b12e9ba2c19 (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/gui/kernel/qguiapplication.cpp
src/platformsupport/input/libinput/qlibinputpointer.cpp
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
src/plugins/platforms/cocoa/qcocoawindow.h
src/testlib/qtestsystem.h
Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
Diffstat (limited to 'tests/auto')
32 files changed, 485 insertions, 166 deletions
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp index 71c6c4e9cd..bf43f6d710 100644 --- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp +++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp @@ -73,37 +73,37 @@ public slots: void cleanup() { setRNGControl(0); } private slots: - void get32_data(); - void get32(); - void get64_data() { get32_data(); } - void get64(); - void quality_data() { get32_data(); } + void generate32_data(); + void generate32(); + void generate64_data() { generate32_data(); } + void generate64(); + void quality_data() { generate32_data(); } void quality(); - void fillRangeUInt_data() { get32_data(); } + void fillRangeUInt_data() { generate32_data(); } void fillRangeUInt(); - void fillRangeULong_data() { get32_data(); } + void fillRangeULong_data() { generate32_data(); } void fillRangeULong(); - void fillRangeULLong_data() { get32_data(); } + void fillRangeULLong_data() { generate32_data(); } void fillRangeULLong(); - void generateUInt_data() { get32_data(); } + void generateUInt_data() { generate32_data(); } void generateUInt(); - void generateULLong_data() { get32_data(); } + void generateULLong_data() { generate32_data(); } void generateULLong(); - void generateNonContiguous_data() { get32_data(); } + void generateNonContiguous_data() { generate32_data(); } void generateNonContiguous(); void bounded_data(); void bounded(); - void boundedQuality_data() { get32_data(); } + void boundedQuality_data() { generate32_data(); } void boundedQuality(); - void getReal_data() { get32_data(); } - void getReal(); + void generateReal_data() { generate32_data(); } + void generateReal(); void seedStdRandomEngines(); void stdUniformIntDistribution_data(); void stdUniformIntDistribution(); - void stdGenerateCanonical_data() { getReal_data(); } + void stdGenerateCanonical_data() { generateReal_data(); } void stdGenerateCanonical(); void stdUniformRealDistribution_data(); void stdUniformRealDistribution(); @@ -114,7 +114,7 @@ using namespace std; QT_WARNING_DISABLE_GCC("-Wfloat-equal") QT_WARNING_DISABLE_CLANG("-Wfloat-equal") -void tst_QRandomGenerator::get32_data() +void tst_QRandomGenerator::generate32_data() { QTest::addColumn<uint>("control"); QTest::newRow("default") << 0U; @@ -127,42 +127,42 @@ void tst_QRandomGenerator::get32_data() #endif } -void tst_QRandomGenerator::get32() +void tst_QRandomGenerator::generate32() { QFETCH(uint, control); setRNGControl(control); for (int i = 0; i < 4; ++i) { QVERIFY_3TIMES([] { - quint32 value = QRandomGenerator::get32(); + quint32 value = QRandomGenerator::generate(); return value != 0 && value != RandomValue32; }()); } // and should hopefully be different from repeated calls for (int i = 0; i < 4; ++i) - QVERIFY_3TIMES(QRandomGenerator::get32() != QRandomGenerator::get32()); + QVERIFY_3TIMES(QRandomGenerator::generate() != QRandomGenerator::generate()); } -void tst_QRandomGenerator::get64() +void tst_QRandomGenerator::generate64() { QFETCH(uint, control); setRNGControl(control); for (int i = 0; i < 4; ++i) { QVERIFY_3TIMES([] { - quint64 value = QRandomGenerator::get32(); + quint64 value = QRandomGenerator::generate(); return value != 0 && value != RandomValue32 && value != RandomValue64; }()); } // and should hopefully be different from repeated calls for (int i = 0; i < 4; ++i) - QVERIFY_3TIMES(QRandomGenerator::get64() != QRandomGenerator::get64()); + QVERIFY_3TIMES(QRandomGenerator::generate64() != QRandomGenerator::generate64()); for (int i = 0; i < 4; ++i) - QVERIFY_3TIMES(QRandomGenerator::get32() != quint32(QRandomGenerator::get64())); + QVERIFY_3TIMES(QRandomGenerator::generate() != quint32(QRandomGenerator::generate64())); for (int i = 0; i < 4; ++i) - QVERIFY_3TIMES(QRandomGenerator::get32() != (QRandomGenerator::get64() >> 32)); + QVERIFY_3TIMES(QRandomGenerator::generate() != (QRandomGenerator::generate64() >> 32)); } void tst_QRandomGenerator::quality() @@ -200,7 +200,7 @@ void tst_QRandomGenerator::quality() // test the quality of the generator quint32 buffer[BufferCount]; memset(buffer, 0xcc, sizeof(buffer)); - generate_n(buffer, +BufferCount, [] { return QRandomGenerator::get32(); }); + generate_n(buffer, +BufferCount, [] { return QRandomGenerator::generate(); }); quint8 *ptr = reinterpret_cast<quint8 *>(buffer); quint8 *end = ptr + sizeof(buffer); @@ -439,21 +439,21 @@ void tst_QRandomGenerator::boundedQuality() << "at" << std::min_element(begin(histogram), end(histogram)) - histogram; } -void tst_QRandomGenerator::getReal() +void tst_QRandomGenerator::generateReal() { QFETCH(uint, control); setRNGControl(control); for (int i = 0; i < 4; ++i) { QVERIFY_3TIMES([] { - qreal value = QRandomGenerator::getReal(); + qreal value = QRandomGenerator::generateDouble(); return value > 0 && value < 1 && value != RandomValueFP; }()); } // and should hopefully be different from repeated calls for (int i = 0; i < 4; ++i) - QVERIFY_3TIMES(QRandomGenerator::getReal() != QRandomGenerator::getReal()); + QVERIFY_3TIMES(QRandomGenerator::generateDouble() != QRandomGenerator::generateDouble()); } template <typename Engine> void seedStdRandomEngine() diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index e6bad9a8ef..8dbac28183 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -394,7 +394,7 @@ void tst_QDir::mkdirRmdir() void tst_QDir::mkdirOnSymlink() { -#ifndef Q_OS_UNIX +#if !defined(Q_OS_UNIX) || defined(Q_NO_SYMLINKS) QSKIP("Test only valid on an OS that supports symlinks"); #else // Create the structure: @@ -1662,9 +1662,7 @@ void tst_QDir::homePath() QVERIFY(!strHome.endsWith('/')); QByteArray envHome = qgetenv("HOME"); -#if !defined(_WRS_KERNEL) // unsetenv is not available on VxWorks DKM mode unsetenv("HOME"); -#endif QCOMPARE(QDir::homePath(), QDir::rootPath()); qputenv("HOME", envHome); diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index a7dc869805..8945daff4a 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1491,21 +1491,27 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() QVERIFY2(file.exists(), msgDoesNotExist(file.fileName()).constData()); QTest::newRow("absolute dir symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath(); - QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalPath(); + QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath(); QTest::newRow("file in symlink dir") << fileInSymlink << false << "" << target.canonicalPath().append("/file"); } { //File symlinks + pwd.mkdir("relative"); + QDir relativeDir("relative"); QFileInfo target(m_sourceFile); QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath()); QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp"); QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath())); QString relSymlink = "rel_symlink.cpp"; + QString relToRelTarget = QDir::toNativeSeparators(relativeDir.relativeFilePath(target.absoluteFilePath())); + QString relToRelSymlink = "relative/rel_symlink"; QVERIFY(pwd.exists("abs_symlink.cpp") || createSymbolicLinkW((wchar_t*)absSymlink.utf16(),(wchar_t*)absTarget.utf16(),0x0)); QVERIFY(pwd.exists(relSymlink) || createSymbolicLinkW((wchar_t*)relSymlink.utf16(),(wchar_t*)relTarget.utf16(),0x0)); - + QVERIFY(pwd.exists(relToRelSymlink) + || createSymbolicLinkW((wchar_t*)relToRelSymlink.utf16(), (wchar_t*)relToRelTarget.utf16(),0x0)); QTest::newRow("absolute file symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath(); - QTest::newRow("relative file symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalFilePath(); + QTest::newRow("relative file symlink") << relSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath(); + QTest::newRow("relative to relative file symlink") << relToRelSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalFilePath(); } //Junctions diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index 75b98bcd09..b5b64973d3 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -41,3 +41,6 @@ SUBDIRS=\ !win32*|winrt: SUBDIRS -= qwineventnotifier android|uikit: SUBDIRS -= qclipboard qobject qsharedmemory qsystemsemaphore + +!qtConfig(systemsemaphore): SUBDIRS -= \ + qsystemsemaphore diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 0962001741..7fb9a861d7 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -99,6 +99,9 @@ void tst_QMutex::convertToMilliseconds_data() QTest::addColumn<qint64>("intValue"); QTest::addColumn<qint64>("expected"); +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#endif auto add = [](TimeUnit unit, double d, long long i, qint64 expected) { const QScopedArrayPointer<char> enumName(QTest::toString(unit)); diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro b/tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro new file mode 100644 index 0000000000..26b3a47472 --- /dev/null +++ b/tests/auto/corelib/tools/qmacautoreleasepool/qmacautoreleasepool.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qmacautoreleasepool +QT = core testlib +SOURCES = tst_qmacautoreleasepool.mm diff --git a/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm new file mode 100644 index 0000000000..8f1069f419 --- /dev/null +++ b/tests/auto/corelib/tools/qmacautoreleasepool/tst_qmacautoreleasepool.mm @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <Foundation/Foundation.h> + +class tst_QMacAutoreleasePool : public QObject +{ + Q_OBJECT +private slots: + void noPool(); + void rootLevelPool(); + void stackAllocatedPool(); + void heapAllocatedPool(); +}; + +static id lastDeallocedObject = nil; + +@interface DeallocTracker : NSObject @end +@implementation DeallocTracker +-(void)dealloc +{ + lastDeallocedObject = self; + [super dealloc]; +} +@end + +void tst_QMacAutoreleasePool::noPool() +{ + // No pool, will not be released, but should not crash + + [[[DeallocTracker alloc] init] autorelease]; +} + +void tst_QMacAutoreleasePool::rootLevelPool() +{ + // The root level case, no NSAutoreleasePool since we're not in the main + // runloop, and objects autoreleased as part of main. + + NSObject *allocedObject = nil; + { + QMacAutoReleasePool qtPool; + allocedObject = [[[DeallocTracker alloc] init] autorelease]; + } + QCOMPARE(lastDeallocedObject, allocedObject); +} + +void tst_QMacAutoreleasePool::stackAllocatedPool() +{ + // The normal case, other pools surrounding our pool, draining + // our pool before any other pool. + + NSObject *allocedObject = nil; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + { + QMacAutoReleasePool qtPool; + allocedObject = [[[DeallocTracker alloc] init] autorelease]; + } + QCOMPARE(lastDeallocedObject, allocedObject); + [pool drain]; +} + +void tst_QMacAutoreleasePool::heapAllocatedPool() +{ + // The special case, a pool allocated on the heap, or as a member of a + // heap allocated object. This is not a supported use of QMacAutoReleasePool, + // and will result in warnings if the pool is prematurely drained. + + NSObject *allocedObject = nil; + { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool *qtPool = nullptr; + { + qtPool = new QMacAutoReleasePool; + allocedObject = [[[DeallocTracker alloc] init] autorelease]; + } + [pool drain]; + delete qtPool; + } + QCOMPARE(lastDeallocedObject, allocedObject); +} + +QTEST_APPLESS_MAIN(tst_QMacAutoreleasePool) + +#include "tst_qmacautoreleasepool.moc" diff --git a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp index 9617afb651..48ea5a794c 100644 --- a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp @@ -136,6 +136,7 @@ class tst_QStringView : public QObject private Q_SLOTS: void constExpr() const; void basics() const; + void literals() const; void at() const; void fromQString() const; @@ -305,6 +306,12 @@ void tst_QStringView::constExpr() const Q_STATIC_ASSERT(!sv2.isNull()); Q_STATIC_ASSERT(!sv2.empty()); Q_STATIC_ASSERT(sv2.size() == 5); + + constexpr char16_t *null = nullptr; + constexpr QStringView sv3(null); + Q_STATIC_ASSERT(sv3.isNull()); + Q_STATIC_ASSERT(sv3.isEmpty()); + Q_STATIC_ASSERT(sv3.size() == 0); } #else // storage_type is wchar_t { @@ -328,6 +335,12 @@ void tst_QStringView::constExpr() const Q_STATIC_ASSERT(!sv2.isNull()); Q_STATIC_ASSERT(!sv2.empty()); Q_STATIC_ASSERT(sv2.size() == 5); + + constexpr wchar_t *null = nullptr; + constexpr QStringView sv3(null); + Q_STATIC_ASSERT(sv3.isNull()); + Q_STATIC_ASSERT(sv3.isEmpty()); + Q_STATIC_ASSERT(sv3.size() == 0); } #endif #endif @@ -348,6 +361,37 @@ void tst_QStringView::basics() const QVERIFY(!(sv2 != sv1)); } +void tst_QStringView::literals() const +{ +#if !defined(Q_OS_WIN) || defined(Q_COMPILER_UNICODE_STRINGS) + // the + ensures it's a pointer, not an array + QCOMPARE(QStringView(+u"Hello").size(), 5); + QStringView sv = u"Hello"; +#else // storage_type is wchar_t + // the + ensures it's a pointer, not an array + QCOMPARE(QStringView(+L"Hello").size(), 5); + QStringView sv = L"Hello"; +#endif + QCOMPARE(sv.size(), 5); + QVERIFY(!sv.empty()); + QVERIFY(!sv.isEmpty()); + QVERIFY(!sv.isNull()); + QCOMPARE(*sv.utf16(), 'H'); + QCOMPARE(sv[0], QLatin1Char('H')); + QCOMPARE(sv.at(0), QLatin1Char('H')); + QCOMPARE(sv.front(), QLatin1Char('H')); + QCOMPARE(sv.first(), QLatin1Char('H')); + QCOMPARE(sv[4], QLatin1Char('o')); + QCOMPARE(sv.at(4), QLatin1Char('o')); + QCOMPARE(sv.back(), QLatin1Char('o')); + QCOMPARE(sv.last(), QLatin1Char('o')); + + QStringView sv2(sv.utf16(), sv.utf16() + sv.size()); + QVERIFY(!sv2.isNull()); + QVERIFY(!sv2.empty()); + QCOMPARE(sv2.size(), 5); +} + void tst_QStringView::at() const { QString hello("Hello"); diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index 6720307d59..f35ed026ac 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -67,3 +67,4 @@ SUBDIRS=\ qvector_strictiterators \ qversionnumber +darwin: SUBDIRS += qmacautoreleasepool diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 0e65f6a23d..235d53f3c1 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -69,6 +69,7 @@ private slots: void convertToFormat_data(); void convertToFormat(); + void convertToFormatWithColorTable(); void convertToFormatRgb888ToRGB32(); @@ -959,6 +960,18 @@ void tst_QImage::convertToFormat() QFile::remove(QLatin1String("expected2.xpm")); } +void tst_QImage::convertToFormatWithColorTable() +{ + QVector<QRgb> colors(2); + colors[0] = 0xFF000000; + colors[1] = 0xFFFFFFFF; + for (int format = QImage::Format_RGB32; format < QImage::Format_Alpha8; ++format) { + QImage fromImage(10, 10, (QImage::Format)format); + QImage bitmap = fromImage.convertToFormat(QImage::Format_Mono, colors); + QVERIFY(!bitmap.isNull()); + } +} + void tst_QImage::convertToFormatRgb888ToRGB32() { // 545 so width % 4 != 0. This ensure there is padding at the end of the scanlines diff --git a/tests/auto/gui/qopengl/BLACKLIST b/tests/auto/gui/qopengl/BLACKLIST index 7f167d81df..a16327d411 100644 --- a/tests/auto/gui/qopengl/BLACKLIST +++ b/tests/auto/gui/qopengl/BLACKLIST @@ -6,3 +6,5 @@ windows windows [openGLPaintDevice] windows +[wglContextWrap] +windows-7 diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp index 3711ce431c..fba0508f04 100644 --- a/tests/auto/network/access/qftp/tst_qftp.cpp +++ b/tests/auto/network/access/qftp/tst_qftp.cpp @@ -186,7 +186,7 @@ void tst_QFtp::initTestCase_data() QTest::addColumn<bool>("setSession"); QTest::newRow("WithoutProxy") << false << 0 << false; -#ifndef QT_NO_SOCKS5 +#if QT_CONFIG(socks5) QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy) << false; #endif //### doesn't work well yet. @@ -194,7 +194,7 @@ void tst_QFtp::initTestCase_data() #ifndef QT_NO_BEARERMANAGEMENT QTest::newRow("WithoutProxyWithSession") << false << 0 << true; -#ifndef QT_NO_SOCKS5 +#if QT_CONFIG(socks5) QTest::newRow("WithSocks5ProxyAndSession") << true << int(QNetworkProxy::Socks5Proxy) << true; #endif #endif diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 906566483d..40e909113e 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -5811,6 +5811,15 @@ void tst_QNetworkReply::proxyChange() QNetworkRequest req(QUrl("http://" + QtNetworkSettings::serverName())); proxyServer.doClose = false; + { + // Needed to initialize a network session in QNAM. Without an initialized session the GET + // will be deferred until later, and the proxy will be unset first. This caused the test to + // fail in standalone runs (it passed in CI because the same QNAM instance is used for the + // entire test). + QNetworkReplyPtr temporary(manager.get(req)); + waitForFinish(temporary); + } + manager.setProxy(dummyProxy); QNetworkReplyPtr reply1(manager.get(req)); connect(reply1, SIGNAL(finished()), &helper, SLOT(finishedSlot())); diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp index 5695f90c53..94c355aadc 100644 --- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp +++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp @@ -32,7 +32,7 @@ #include <qcoreapplication.h> #include <qnetworkinterface.h> -#include <qtcpsocket.h> +#include <qudpsocket.h> #ifndef QT_NO_BEARERMANAGEMENT #include <QNetworkConfigurationManager> #include <QNetworkSession> @@ -48,6 +48,8 @@ public: tst_QNetworkInterface(); virtual ~tst_QNetworkInterface(); + bool isIPv6Working(); + private slots: void initTestCase(); void cleanupTestCase(); @@ -76,6 +78,13 @@ tst_QNetworkInterface::~tst_QNetworkInterface() { } +bool tst_QNetworkInterface::isIPv6Working() +{ + QUdpSocket socket; + socket.connectToHost(QHostAddress::LocalHostIPv6, 1234); + return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100); +} + void tst_QNetworkInterface::initTestCase() { if (!QtNetworkSettings::verifyTestNetworkSettings()) @@ -172,34 +181,20 @@ void tst_QNetworkInterface::loopbackIPv4() void tst_QNetworkInterface::loopbackIPv6() { + if (!isIPv6Working()) + QSKIP("IPv6 not active on this machine"); QList<QHostAddress> all = QNetworkInterface::allAddresses(); - - bool loopbackfound = false; - bool anyIPv6 = false; - foreach (QHostAddress addr, all) - if (addr == QHostAddress::LocalHostIPv6) { - loopbackfound = true; - anyIPv6 = true; - break; - } else if (addr.protocol() == QAbstractSocket::IPv6Protocol) - anyIPv6 = true; - - QVERIFY(!anyIPv6 || loopbackfound); + QVERIFY(all.contains(QHostAddress(QHostAddress::LocalHostIPv6))); } void tst_QNetworkInterface::localAddress() { - QTcpSocket socket; + QUdpSocket socket; socket.connectToHost(QtNetworkSettings::serverName(), 80); QVERIFY(socket.waitForConnected(5000)); QHostAddress local = socket.localAddress(); - // make Apache happy on fluke - socket.write("GET / HTTP/1.0\r\n\r\n"); - socket.waitForBytesWritten(1000); - socket.close(); - // test that we can find the address that QTcpSocket reported QList<QHostAddress> all = QNetworkInterface::allAddresses(); QVERIFY(all.contains(local)); diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/BLACKLIST b/tests/auto/network/kernel/qnetworkproxyfactory/BLACKLIST deleted file mode 100644 index 73570c98b7..0000000000 --- a/tests/auto/network/kernel/qnetworkproxyfactory/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[genericSystemProxy] -ubuntu-14.04 diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/qnetworkproxyfactory.pro b/tests/auto/network/kernel/qnetworkproxyfactory/qnetworkproxyfactory.pro index ed73e3e10e..a7fa43015f 100644 --- a/tests/auto/network/kernel/qnetworkproxyfactory/qnetworkproxyfactory.pro +++ b/tests/auto/network/kernel/qnetworkproxyfactory/qnetworkproxyfactory.pro @@ -4,6 +4,6 @@ CONFIG += testcase TARGET = tst_qnetworkproxyfactory -QT = core network testlib +QT = core network-private testlib SOURCES += tst_qnetworkproxyfactory.cpp diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp index 81d598641b..f3a1ac84ff 100644 --- a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp +++ b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp @@ -42,6 +42,8 @@ #include <QSysInfo> #include <QThread> +#include <private/qtnetworkglobal_p.h> + class tst_QNetworkProxyFactory : public QObject { Q_OBJECT @@ -255,7 +257,7 @@ void tst_QNetworkProxyFactory::genericSystemProxy() QFETCH(int, port); // The generic system proxy is only available on the following platforms -#if (!defined Q_OS_WIN) && (!defined Q_OS_OSX) +#if (!defined Q_OS_WIN) && (!defined Q_OS_OSX) && !QT_CONFIG(libproxy) qputenv(envVar, url); const QList<QNetworkProxy> systemProxy = QNetworkProxyFactory::systemProxyForQuery(); QCOMPARE(systemProxy.size(), 1); diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp index 43b5422635..bc53faf106 100644 --- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp +++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp @@ -76,7 +76,9 @@ private slots: void serverTest(); void udpLoopbackPerformance(); void tcpLoopbackPerformance(); +#if 0 void readWriteBufferSize(); +#endif void bind(); void networkError(); void setSocketDescriptor(); @@ -485,6 +487,7 @@ void tst_PlatformSocketEngine::tcpLoopbackPerformance() (readBytes / (timer.elapsed() / 1000.0)) / (1024 * 1024)); } +#if 0 // unused //--------------------------------------------------------------------------- void tst_PlatformSocketEngine::readWriteBufferSize() { @@ -503,6 +506,7 @@ void tst_PlatformSocketEngine::readWriteBufferSize() QVERIFY(device.sendBufferSize() > bufferSize); } +#endif //--------------------------------------------------------------------------- void tst_PlatformSocketEngine::tooManySockets() diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp index c4432c83ee..31f82539aa 100644 --- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -149,7 +149,7 @@ void tst_QTcpServer::initTestCase_data() QTest::addColumn<int>("proxyType"); QTest::newRow("WithoutProxy") << false << 0; -#ifndef QT_NO_SOCKS5 +#if QT_CONFIG(socks5) QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); #endif diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index af7cf24838..aeb6e61cd2 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -205,7 +205,7 @@ void tst_QUdpSocket::initTestCase_data() QTest::addColumn<int>("proxyType"); QTest::newRow("WithoutProxy") << false << 0; -#ifndef QT_NO_SOCKS5 +#if QT_CONFIG(socks5) if (!newTestServer) QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); #endif @@ -233,14 +233,14 @@ void tst_QUdpSocket::init() { QFETCH_GLOBAL(bool, setProxy); if (setProxy) { -#ifndef QT_NO_SOCKS5 +#if QT_CONFIG(socks5) QFETCH_GLOBAL(int, proxyType); if (proxyType == QNetworkProxy::Socks5Proxy) { QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080)); } #else QSKIP("No proxy support"); -#endif // !QT_NO_SOCKS5 +#endif // QT_CONFIG(socks5) } } diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 74bdcfc5f0..12588c5e29 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -237,6 +237,7 @@ private slots: void ephemeralServerKey(); void allowedProtocolNegotiation(); void pskServer(); + void forwardReadChannelFinished(); #endif void setEmptyDefaultConfiguration(); // this test should be last @@ -3838,6 +3839,28 @@ void tst_QSslSocket::pskServer() QCOMPARE(disconnectedSpy.count(), 1); } +void tst_QSslSocket::forwardReadChannelFinished() +{ + if (!QSslSocket::supportsSsl()) + QSKIP("Needs SSL"); + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + QSKIP("This test doesn't work via a proxy"); + + QSslSocket socket; + QSignalSpy readChannelFinishedSpy(&socket, &QAbstractSocket::readChannelFinished); + connect(&socket, &QSslSocket::encrypted, [&socket]() { + const auto data = QString("GET /ip HTTP/1.0\r\nHost: %1\r\n\r\nAccept: */*\r\n\r\n") + .arg(QtNetworkSettings::serverLocalName()).toUtf8(); + socket.write(data); + }); + connect(&socket, &QSslSocket::readChannelFinished, + &QTestEventLoop::instance(), &QTestEventLoop::exitLoop); + socket.connectToHostEncrypted(QtNetworkSettings::serverLocalName(), 443); + enterLoop(10); + QVERIFY(readChannelFinishedSpy.count()); +} + #endif // QT_NO_OPENSSL #endif // QT_NO_SSL diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp index cc32e73b9c..88bae686ab 100644 --- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp +++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp @@ -83,7 +83,7 @@ private slots: void customPaperSizeAndMargins(); void customPaperNameSettingBySize(); void customPaperNameSettingByName(); -#if !defined(QT_NO_COMPLETER) && QT_CONFIG(filedialog) +#if QT_CONFIG(completer) && QT_CONFIG(filedialog) void printDialogCompleter(); #endif void testCurrentPage(); @@ -587,7 +587,7 @@ void tst_QPrinter::customPaperSizeAndMargins() } } -#if !defined(QT_NO_COMPLETER) && QT_CONFIG(filedialog) +#if QT_CONFIG(completer) && QT_CONFIG(filedialog) void tst_QPrinter::printDialogCompleter() { QPrintDialog dialog; diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp index e3f088e763..9b0d5b6920 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp @@ -754,8 +754,8 @@ void tst_QSqlDatabase::recordOCI() FieldDef("long raw", QVariant::ByteArray, QByteArray("blah5")), FieldDef("raw(2000)", QVariant::ByteArray, QByteArray("blah6"), false), FieldDef("blob", QVariant::ByteArray, QByteArray("blah7")), - FieldDef("clob", QVariant::String, QString("blah8")), - FieldDef("nclob", QVariant::String, QString("blah9")), + FieldDef("clob", QVariant::ByteArray, QByteArray("blah8")), + FieldDef("nclob", QVariant::ByteArray, QByteArray("blah9")), // FieldDef("bfile", QVariant::ByteArray, QByteArray("blah10")), intytm, diff --git a/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp b/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp index a19c849b4d..8f8cfe009d 100644 --- a/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp +++ b/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp @@ -72,7 +72,13 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); tst_Databases::safeDropTable( db, relTEST1 ); - QString doubleField = (dbType == QSqlDriver::SQLite) ? "more_data double" : "more_data double(8,7)"; + QString doubleField; + if (dbType == QSqlDriver::SQLite) + doubleField = "more_data double"; + else if (dbType == QSqlDriver::Oracle) + doubleField = "more_data number(8,7)"; + else + doubleField = "more_data double(8,7)"; QVERIFY_SQL( q, exec("create table " + relTEST1 + " (id int not null primary key, name varchar(20), title_key int, another_title_key int, " + doubleField + QLatin1Char(')'))); QVERIFY_SQL( q, exec("insert into " + relTEST1 + " values(1, 'harry', 1, 2, 1.234567)")); diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index d3bc83fe6d..d704d212dd 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -73,7 +73,7 @@ private slots: void toolDialogPosition(); void deleteMainDefault(); void deleteInExec(); -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) void showSizeGrip(); #endif void setVisible(); @@ -235,7 +235,7 @@ void tst_QDialog::showMaximized() { QDialog dialog(0); dialog.setSizeGripEnabled(true); -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) QSizeGrip *sizeGrip = dialog.findChild<QSizeGrip *>(); QVERIFY(sizeGrip); #endif @@ -243,14 +243,14 @@ void tst_QDialog::showMaximized() dialog.showMaximized(); QVERIFY(dialog.isMaximized()); QVERIFY(dialog.isVisible()); -#if !defined(QT_NO_SIZEGRIP) && !defined(Q_OS_MAC) && !defined(Q_OS_IRIX) && !defined(Q_OS_HPUX) +#if QT_CONFIG(sizegrip) && !defined(Q_OS_DARWIN) && !defined(Q_OS_IRIX) && !defined(Q_OS_HPUX) QVERIFY(!sizeGrip->isVisible()); #endif dialog.showNormal(); QVERIFY(!dialog.isMaximized()); QVERIFY(dialog.isVisible()); -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) QVERIFY(sizeGrip->isVisible()); #endif @@ -312,7 +312,7 @@ void tst_QDialog::showFullScreen() { QDialog dialog(0, Qt::X11BypassWindowManagerHint); dialog.setSizeGripEnabled(true); -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) QSizeGrip *sizeGrip = dialog.findChild<QSizeGrip *>(); QVERIFY(sizeGrip); #endif @@ -320,14 +320,14 @@ void tst_QDialog::showFullScreen() dialog.showFullScreen(); QVERIFY(dialog.isFullScreen()); QVERIFY(dialog.isVisible()); -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) QVERIFY(!sizeGrip->isVisible()); #endif dialog.showNormal(); QVERIFY(!dialog.isFullScreen()); QVERIFY(dialog.isVisible()); -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) QVERIFY(sizeGrip->isVisible()); #endif @@ -414,7 +414,7 @@ void tst_QDialog::deleteInExec() QCOMPARE(dialog->exec(), int(QDialog::Rejected)); } -#ifndef QT_NO_SIZEGRIP +#if QT_CONFIG(sizegrip) // From Task 124269 void tst_QDialog::showSizeGrip() { diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST index c6f69a51a5..70170d2822 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST @@ -1,3 +1,5 @@ [removeItem] # QTBUG-60754, QTest::mouseMove is not always respected, or the CI moves the cursor osx-10.11 ci +[isActive] +opensuse-42.3 ci diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST index 3cba8bad7e..40d106e3ba 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST @@ -12,7 +12,5 @@ xcb xcb [forwardMousePress] xcb -[hoverLeave] -xcb [resizeAnchor] xcb diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 1430911cf0..3d87836698 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -4777,8 +4777,6 @@ class GraphicsItemWithHover : public QGraphicsRectItem { public: GraphicsItemWithHover() - : receivedEnterEvent(false), receivedLeaveEvent(false), - enterWidget(0), leaveWidget(0) { setRect(0, 0, 100, 100); setAcceptHoverEvents(true); @@ -4786,6 +4784,9 @@ public: bool sceneEvent(QEvent *event) { + if (!checkEvents) // ensures that we don't look at stray events before we are ready + return QGraphicsRectItem::sceneEvent(event); + if (event->type() == QEvent::GraphicsSceneHoverEnter) { receivedEnterEvent = true; enterWidget = static_cast<QGraphicsSceneHoverEvent *>(event)->widget(); @@ -4796,50 +4797,39 @@ public: return QGraphicsRectItem::sceneEvent(event); } - bool receivedEnterEvent; - bool receivedLeaveEvent; - QWidget *enterWidget; - QWidget *leaveWidget; + bool receivedEnterEvent = false; + bool receivedLeaveEvent = false; + QWidget *enterWidget = nullptr; + QWidget *leaveWidget = nullptr; + bool checkEvents = false; }; void tst_QGraphicsView::hoverLeave() { - if (platformName == QStringLiteral("cocoa")) { - QSKIP("Insignificant on OSX"); - } else if (platformName == QStringLiteral("minimal") - || (platformName == QStringLiteral("offscreen"))) { - QSKIP("Fails in minimal/offscreen platforms if forwardMouseDoubleClick has been run"); - } - const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); QGraphicsScene scene; QGraphicsView view(&scene); view.resize(160, 160); - view.move(availableGeometry.center() - QPoint(80, 80)); GraphicsItemWithHover *item = new GraphicsItemWithHover; scene.addItem(item); - // move the cursor out of the way - const QPoint outOfWindow = view.geometry().topRight() + QPoint(50, 0); - QCursor::setPos(outOfWindow); - view.showNormal(); qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); - - QPoint pos = view.viewport()->mapToGlobal(view.mapFromScene(item->mapToScene(10, 10))); - QCursor::setPos(pos); + QVERIFY(QTest::qWaitForWindowExposed(&view)); -#if defined(Q_OS_QNX) - QEXPECT_FAIL("", "QCursor does not set native cursor on QNX", Abort); -#endif + QWindow *viewWindow = view.window()->windowHandle(); + QPoint posOutsideItem = view.mapFromScene(item->mapToScene(0, 0)) - QPoint(5, 0); + QPoint posOutsideItemGlobal = view.mapToGlobal(posOutsideItem); + QPoint posOutsideItemInWindow = viewWindow->mapFromGlobal(posOutsideItemGlobal); + QTest::mouseMove(viewWindow, posOutsideItemInWindow); + item->checkEvents = true; + QPoint posInItemGlobal = view.mapToGlobal(view.mapFromScene(item->mapToScene(10, 10))); + QTest::mouseMove(viewWindow, viewWindow->mapFromGlobal(posInItemGlobal)); QTRY_VERIFY(item->receivedEnterEvent); QCOMPARE(item->enterWidget, view.viewport()); - QCursor::setPos(outOfWindow); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-26274 - behaviour regression", Abort); -#endif + QTest::mouseMove(viewWindow, posOutsideItemInWindow); + QTRY_VERIFY(item->receivedLeaveEvent); QCOMPARE(item->leaveWidget, view.viewport()); } diff --git a/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST b/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST new file mode 100644 index 0000000000..a16fd19b99 --- /dev/null +++ b/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST @@ -0,0 +1,2 @@ +[enterKey] +opensuse-42.3 diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index 5648218d04..8e8602840e 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -60,6 +60,7 @@ osx [maskedUpdate] osx opensuse-42.1 +opensuse-42.3 [hideWhenFocusWidgetIsChild] osx-10.10 [hideOpaqueChildWhileHidden] diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 6fcf6dc3ed..81fb332a62 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -196,7 +196,9 @@ private slots: void mapFromAndTo(); void focusChainOnHide(); void focusChainOnReparent(); - void setTabOrder(); + void defaultTabOrder(); + void reverseTabOrder(); + void tabOrderWithProxy(); #ifdef Q_OS_WIN void activation(); #endif @@ -1667,74 +1669,185 @@ public: : QFrame(parent) { setObjectName(name); - //QHBoxLayout* hbox = new QHBoxLayout(this, 2, 0); - //hbox->setAutoAdd(true); + + lineEdit1 = new QLineEdit; + lineEdit2 = new QLineEdit; + QHBoxLayout* hbox = new QHBoxLayout(this); + hbox->addWidget(lineEdit1); + hbox->addWidget(lineEdit2); + } - lineEdit = new QLineEdit(this); - hbox->addWidget(lineEdit); +public: + QLineEdit *lineEdit1; + QLineEdit *lineEdit2; +}; - button = new QPushButton(this); - hbox->addWidget(button); - button->setFocusPolicy( Qt::NoFocus ); +void tst_QWidget::defaultTabOrder() +{ + const int compositeCount = 2; + Container container; + Composite *composite[compositeCount]; - setFocusProxy( lineEdit ); - setFocusPolicy( Qt::StrongFocus ); + QLineEdit *firstEdit = new QLineEdit; + container.box->addWidget(firstEdit); - setTabOrder(lineEdit, button); + for (int i = 0; i < compositeCount; i++) { + composite[i] = new Composite(); + container.box->addWidget(composite[i]); } -private: - QLineEdit* lineEdit; - QPushButton* button; -}; + QLineEdit *lastEdit = new QLineEdit(); + container.box->addWidget(lastEdit); -#define NUM_WIDGETS 4 + container.show(); + container.activateWindow(); + qApp->setActiveWindow(&container); + QVERIFY(QTest::qWaitForWindowActive(&container)); -void tst_QWidget::setTabOrder() -{ - QTest::qWait(100); + QTRY_VERIFY(firstEdit->hasFocus()); - Container container; - container.setObjectName("setTabOrder"); - container.setWindowTitle(container.objectName()); + // Check that focus moves between the line edits when we tab forward + for (int i = 0; i < compositeCount; ++i) { + container.tab(); + QVERIFY(composite[i]->lineEdit1->hasFocus()); + QVERIFY(!composite[i]->lineEdit2->hasFocus()); + container.tab(); + QVERIFY(!composite[i]->lineEdit1->hasFocus()); + QVERIFY(composite[i]->lineEdit2->hasFocus()); + } + + container.tab(); + QVERIFY(lastEdit->hasFocus()); - Composite* comp[NUM_WIDGETS]; + // Check that focus moves between the line edits in reverse + // order when we tab backwards + for (int i = compositeCount - 1; i >= 0; --i) { + container.backTab(); + QVERIFY(!composite[i]->lineEdit1->hasFocus()); + QVERIFY(composite[i]->lineEdit2->hasFocus()); + + container.backTab(); + QVERIFY(composite[i]->lineEdit1->hasFocus()); + QVERIFY(!composite[i]->lineEdit2->hasFocus()); + } + + container.backTab(); + QVERIFY(firstEdit->hasFocus()); +} + +void tst_QWidget::reverseTabOrder() +{ + const int compositeCount = 2; + Container container; + Composite* composite[compositeCount]; - QLineEdit *firstEdit = new QLineEdit(&container); + QLineEdit *firstEdit = new QLineEdit(); container.box->addWidget(firstEdit); - int i = 0; - for(i = 0; i < NUM_WIDGETS; i++) { - comp[i] = new Composite(&container); - container.box->addWidget(comp[i]); + for (int i = 0; i < compositeCount; i++) { + composite[i] = new Composite(); + container.box->addWidget(composite[i]); } - QLineEdit *lastEdit = new QLineEdit(&container); + QLineEdit *lastEdit = new QLineEdit(); container.box->addWidget(lastEdit); - container.setTabOrder(lastEdit, comp[NUM_WIDGETS-1]); - for(i = NUM_WIDGETS-1; i > 0; i--) { - container.setTabOrder(comp[i], comp[i-1]); + // Reverse tab order inside each composite + for (int i = 0; i < compositeCount; ++i) + QWidget::setTabOrder(composite[i]->lineEdit2, composite[i]->lineEdit1); + + container.show(); + container.activateWindow(); + qApp->setActiveWindow(&container); + QVERIFY(QTest::qWaitForWindowActive(&container)); + + QTRY_VERIFY(firstEdit->hasFocus()); + + // Check that focus moves in reverse order when tabbing inside the composites + // (but in the correct order when tabbing between them) + for (int i = 0; i < compositeCount; ++i) { + container.tab(); + QVERIFY(!composite[i]->lineEdit1->hasFocus()); + QVERIFY(composite[i]->lineEdit2->hasFocus()); + container.tab(); + QVERIFY(composite[i]->lineEdit1->hasFocus()); + QVERIFY(!composite[i]->lineEdit2->hasFocus()); + } + + container.tab(); + QVERIFY(lastEdit->hasFocus()); + + // Check that focus moves in "normal" order when tabbing backwards inside the + // composites (since backwards of reversed order cancels each other out), + // but in the reverse order when tabbing between them. + for (int i = compositeCount - 1; i >= 0; --i) { + container.backTab(); + QVERIFY(composite[i]->lineEdit1->hasFocus()); + QVERIFY(!composite[i]->lineEdit2->hasFocus()); + container.backTab(); + QVERIFY(!composite[i]->lineEdit1->hasFocus()); + QVERIFY(composite[i]->lineEdit2->hasFocus()); } - container.setTabOrder(comp[0], firstEdit); - int current = NUM_WIDGETS-1; - lastEdit->setFocus(); + container.backTab(); + QVERIFY(firstEdit->hasFocus()); +} + +void tst_QWidget::tabOrderWithProxy() +{ + const int compositeCount = 2; + Container container; + Composite* composite[compositeCount]; + + QLineEdit *firstEdit = new QLineEdit(); + container.box->addWidget(firstEdit); + + for (int i = 0; i < compositeCount; i++) { + composite[i] = new Composite(); + container.box->addWidget(composite[i]); + + // Set second child as focus proxy + composite[i]->setFocusPolicy(Qt::StrongFocus); + composite[i]->setFocusProxy(composite[i]->lineEdit2); + } + + QLineEdit *lastEdit = new QLineEdit(); + container.box->addWidget(lastEdit); container.show(); container.activateWindow(); qApp->setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); - QTRY_VERIFY(lastEdit->hasFocus()); - container.tab(); - do { - QVERIFY(comp[current]->focusProxy()->hasFocus()); + QTRY_VERIFY(firstEdit->hasFocus()); + + // Check that focus moves between the second line edits + // (the focus proxies) when we tab forward + for (int i = 0; i < compositeCount; ++i) { container.tab(); - current--; - } while (current >= 0); + QVERIFY(!composite[i]->lineEdit1->hasFocus()); + QVERIFY(composite[i]->lineEdit2->hasFocus()); + } + container.tab(); + QVERIFY(lastEdit->hasFocus()); + + // Check that focus moves between the line edits + // in reverse order when we tab backwards. + // Note that in this case, the focus proxies should not + // be taken into consideration, since they only take + // effect when tabbing forward + for (int i = compositeCount - 1; i >= 0; --i) { + container.backTab(); + QVERIFY(!composite[i]->lineEdit1->hasFocus()); + QVERIFY(composite[i]->lineEdit2->hasFocus()); + container.backTab(); + QVERIFY(composite[i]->lineEdit1->hasFocus()); + QVERIFY(!composite[i]->lineEdit2->hasFocus()); + } + + container.backTab(); QVERIFY(firstEdit->hasFocus()); } @@ -1743,8 +1856,6 @@ void tst_QWidget::activation() { Q_CHECK_PAINTEVENTS - int waitTime = 100; - QWidget widget1; widget1.setObjectName("activation-Widget1"); widget1.setWindowTitle(widget1.objectName()); @@ -1756,25 +1867,18 @@ void tst_QWidget::activation() widget1.show(); widget2.show(); - QTest::qWait(waitTime); - QCOMPARE(QApplication::activeWindow(), &widget2); + QTRY_COMPARE(QApplication::activeWindow(), &widget2); widget2.showMinimized(); - QTest::qWait(waitTime); - QCOMPARE(QApplication::activeWindow(), &widget1); + QTRY_COMPARE(QApplication::activeWindow(), &widget1); widget2.showMaximized(); - QTest::qWait(waitTime); - QCOMPARE(QApplication::activeWindow(), &widget2); + QTRY_COMPARE(QApplication::activeWindow(), &widget2); widget2.showMinimized(); - QTest::qWait(waitTime); - QCOMPARE(QApplication::activeWindow(), &widget1); + QTRY_COMPARE(QApplication::activeWindow(), &widget1); widget2.showNormal(); - QTest::qWait(waitTime); - QTest::qWait(waitTime); - QCOMPARE(QApplication::activeWindow(), &widget2); + QTRY_COMPARE(QApplication::activeWindow(), &widget2); widget2.hide(); - QTest::qWait(waitTime); - QCOMPARE(QApplication::activeWindow(), &widget1); + QTRY_COMPARE(QApplication::activeWindow(), &widget1); } #endif // Q_OS_WIN diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index b865a10874..a396063c1c 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -261,7 +261,7 @@ private slots: // task-specific tests: void task180999_focus(); void task174640_editingFinished(); -#ifndef QT_NO_COMPLETER +#if QT_CONFIG(completer) void task198789_currentCompletion(); void task210502_caseInsensitiveInlineCompletion(); #endif @@ -3629,7 +3629,7 @@ void tst_QLineEdit::task174640_editingFinished() QCOMPARE(editingFinishedSpy.count(), 1); } -#ifndef QT_NO_COMPLETER +#if QT_CONFIG(completer) class task198789_Widget : public QWidget { Q_OBJECT @@ -3688,7 +3688,7 @@ void tst_QLineEdit::task210502_caseInsensitiveInlineCompletion() QCOMPARE(lineEdit.text(), completion); } -#endif // QT_NO_COMPLETER +#endif // QT_CONFIG(completer) void tst_QLineEdit::task229938_dontEmitChangedWhenTextIsNotChanged() |