diff options
Diffstat (limited to 'tests')
24 files changed, 544 insertions, 87 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 5248f75a84..1abbef0d68 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -68,6 +68,24 @@ expect_fail(test_wrap_cpp_options) expect_pass(test_platform_defs_include) expect_pass(test_qtmainwin_library) +if (HAVE_NINJA) + make_directory("${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build") + add_test(test_QFINDTESTDATA ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA" + # Build in a subdir of the source dir. + # This causes Ninja to use relative paths. + "${CMAKE_CURRENT_SOURCE_DIR}/test_QFINDTESTDATA/build" + --build-generator Ninja + --build-options "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) + add_test(NAME run_test_QFINDTESTDATA COMMAND sh -c "cd \"${CMAKE_SOURCE_DIR}/test_QFINDTESTDATA/build/tests\" && ./test_QFINDTESTDATA -v2") + + set_property(TEST run_test_QFINDTESTDATA + PROPERTY DEPENDS test_QFINDTESTDATA + ) +endif() + if (NOT NO_DBUS) expect_pass(test_dbus_module) endif() diff --git a/tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt b/tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt new file mode 100644 index 0000000000..e56c3c5eb9 --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/CMakeLists.txt @@ -0,0 +1,11 @@ + +cmake_minimum_required(VERSION 2.8.11) + +project(test_QFINDTESTDATA) + +find_package(Qt5Test REQUIRED) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +add_subdirectory(tests) diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt new file mode 100644 index 0000000000..dfe321982a --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_executable(test_QFINDTESTDATA WIN32 main.cpp) + +target_link_libraries(test_QFINDTESTDATA Qt5::Test) diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp b/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp new file mode 100644 index 0000000000..0a5b6acd32 --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Stephen Kelly <steveire@gmail,com> +** 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 <QCoreApplication> +#include <QtTest/QTest> + +class TestClass : public QObject +{ + Q_OBJECT +public: + TestClass(QObject* parent = 0) {} + +private slots: + void doTest(); +}; + +void TestClass::doTest() +{ + QFile f(QFINDTESTDATA("testdata.txt")); + QVERIFY(f.open(QFile::ReadOnly)); + QCOMPARE(f.readAll().trimmed(), QByteArrayLiteral("This is a test.")); +} + +QTEST_MAIN(TestClass) +#include "main.moc" diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt b/tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt new file mode 100644 index 0000000000..484ba93ef5 --- /dev/null +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/testdata.txt @@ -0,0 +1 @@ +This is a test. diff --git a/tests/auto/corelib/io/qtextstream/test/test.pro b/tests/auto/corelib/io/qtextstream/test/test.pro index 93fb6d232f..50335524d3 100644 --- a/tests/auto/corelib/io/qtextstream/test/test.pro +++ b/tests/auto/corelib/io/qtextstream/test/test.pro @@ -19,3 +19,7 @@ TESTDATA += \ ../qtextstream.qrc \ ../tst_qtextstream.cpp \ ../resources + +builtin_testdata { + DEFINES += BUILTIN_TESTDATA +} diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 2852420557..104873b85e 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -60,6 +60,7 @@ public: public slots: void initTestCase(); void cleanup(); + void cleanupTestCase(); private slots: void getSetCheck(); @@ -236,6 +237,9 @@ private: QTemporaryDir tempDir; QString testFileName; +#ifdef BUILTIN_TESTDATA + QSharedPointer<QTemporaryDir> m_dataDir; +#endif const QString m_rfc3261FilePath; const QString m_shiftJisFilePath; }; @@ -262,9 +266,14 @@ void tst_QTextStream::initTestCase() testFileName = tempDir.path() + "/testfile"; +#ifdef BUILTIN_TESTDATA + m_dataDir = QEXTRACTTESTDATA("/"); + QVERIFY2(QDir::setCurrent(m_dataDir->path()), qPrintable("Could not chdir to " + m_dataDir->path())); +#else // chdir into the testdata dir and refer to our helper apps with relative paths QString testdata_dir = QFileInfo(QFINDTESTDATA("stdinProcess")).absolutePath(); QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir)); +#endif } // Testing get/set functions @@ -387,6 +396,13 @@ void tst_QTextStream::cleanup() QCoreApplication::instance()->processEvents(); } +void tst_QTextStream::cleanupTestCase() +{ +#ifdef BUILTIN_TESTDATA + QDir::setCurrent(QCoreApplication::applicationDirPath()); +#endif +} + // ------------------------------------------------------------------------------ void tst_QTextStream::construction() { @@ -3044,12 +3060,10 @@ void tst_QTextStream::int_write_with_locale() void tst_QTextStream::textModeOnEmptyRead() { - const QString filename("textmodetest.txt"); - QFile::remove(filename); // Remove file if exists - + const QString filename(tempDir.path() + QLatin1String("/textmodetest.txt")); QFile file(filename); - QVERIFY(file.open(QIODevice::ReadWrite | QIODevice::Text)); + QVERIFY2(file.open(QIODevice::ReadWrite | QIODevice::Text), qPrintable(file.errorString())); QTextStream stream(&file); QVERIFY(file.isTextModeEnabled()); QString emptyLine = stream.readLine(); // Text mode flag cleared here diff --git a/tests/auto/corelib/plugin/plugin.pro b/tests/auto/corelib/plugin/plugin.pro index e6b748e4f4..777e920995 100644 --- a/tests/auto/corelib/plugin/plugin.pro +++ b/tests/auto/corelib/plugin/plugin.pro @@ -8,3 +8,9 @@ load(qfeatures) qpluginloader \ qplugin \ qlibrary + +contains(CONFIG, static) { + message(Disabling tests requiring shared build of Qt) + SUBDIRS -= qfactoryloader \ + qpluginloader +} diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index 9b35cdec30..d3c6412b0d 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -2347,7 +2347,7 @@ void tst_QRect::center_data() QTest::newRow( "SmallestQRect" ) << getQRectCase( SmallestQRect ) << QPoint(1,1); QTest::newRow( "MiddleQRect" ) << getQRectCase( MiddleQRect ) << QPoint(0,0); QTest::newRow( "LargestQRect" ) << getQRectCase( LargestQRect ) << QPoint(INT_MAX/2,INT_MAX/2); - QTest::newRow( "SmallestCoordQRect" ) << getQRectCase( SmallestCoordQRect ) << QPoint(0,0); + QTest::newRow( "SmallestCoordQRect" ) << getQRectCase( SmallestCoordQRect ) << QPoint(INT_MIN, INT_MIN); QTest::newRow( "LargestCoordQRect" ) << getQRectCase( LargestCoordQRect ) << QPoint(0,0); QTest::newRow( "RandomQRect" ) << getQRectCase( RandomQRect ) << QPoint(105,207); QTest::newRow( "NegativeSizeQRect" ) << getQRectCase( NegativeSizeQRect ) << QPoint(-4,-4); @@ -3169,8 +3169,7 @@ void tst_QRect::newMoveTopLeft_data() } { - QTest::newRow("LargestCoordQRect_NullQPoint") << getQRectCase(LargestCoordQRect) << getQPointCase(NullQPoint) - << QRect(QPoint(0,0), QPoint(INT_MAX+(0-INT_MIN),INT_MAX+(0-INT_MIN))); + // QTest::newRow("LargestCoordQRect_NullQPoint") -- Not tested as it would cause an overflow QTest::newRow("LargestCoordQRect_SmallestCoordQPoint") << getQRectCase(LargestCoordQRect) << getQPointCase(SmallestCoordQPoint) << QRect(QPoint(INT_MIN,INT_MIN), QPoint(INT_MAX,INT_MAX)); // QTest::newRow("LargestCoordQRect_MiddleNegCoordQPoint") -- Not tested as it would cause an overflow diff --git a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp index 1879543581..077a6a20f1 100644 --- a/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/tools/qtimezone/tst_qtimezone.cpp @@ -893,7 +893,7 @@ void tst_QTimeZone::macTest() void tst_QTimeZone::winTest() { -#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) // Known datetimes qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); diff --git a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp index b889bcc6a9..8a153a4599 100644 --- a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp @@ -902,7 +902,8 @@ void tst_QXmlStream::testFalsePrematureError() const // Regression test for crash due to using empty QStack. void tst_QXmlStream::writerHangs() const { - QFile file("test.xml"); + QTemporaryDir dir(QDir::tempPath() + QLatin1String("/tst_qxmlstream.XXXXXX")); + QFile file(dir.path() + "/test.xml"); QVERIFY(file.open(QIODevice::WriteOnly)); diff --git a/tests/auto/gui/text/qstatictext/qstatictext.pro b/tests/auto/gui/text/qstatictext/qstatictext.pro index 002cead51d..0f4906ce4d 100644 --- a/tests/auto/gui/text/qstatictext/qstatictext.pro +++ b/tests/auto/gui/text/qstatictext/qstatictext.pro @@ -1,5 +1,7 @@ CONFIG += testcase TARGET = tst_qstatictext QT += testlib -QT += core-private gui-private + SOURCES += tst_qstatictext.cpp + +contains(QT_CONFIG, private_tests): QT += core-private gui-private diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index 096b820004..ec30cc8b67 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -34,7 +34,9 @@ #include <qstatictext.h> #include <qpaintengine.h> +#ifdef QT_BUILD_INTERNAL #include <private/qstatictext_p.h> +#endif // #define DEBUG_SAVE_IMAGE @@ -89,8 +91,10 @@ private slots: void unprintableCharacter_qtbug12614(); +#ifdef QT_BUILD_INTERNAL void underlinedColor_qtbug20159(); void textDocumentColor(); +#endif private: bool supportsTransformations() const; @@ -811,6 +815,7 @@ void tst_QStaticText::unprintableCharacter_qtbug12614() QVERIFY(staticText.size().isValid()); // Force layout. Should not crash. } +#ifdef QT_BUILD_INTERNAL void tst_QStaticText::underlinedColor_qtbug20159() { QString multiScriptText; @@ -847,6 +852,7 @@ void tst_QStaticText::textDocumentColor() QCOMPARE(d->items[1].color, QColor(Qt::red)); } +#endif QTEST_MAIN(tst_QStaticText) #include "tst_qstatictext.moc" diff --git a/tests/auto/gui/text/text.pro b/tests/auto/gui/text/text.pro index 6c0def4d63..dc67794a98 100644 --- a/tests/auto/gui/text/text.pro +++ b/tests/auto/gui/text/text.pro @@ -30,6 +30,5 @@ win32:SUBDIRS -= qtextpiecetable !contains(QT_CONFIG, private_tests): SUBDIRS -= \ qfontcache \ qcssparser \ - qstatictext \ qtextlayout \ qtextpiecetable \ diff --git a/tests/auto/network/socket/qlocalsocket/BLACKLIST b/tests/auto/network/socket/qlocalsocket/BLACKLIST deleted file mode 100644 index 11ddef30a5..0000000000 --- a/tests/auto/network/socket/qlocalsocket/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[processConnection:1 client] -windows diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index ef47b45e9e..123fbfeb2a 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -517,6 +517,7 @@ void tst_QLocalSocket::sendData() // test creating a connection socket.connectToServer(name); bool timedOut = true; + int expectedReadyReadSignals = 0; QCOMPARE(server.waitForNewConnection(3000, &timedOut), canListen); @@ -540,15 +541,17 @@ void tst_QLocalSocket::sendData() out << testLine << endl; bool wrote = serverSocket->waitForBytesWritten(3000); - if (!socket.canReadLine()) + if (!socket.canReadLine()) { + expectedReadyReadSignals = 1; QVERIFY(socket.waitForReadyRead()); + } QVERIFY(socket.bytesAvailable() >= 0); QCOMPARE(socket.bytesToWrite(), (qint64)0); QCOMPARE(socket.flush(), false); QCOMPARE(socket.isValid(), canListen); QCOMPARE(socket.readBufferSize(), (qint64)0); - QCOMPARE(spyReadyRead.count(), 1); + QCOMPARE(spyReadyRead.count(), expectedReadyReadSignals); QVERIFY(testLine.startsWith(in.readLine())); @@ -563,7 +566,7 @@ void tst_QLocalSocket::sendData() QCOMPARE(spyDisconnected.count(), canListen ? 1 : 0); QCOMPARE(spyError.count(), canListen ? 0 : 1); QCOMPARE(spyStateChanged.count(), canListen ? 4 : 2); - QCOMPARE(spyReadyRead.count(), canListen ? 1 : 0); + QCOMPARE(spyReadyRead.count(), canListen ? expectedReadyReadSignals : 0); server.close(); diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 64e123309d..be3a86f4de 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -1748,24 +1748,6 @@ void tst_QSqlQuery::synonyms() QCOMPARE( rec.field( 2 ).name().toLower(), QString( "t_varchar" ) ); } -// This class is used to test protected QSqlResult methods -class ResultHelper: public QSqlResult -{ - -public: - ResultHelper(): QSqlResult( 0 ) {} // don't call, it's only for stupid compilers - - bool execBatch( bool bindArray = false ) - { - return QSqlResult::execBatch( bindArray ); - } - - QString boundValueName( int pos ) const - { - return QSqlResult::boundValueName( pos ); - } -}; - // It doesn't make sense to split this into several tests void tst_QSqlQuery::prepare_bind_exec() { @@ -1890,81 +1872,81 @@ void tst_QSqlQuery::prepare_bind_exec() q.bindValue( 0, 0 ); q.bindValue( 1, values[ 0 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 0 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[0] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 0); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[0]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 0 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[0] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 0); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[0]); q.addBindValue( 1 ); q.addBindValue( values[ 1 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 1 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[1] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 1); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[1]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 1 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[1] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 1); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[1]); q.addBindValue( 2 ); q.addBindValue( values[ 2 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[2] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 2); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[2]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[2] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 2); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[2]); q.addBindValue( 3 ); q.addBindValue( values[ 3 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 3 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[3] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 3); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[3]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 3 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[3] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 3); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[3]); q.addBindValue( 4 ); q.addBindValue( values[ 4 ] ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 4 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[4] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 4); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[4]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 4 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[4] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 4); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[4]); q.bindValue( 1, values[ 5 ] ); q.bindValue( 0, 5 ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 5 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[5] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 5); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[5]); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 5 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), values[5] ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 5); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), values[5]); q.bindValue( 0, 6 ); q.bindValue( 1, QString() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 6 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), QString() ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 6); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), QString()); QVERIFY_SQL( q, exec() ); QCOMPARE( q.boundValues().size(), 2 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 6 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), QString() ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 6); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), QString()); if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) { q.bindValue( 0, 7 ); q.bindValue( 1, utf8str ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 7 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), utf8str ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 7); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), utf8str); QVERIFY_SQL( q, exec() ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(0) ].toInt(), 7 ); - QCOMPARE( q.boundValues()[ ((ResultHelper*)q.result())->boundValueName(1) ].toString(), utf8str ); + QCOMPARE(q.boundValues()[q.result()->boundValueName(0)].toInt(), 7); + QCOMPARE(q.boundValues()[q.result()->boundValueName(1)].toString(), utf8str); } QVERIFY_SQL( q, exec( "SELECT * FROM " + qtest_prepare + " order by id" ) ); diff --git a/tests/auto/widgets/widgets/qdockwidget/BLACKLIST b/tests/auto/widgets/widgets/qdockwidget/BLACKLIST deleted file mode 100644 index 60adfb9f4b..0000000000 --- a/tests/auto/widgets/widgets/qdockwidget/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[restoreDockWidget] -ubuntu-14.04 diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index 947c251590..550cca8145 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -274,36 +274,30 @@ void tst_QTabBar::sizeHints() { QTabBar tabBar; tabBar.setFont(QFont("Arial", 10)); - tabBar.addTab("tab 01"); - tabBar.addTab("tab 02"); - tabBar.addTab("tab 03"); - tabBar.addTab("tab 04"); - tabBar.addTab("tab 05"); - tabBar.addTab("tab 06"); - tabBar.addTab("This is tab7"); - tabBar.addTab("This is tab8"); - tabBar.addTab("This is tab9 with a very long title"); // No eliding and no scrolling -> tabbar becomes very wide tabBar.setUsesScrollButtons(false); tabBar.setElideMode(Qt::ElideNone); -// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-27230", Abort); -#endif + tabBar.addTab("tab 01"); + + // Fetch the minimum size hint width and make sure that we create enough + // tabs. + int minimumSizeHintWidth = tabBar.minimumSizeHint().width(); + for (int i = 0; i <= 700 / minimumSizeHintWidth; ++i) + tabBar.addTab(QString("tab 0%1").arg(i+2)); + + //qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); QVERIFY(tabBar.minimumSizeHint().width() > 700); QVERIFY(tabBar.sizeHint().width() > 700); // Scrolling enabled -> no reason to become very wide tabBar.setUsesScrollButtons(true); - // qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); QVERIFY(tabBar.minimumSizeHint().width() < 200); QVERIFY(tabBar.sizeHint().width() > 700); // unchanged // Eliding enabled -> no reason to become very wide tabBar.setUsesScrollButtons(false); tabBar.setElideMode(Qt::ElideRight); -// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint(); // The sizeHint is very much dependent on the screen DPI value // so we can not really predict it. @@ -312,7 +306,7 @@ void tst_QTabBar::sizeHints() QVERIFY(tabBarMinSizeHintWidth < tabBarSizeHintWidth); QVERIFY(tabBarSizeHintWidth > 700); // unchanged - tabBar.addTab("This is tab10 with a very long title"); + tabBar.addTab("This is tab with a very long title"); QVERIFY(tabBar.minimumSizeHint().width() > tabBarMinSizeHintWidth); QVERIFY(tabBar.sizeHint().width() > tabBarSizeHintWidth); } diff --git a/tests/manual/foreignwindows/foreignwindows.pro b/tests/manual/foreignwindows/foreignwindows.pro new file mode 100644 index 0000000000..6a370a6813 --- /dev/null +++ b/tests/manual/foreignwindows/foreignwindows.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +QT += widgets +CONFIG += console c++11 +CONFIG -= app_bundle +SOURCES += main.cpp +include(../diaglib/diaglib.pri) diff --git a/tests/manual/foreignwindows/main.cpp b/tests/manual/foreignwindows/main.cpp new file mode 100644 index 0000000000..6c722a3f6f --- /dev/null +++ b/tests/manual/foreignwindows/main.cpp @@ -0,0 +1,329 @@ +/**************************************************************************** +** +** 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 <QtWidgets/QAction> +#include <QtWidgets/QApplication> +#include <QtWidgets/QDesktopWidget> +#include <QtWidgets/QMainWindow> +#include <QtWidgets/QMenu> +#include <QtWidgets/QMenuBar> +#include <QtWidgets/QToolBar> + +#include <QtGui/QScreen> +#include <QtGui/QWindow> + +#include <QtCore/QCommandLineOption> +#include <QtCore/QCommandLineParser> +#include <QtCore/QDebug> +#include <QtCore/QSharedPointer> +#include <QtCore/QStringList> +#include <QtCore/QTextStream> +#include <QtCore/QTimer> + +#ifdef Q_OS_WIN +# include <QtCore/qt_windows.h> +#endif + +#include <eventfilter.h> // diaglib +#include <nativewindowdump.h> +#include <qwidgetdump.h> +#include <qwindowdump.h> + +#include <iostream> +#include <algorithm> + +QT_USE_NAMESPACE + +typedef QSharedPointer<QWidget> WidgetPtr; +typedef QList<WidgetPtr> WidgetPtrList; +typedef QList<WId> WIdList; + +// Create some pre-defined Windows controls by class name +static WId createInternalWindow(const QString &name) +{ + WId result = 0; +#ifdef Q_OS_WIN + if (name == QLatin1String("BUTTON") || name == QLatin1String("COMBOBOX") + || name == QLatin1String("EDIT") || name.startsWith(QLatin1String("RICHEDIT"))) { + const HWND hwnd = + CreateWindowEx(0, reinterpret_cast<const wchar_t *>(name.utf16()), + L"NativeCtrl", WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + 0, 0, GetModuleHandle(NULL), NULL); + if (hwnd) { + SetWindowText(hwnd, L"Demo"); + result = WId(hwnd); + } else { + qErrnoWarning("Cannot create window \"%s\"", qPrintable(name)); + } + } +#else // Q_OS_WIN + Q_UNUSED(name) +#endif + return result; +} + +// Embed a foreign window using createWindowContainer() providing +// menu actions to dump information. +class EmbeddingWindow : public QMainWindow +{ + Q_OBJECT +public: + explicit EmbeddingWindow(QWindow *window); + +public slots: + void releaseForeignWindow(); + +private: + QWindow *m_window; + QAction *m_releaseAction; +}; + +EmbeddingWindow::EmbeddingWindow(QWindow *window) : m_window(window) +{ + const QString title = QLatin1String("Qt ") + QLatin1String(QT_VERSION_STR) + + QLatin1String(" 0x") + QString::number(window->winId(), 16); + setWindowTitle(title); + setObjectName("MainWindow"); + QWidget *container = QWidget::createWindowContainer(window, Q_NULLPTR, Qt::Widget); + container->setObjectName("Container"); + setCentralWidget(container); + + QMenu *fileMenu = menuBar()->addMenu("File"); + fileMenu->setObjectName("FileMenu"); + QToolBar *toolbar = new QToolBar; + addToolBar(Qt::TopToolBarArea, toolbar); + + // Manipulation + QAction *action = fileMenu->addAction("Visible"); + action->setCheckable(true); + action->setChecked(true); + connect(action, &QAction::toggled, m_window, &QWindow::setVisible); + toolbar->addAction(action); + + m_releaseAction = fileMenu->addAction("Release", this, &EmbeddingWindow::releaseForeignWindow); + toolbar->addAction(m_releaseAction); + + fileMenu->addSeparator(); // Diaglib actions + action = fileMenu->addAction("Dump Widgets", + this, [] () { QtDiag::dumpAllWidgets(); }); + toolbar->addAction(action); + action = fileMenu->addAction("Dump Windows", + this, [] () { QtDiag::dumpAllWindows(); }); + toolbar->addAction(action); + action = fileMenu->addAction("Dump Native Windows", + this, [this] () { QtDiag::dumpNativeWindows(winId()); }); + toolbar->addAction(action); + + fileMenu->addSeparator(); + action = fileMenu->addAction("Quit", qApp, &QCoreApplication::quit); + toolbar->addAction(action); + action->setShortcut(Qt::CTRL + Qt::Key_Q); +} + +void EmbeddingWindow::releaseForeignWindow() +{ + if (m_window) { + m_window->setParent(Q_NULLPTR); + m_window = Q_NULLPTR; + m_releaseAction->setEnabled(false); + } +} + +// Dump information about foreign windows. +class WindowDumper : public QObject { + Q_OBJECT +public: + explicit WindowDumper(const QWindowList &watchedWindows) + : m_watchedWindows(watchedWindows) {} + +public slots: + void dump() const; + +private: + const QWindowList m_watchedWindows; +}; + +void WindowDumper::dump() const +{ + static int n = 0; + QString s; + QDebug debug(&s); + debug.nospace(); + debug.setVerbosity(3); + debug << '#' << n++; + if (m_watchedWindows.size() > 1) + debug << '\n'; + foreach (const QWindow *w, m_watchedWindows) { + const QPoint globalPos = w->mapToGlobal(QPoint()); + debug << " " << w << " pos=" << globalPos.x() << ',' << globalPos.y() << '\n'; + } + + std::cout << qPrintable(s); +} + +static QString description(const QString &appName) +{ + QString result; + QTextStream(&result) + << "\nDumps information about foreign windows passed on the command line or\n" + "tests embedding foreign windows into Qt.\n\nUse cases:\n\n" + << appName << " -a Dump a list of all native window ids.\n" + << appName << " <winid> Dump information on the window.\n" + << appName << " -c <winid> Dump information on the window continuously.\n" + << appName << " -e <winid> Embed window into a Qt widget.\n" + << "\nOn Windows, class names of well known controls (EDIT, BUTTON...) can be\n" + "passed as <winid> along with -e, which will create the control.\n"; + return result; +} + +struct EventFilterOption +{ + const char *name; + const char *description; + QtDiag::EventFilter::EventCategories categories; +}; + +EventFilterOption eventFilterOptions[] = { +{"mouse-events", "Dump mouse events.", QtDiag::EventFilter::MouseEvents}, +{"keyboard-events", "Dump keyboard events.", QtDiag::EventFilter::KeyEvents}, +{"state-events", "Dump state/focus change events.", QtDiag::EventFilter::StateChangeEvents | QtDiag::EventFilter::FocusEvents} +}; + +static inline bool isOptionSet(int argc, char *argv[], const char *option) +{ + return (argv + argc) != + std::find_if(argv + 1, argv + argc, + [option] (const char *arg) { return !qstrcmp(arg, option); }); +} + +int main(int argc, char *argv[]) +{ + // Check for no scaling before QApplication is instantiated. + if (isOptionSet(argc, argv, "-s")) + QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); + QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); + QGuiApplication::setApplicationDisplayName("Foreign window tester"); + + QApplication app(argc, argv); + + QCommandLineParser parser; + parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); + parser.setApplicationDescription(description(QCoreApplication::applicationName())); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption noScalingDummy(QStringLiteral("s"), + QStringLiteral("Disable High DPI scaling.")); + parser.addOption(noScalingDummy); + QCommandLineOption outputAllOption(QStringList() << QStringLiteral("a") << QStringLiteral("all"), + QStringLiteral("Output all native window ids (requires diaglib).")); + parser.addOption(outputAllOption); + QCommandLineOption continuousOption(QStringList() << QStringLiteral("c") << QStringLiteral("continuous"), + QStringLiteral("Output continuously.")); + parser.addOption(continuousOption); + QCommandLineOption embedOption(QStringList() << QStringLiteral("e") << QStringLiteral("embed"), + QStringLiteral("Embed a foreign window into a Qt widget.")); + parser.addOption(embedOption); + const int eventFilterOptionCount = int(sizeof(eventFilterOptions) / sizeof(eventFilterOptions[0])); + for (int i = 0; i < eventFilterOptionCount; ++i) { + parser.addOption(QCommandLineOption(QLatin1String(eventFilterOptions[i].name), + QLatin1String(eventFilterOptions[i].description))); + } + parser.addPositionalArgument(QStringLiteral("[windows]"), QStringLiteral("Window IDs.")); + + parser.process(QCoreApplication::arguments()); + + if (parser.isSet(outputAllOption)) { + QtDiag::dumpNativeWindows(); + return 0; + } + + QWindowList windows; + foreach (const QString &argument, parser.positionalArguments()) { + bool ok = true; + WId wid = createInternalWindow(argument); + if (!wid) + wid = argument.toULongLong(&ok, 0); + if (!wid || !ok) { + std::cerr << "Invalid window id: \"" << qPrintable(argument) << "\"\n"; + return -1; + } + QWindow *foreignWindow = QWindow::fromWinId(wid); + foreignWindow->setObjectName("ForeignWindow" + QString::number(wid, 16)); + windows.append(foreignWindow); + } + + if (windows.isEmpty()) + parser.showHelp(0); + + int exitCode = 0; + + if (parser.isSet(embedOption)) { + QtDiag::EventFilter::EventCategories eventCategories = 0; + for (int i = 0; i < eventFilterOptionCount; ++i) { + if (parser.isSet(QLatin1String(eventFilterOptions[i].name))) + eventCategories |= eventFilterOptions[i].categories; + } + if (eventCategories) + app.installEventFilter(new QtDiag::EventFilter(eventCategories, &app)); + + const QRect availableGeometry = QApplication::desktop()->availableGeometry(0); + QPoint pos = availableGeometry.topLeft() + QPoint(availableGeometry.width(), availableGeometry.height()) / 3; + + WidgetPtrList mainWindows; + foreach (QWindow *window, windows) { + WidgetPtr mainWindow(new EmbeddingWindow(window)); + mainWindow->move(pos); + mainWindow->resize(availableGeometry.size() / 4); + mainWindow->show(); + pos += QPoint(40, 40); + mainWindows.append(mainWindow); + } + exitCode = app.exec(); + + } else if (parser.isSet(continuousOption)) { + WindowDumper dumper(windows); + dumper.dump(); + QTimer *timer = new QTimer(&dumper); + QObject::connect(timer, &QTimer::timeout, &dumper, &WindowDumper::dump); + timer->start(1000); + exitCode = app.exec(); + + } else { + WindowDumper(windows).dump(); + } + + return exitCode; +} + +#include "main.moc" diff --git a/tests/manual/highdpi/dragwidget.cpp b/tests/manual/highdpi/dragwidget.cpp index b5ad6fa63b..fc1ea72963 100644 --- a/tests/manual/highdpi/dragwidget.cpp +++ b/tests/manual/highdpi/dragwidget.cpp @@ -163,7 +163,11 @@ void DragWidget::mousePressEvent(QMouseEvent *event) mimeData->setData("application/x-hotspot", QByteArray::number(hotSpot.x()) + ' ' + QByteArray::number(hotSpot.y())); - QPixmap pixmap(child->size()); + const qreal dpr = devicePixelRatioF() > 1 && !(QGuiApplication::keyboardModifiers() & Qt::ShiftModifier) + ? devicePixelRatioF() : 1; + + QPixmap pixmap(child->size() * dpr); + pixmap.setDevicePixelRatio(dpr); child->render(&pixmap); QDrag *drag = new QDrag(this); diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp index dcfabb213c..bd6af75b16 100644 --- a/tests/manual/highdpi/main.cpp +++ b/tests/manual/highdpi/main.cpp @@ -375,16 +375,22 @@ Labels::Labels() class MainWindow : public QMainWindow { + Q_OBJECT public: MainWindow(); QMenu *addNewMenu(const QString &title, int itemCount = 5); +private slots: + void maskActionToggled(bool t); + +private: QIcon qtIcon; QIcon qtIcon1x; QIcon qtIcon2x; QToolBar *fileToolBar; int menuCount; + QAction *m_maskAction; }; MainWindow::MainWindow() @@ -403,7 +409,12 @@ MainWindow::MainWindow() addNewMenu("&Edit"); addNewMenu("&Build"); addNewMenu("&Debug", 4); - addNewMenu("&Transmogrify", 7); + QMenu *menu = addNewMenu("&Transmogrify", 7); + menu->addSeparator(); + m_maskAction = menu->addAction("Mask"); + m_maskAction->setCheckable(true); + connect(m_maskAction, &QAction::toggled, this, &MainWindow::maskActionToggled); + fileToolBar->addAction(m_maskAction); addNewMenu("T&ools"); addNewMenu("&Help", 2); } @@ -426,6 +437,16 @@ QMenu *MainWindow::addNewMenu(const QString &title, int itemCount) return menu; } +void MainWindow::maskActionToggled(bool t) +{ + if (t) { + QVector<QPoint> upperLeftTriangle; + upperLeftTriangle << QPoint(0, 0) << QPoint(width(), 0) << QPoint(0, height()); + setMask(QRegion(QPolygon(upperLeftTriangle))); + } else { + clearMask(); + } +} class StandardIcons : public QWidget { diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index cffe76b2b4..8777cc6e11 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -2,6 +2,7 @@ TEMPLATE=subdirs SUBDIRS = bearerex \ filetest \ +foreignwindows \ gestures \ inputmethodhints \ keypadnavigation \ @@ -62,4 +63,5 @@ win32 { } lessThan(QT_MAJOR_VERSION, 5): SUBDIRS -= bearerex lance qnetworkaccessmanager/qget qmimedatabase qnetworkreply \ -qpainfo qscreen socketengine xembed-raster xembed-widgets windowtransparency +qpainfo qscreen socketengine xembed-raster xembed-widgets windowtransparency \ +foreignwindows |