diff options
author | Liang Qi <liang.qi@qt.io> | 2017-10-30 08:43:14 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-10-30 08:54:05 +0100 |
commit | 17d51411132edef53e79dcbaf1046f06f79bed5d (patch) | |
tree | 38398d448b30313f91960c70a3a28cce91293da9 /tests | |
parent | ea0e868c4881944207e9b3a77011e05a505ff3b7 (diff) | |
parent | 9f0dda29d5d070f63b7f098139f01f07ec91ffdf (diff) |
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts:
src/plugins/platforms/windows/qwindowswindow.cpp
tests/auto/widgets/kernel/qaction/tst_qaction.cpp
Change-Id: Ia017a825ed2ca2d53ac586f4ae48df6f65818d40
Diffstat (limited to 'tests')
18 files changed, 596 insertions, 58 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 7bf45be58c..9026864b12 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -109,6 +109,30 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QFile::FileError) + +class StdioFileGuard +{ + Q_DISABLE_COPY(StdioFileGuard) +public: + explicit StdioFileGuard(FILE *f = nullptr) : m_file(f) {} + ~StdioFileGuard() { close(); } + + operator FILE *() const { return m_file; } + + void close(); + +private: + FILE * m_file; +}; + +void StdioFileGuard::close() +{ + if (m_file != nullptr) { + fclose(m_file); + m_file = nullptr; + } +} + class tst_QFile : public QObject { Q_OBJECT @@ -660,14 +684,13 @@ void tst_QFile::size() } { - QFile f; - FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb"); + StdioFileGuard stream(QT_FOPEN(filename.toLocal8Bit().constData(), "rb")); QVERIFY( stream ); + QFile f; QVERIFY( f.open(stream, QIODevice::ReadOnly) ); QCOMPARE( f.size(), size ); f.close(); - fclose(stream); } { @@ -1592,12 +1615,34 @@ void tst_QFile::writeTextFile() } #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +// Helper for executing QFile::open() with warning in QTRY_VERIFY(), which evaluates the condition +// multiple times +static bool qFileOpen(QFile &file, QIODevice::OpenMode ioFlags) +{ + const bool result = file.isOpen() || file.open(ioFlags); + if (!result) + qWarning() << "Cannot open" << file.fileName() << ':' << file.errorString(); + return result; +} + +// Helper for executing fopen() with warning in QTRY_VERIFY(), which evaluates the condition +// multiple times +static bool fOpen(const QByteArray &fileName, const char *mode, FILE **file) +{ + if (*file == nullptr) + *file = fopen(fileName.constData(), mode); + if (*file == nullptr) + qWarning("Cannot open %s: %s", fileName.constData(), strerror(errno)); + return *file != nullptr; +} + void tst_QFile::largeUncFileSupport() { qint64 size = Q_INT64_C(8589934592); qint64 dataOffset = Q_INT64_C(8589914592); QByteArray knownData("LargeFile content at offset 8589914592"); QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin"); + const QByteArray largeFileEncoded = QFile::encodeName(largeFile); { // 1) Native file handling. @@ -1605,31 +1650,36 @@ void tst_QFile::largeUncFileSupport() QVERIFY2(file.exists(), msgFileDoesNotExist(largeFile)); QCOMPARE(file.size(), size); - QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); + // Retry in case of sharing violation + QTRY_VERIFY2(qFileOpen(file, QIODevice::ReadOnly), msgOpenFailed(file).constData()); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); } { // 2) stdlib file handling. + FILE *fhF = nullptr; + // Retry in case of sharing violation + QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF)); + StdioFileGuard fh(fhF); QFile file; - FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb"); QVERIFY(file.open(fh, QIODevice::ReadOnly)); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); - fclose(fh); } { // 3) stdio file handling. - QFile file; - FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb"); + FILE *fhF = nullptr; + // Retry in case of sharing violation + QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF)); + StdioFileGuard fh(fhF); int fd = int(_fileno(fh)); + QFile file; QVERIFY(file.open(fd, QIODevice::ReadOnly)); QCOMPARE(file.size(), size); QVERIFY(file.seek(dataOffset)); QCOMPARE(file.read(knownData.size()), knownData); - fclose(fh); } } #endif @@ -1670,7 +1720,7 @@ void tst_QFile::bufferedRead() file.write("abcdef"); file.close(); - FILE *stdFile = fopen("stdfile.txt", "r"); + StdioFileGuard stdFile(fopen("stdfile.txt", "r")); QVERIFY(stdFile); char c; QCOMPARE(int(fread(&c, 1, 1, stdFile)), 1); @@ -1685,8 +1735,6 @@ void tst_QFile::bufferedRead() QCOMPARE(c, 'b'); QCOMPARE(file.pos(), qlonglong(2)); } - - fclose(stdFile); } #ifdef Q_OS_UNIX @@ -1815,7 +1863,7 @@ void tst_QFile::FILEReadWrite() f.close(); } - FILE *fp = fopen("FILEReadWrite.txt", "r+b"); + StdioFileGuard fp(fopen("FILEReadWrite.txt", "r+b")); QVERIFY(fp); QFile file; QVERIFY2(file.open(fp, QFile::ReadWrite), msgOpenFailed(file).constData()); @@ -1850,7 +1898,7 @@ void tst_QFile::FILEReadWrite() } file.close(); - fclose(fp); + fp.close(); // check modified file { @@ -2436,11 +2484,10 @@ void tst_QFile::virtualFile() void tst_QFile::textFile() { -#if defined(Q_OS_WIN) - FILE *fs = ::fopen("writeabletextfile", "wt"); -#else - FILE *fs = ::fopen("writeabletextfile", "w"); -#endif + const char *openMode = QOperatingSystemVersion::current().type() != QOperatingSystemVersion::Windows + ? "w" : "wt"; + StdioFileGuard fs(fopen("writeabletextfile", openMode)); + QVERIFY(fs); QFile f; QByteArray part1("This\nis\na\nfile\nwith\nnewlines\n"); QByteArray part2("Add\nsome\nmore\nnewlines\n"); @@ -2449,7 +2496,7 @@ void tst_QFile::textFile() f.write(part1); f.write(part2); f.close(); - ::fclose(fs); + fs.close(); QFile file("writeabletextfile"); QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); @@ -2705,11 +2752,12 @@ void tst_QFile::handle() //test round trip of adopted stdio file handle QFile file2; - FILE *fp = fopen(qPrintable(m_testSourceFile), "r"); + StdioFileGuard fp(fopen(qPrintable(m_testSourceFile), "r")); + QVERIFY(fp); file2.open(fp, QIODevice::ReadOnly); QCOMPARE(int(file2.handle()), int(fileno(fp))); QCOMPARE(int(file2.handle()), int(fileno(fp))); - fclose(fp); + fp.close(); //test round trip of adopted posix file handle #ifdef Q_OS_UNIX diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc index ea9b8270e0..54b2e0a0e2 100644 --- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc +++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc @@ -21,6 +21,7 @@ <file>platforms/+unix/+darwin/test</file> <file>platforms/+unix/+haiku/test</file> <file>platforms/+unix/+linux/test</file> + <file>platforms/+unix/+qnx/test</file> <file>platforms/+unix/test</file> <file>platforms/+windows/+wince/test</file> <file>platforms/+windows/+winnt/test</file> @@ -34,6 +35,7 @@ <file>platforms/+mac/test</file> <file>platforms/+haiku/test</file> <file>platforms/+linux/test</file> + <file>platforms/+qnx/test</file> <file>platforms/+wince/test</file> <file>platforms/+winrt/test</file> @@ -44,6 +46,7 @@ <file>platforms/+macos/test2</file> <file>platforms/+haiku/test2</file> <file>platforms/+linux/test2</file> + <file>platforms/+qnx/test2</file> <file>platforms/+wince/test2</file> <file>platforms/+winnt/test2</file> <file>platforms/+winrt/test2</file> diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index c537e43802..c9f1e3d9f6 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -86,7 +86,7 @@ void tst_QFileSelector::basicTest_data() QString expectedPlatform2File(""); //Only the last selector QString expectedPlatform3File; // Only the first selector (the family) #if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && \ - !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) + !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) && !defined(Q_OS_QNX) /* We are only aware of specific unixes, and do not have test files for any of the others. However those unixes can get a selector added from the result of a uname call, so this will lead to a case where we don't have that file so we can't expect the concatenation of platform diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 400a89c03f..20282068cb 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2063,6 +2063,11 @@ void tst_QUrl::isValid() QVERIFY(!url.isValid()); QVERIFY(url.toString().isEmpty()); QVERIFY(url.errorString().contains("Path component starts with '//' and authority is absent")); + + // should disappear if we set a port + url.setPort(80); + QVERIFY(url.isValid()); + QCOMPARE(url.toString(), QString("http://:80//example.com")); } { @@ -2071,6 +2076,13 @@ void tst_QUrl::isValid() QVERIFY(!url.isValid()); QVERIFY(url.toString().isEmpty()); QVERIFY(url.errorString().contains("':' before any '/'")); + + // this specific error disappears if we set anything in the authority, + // but then we run into another error + url.setPort(80); + QVERIFY(!url.isValid()); + QVERIFY(url.toString().isEmpty()); + QVERIFY(url.errorString().contains("Path component is relative and authority is present")); } { @@ -2810,6 +2822,29 @@ void tst_QUrl::setPort() QCOMPARE(url.port(), -1); QVERIFY(url.errorString().contains("out of range")); } + + { + QUrl reference("//:80"); + QUrl piecewise; + piecewise.setPort(80); + QCOMPARE(piecewise, reference); + } + + { + // setAuthority must clear the port + QUrl url("http://example.com:80"); + url.setAuthority("example.org"); + QCOMPARE(url.port(), -1); + QCOMPARE(url.toString(), QString("http://example.org")); + } + + { + // setAuthority must clear the port + QUrl url("http://example.com:80"); + url.setAuthority(QString()); + QCOMPARE(url.port(), -1); + QCOMPARE(url.toString(), QString("http:")); + } } void tst_QUrl::port_data() diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index d22850ba4e..93afca3d48 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -491,10 +491,12 @@ private Q_SLOTS: void ioHttpRedirect_data(); void ioHttpRedirect(); void ioHttpRedirectFromLocalToRemote(); - void ioHttpRedirectPost_data(); - void ioHttpRedirectPost(); + void ioHttpRedirectPostPut_data(); + void ioHttpRedirectPostPut(); void ioHttpRedirectMultipartPost_data(); void ioHttpRedirectMultipartPost(); + void ioHttpRedirectDelete(); + void ioHttpRedirectCustom(); #ifndef QT_NO_SSL void putWithServerClosingConnectionImmediately(); #endif @@ -546,7 +548,7 @@ static void setupSslServer(QSslSocket* serverSocket) } #endif -// Does not work for PUT! Limited support for POST. +// Limited support for POST and PUT. class MiniHttpServer: public QTcpServer { Q_OBJECT @@ -678,7 +680,7 @@ public slots: if (doubleEndlPos != -1) { const int endOfHeader = doubleEndlPos + 4; - hasContent = receivedData.startsWith("POST"); + hasContent = receivedData.startsWith("POST") || receivedData.startsWith("PUT"); if (hasContent && contentLength == 0) parseContentLength(); contentRead = receivedData.length() - endOfHeader; @@ -8546,37 +8548,46 @@ void tst_QNetworkReply::ioHttpRedirectFromLocalToRemote() QCOMPARE(reply->readAll(), reference.readAll()); } -void tst_QNetworkReply::ioHttpRedirectPost_data() +void tst_QNetworkReply::ioHttpRedirectPostPut_data() { + QTest::addColumn<bool>("usePost"); QTest::addColumn<QString>("status"); QTest::addColumn<QByteArray>("data"); QTest::addColumn<QString>("contentType"); QByteArray data; data = "hello world"; - QTest::addRow("307") << "307 Temporary Redirect" << data << "text/plain"; + QTest::addRow("post-307") << true << "307 Temporary Redirect" << data << "text/plain"; + QTest::addRow("put-307") << false << "307 Temporary Redirect" << data << "text/plain"; QString permanentRedirect = "308 Permanent Redirect"; - QTest::addRow("308") << permanentRedirect << data << "text/plain"; + QTest::addRow("post-308") << true << permanentRedirect << data << "text/plain"; + QTest::addRow("put-308") << false << permanentRedirect << data << "text/plain"; // Some data from ::putToFile_data data = ""; - QTest::newRow("empty") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-empty") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-empty") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray("abcd\0\1\2\abcd",12); - QTest::newRow("with-nul") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-with-nul") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-with-nul") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray(4097, '\4'); - QTest::newRow("4k+1") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-4k+1") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-4k+1") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray(128*1024+1, '\177'); - QTest::newRow("128k+1") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-128k+1") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-128k+1") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray(2*1024*1024+1, '\177'); - QTest::newRow("2MB+1") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-2MB+1") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-2MB+1") << false << permanentRedirect << data << "application/octet-stream"; } -void tst_QNetworkReply::ioHttpRedirectPost() +void tst_QNetworkReply::ioHttpRedirectPostPut() { + QFETCH(bool, usePost); QFETCH(QString, status); QFETCH(QByteArray, data); QFETCH(QString, contentType); @@ -8595,7 +8606,7 @@ void tst_QNetworkReply::ioHttpRedirectPost() auto oldRedirectPolicy = manager.redirectPolicy(); manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy); - QNetworkReplyPtr reply(manager.post(request, data)); + QNetworkReplyPtr reply(usePost ? manager.post(request, data) : manager.put(request, data)); // Restore previous policy: manager.setRedirectPolicy(oldRedirectPolicy); @@ -8664,6 +8675,50 @@ void tst_QNetworkReply::ioHttpRedirectMultipartPost() QCOMPARE(replyData, expectedReplyData); } +void tst_QNetworkReply::ioHttpRedirectDelete() +{ + MiniHttpServer target(httpEmpty200Response, false); + QUrl targetUrl("http://localhost/"); + targetUrl.setPort(target.serverPort()); + + QString redirectReply = tempRedirectReplyStr().arg(targetUrl.toString()); + MiniHttpServer redirectServer(redirectReply.toLatin1()); + QUrl url("http://localhost/"); + url.setPort(redirectServer.serverPort()); + QNetworkRequest request(url); + auto oldRedirectPolicy = manager.redirectPolicy(); + manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy); + + QNetworkReplyPtr reply(manager.deleteResource(request)); + // Restore previous policy: + manager.setRedirectPolicy(oldRedirectPolicy); + + QCOMPARE(waitForFinish(reply), int(Success)); + QVERIFY2(target.receivedData.startsWith("DELETE"), "Target server called with the wrong method"); +} + +void tst_QNetworkReply::ioHttpRedirectCustom() +{ + MiniHttpServer target(httpEmpty200Response, false); + QUrl targetUrl("http://localhost/"); + targetUrl.setPort(target.serverPort()); + + QString redirectReply = tempRedirectReplyStr().arg(targetUrl.toString()); + MiniHttpServer redirectServer(redirectReply.toLatin1()); + QUrl url("http://localhost/"); + url.setPort(redirectServer.serverPort()); + QNetworkRequest request(url); + auto oldRedirectPolicy = manager.redirectPolicy(); + manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy); + + QNetworkReplyPtr reply(manager.sendCustomRequest(request, QByteArrayLiteral("CUSTOM"))); + // Restore previous policy: + manager.setRedirectPolicy(oldRedirectPolicy); + + QCOMPARE(waitForFinish(reply), int(Success)); + QVERIFY2(target.receivedData.startsWith("CUSTOM"), "Target server called with the wrong method"); +} + #ifndef QT_NO_SSL class PutWithServerClosingConnectionImmediatelyHandler: public QObject diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index e73af60e74..dc8de72b2a 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -47,6 +47,7 @@ #include <qpa/qplatformintegration.h> #include <qpa/qplatformaccessibility.h> #include <QtGui/private/qguiapplication_p.h> +#include <QtGui/private/qhighdpiscaling_p.h> #if defined(Q_OS_WIN) && defined(interface) # undef interface @@ -301,6 +302,7 @@ void tst_QAccessibility::cleanup() qAccessibleEventString(list.at(i)->type()), list.at(i)->child()); } QTestAccessibility::clearEvents(); + QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QAccessibility::eventTest() @@ -3743,14 +3745,14 @@ void tst_QAccessibility::bridgeTest() // Ideally it should be extended to test all aspects of the bridge. #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // First, test MSAA part of bridge - QWidget *window = new QWidget; - QVBoxLayout *lay = new QVBoxLayout(window); - QPushButton *button = new QPushButton(tr("Push me"), window); - QTextEdit *te = new QTextEdit(window); + QWidget window; + QVBoxLayout *lay = new QVBoxLayout(&window); + QPushButton *button = new QPushButton(tr("Push me"), &window); + QTextEdit *te = new QTextEdit(&window); te->setText(QLatin1String("hello world\nhow are you today?\n")); // Add QTableWidget - QTableWidget *tableWidget = new QTableWidget(3, 3, window); + QTableWidget *tableWidget = new QTableWidget(3, 3, &window); tableWidget->setColumnCount(3); QStringList hHeader; hHeader << "h1" << "h2" << "h3"; @@ -3776,8 +3778,8 @@ void tst_QAccessibility::bridgeTest() lay->addWidget(tableWidget); lay->addWidget(label); - window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); /************************************************** @@ -3789,9 +3791,8 @@ void tst_QAccessibility::bridgeTest() QCOMPARE(buttonRect.topLeft(), buttonPos); // All set, now test the bridge. - POINT pt; - pt.x = buttonRect.center().x(); - pt.y = buttonRect.center().y(); + const QPoint nativePos = QHighDpi::toNativePixels(buttonRect.center(), window.windowHandle()); + POINT pt{nativePos.x(), nativePos.y()}; IAccessible *iaccButton; VARIANT varChild; @@ -3817,7 +3818,7 @@ void tst_QAccessibility::bridgeTest() QCOMPARE(SUCCEEDED(hr), false); hr = iaccButton->accLocation(&x, &y, &w, &h, varSELF); - QCOMPARE(buttonRect, QRect(x, y, w, h)); + QCOMPARE(buttonRect, QHighDpi::fromNativePixels(QRect(x, y, w, h), window.windowHandle())); #ifdef QT_SUPPORTS_IACCESSIBLE2 // Test IAccessible2 part of bridge @@ -3832,7 +3833,7 @@ void tst_QAccessibility::bridgeTest() long x, y; hr = ia2Component->get_locationInParent(&x, &y); QVERIFY(SUCCEEDED(hr)); - QCOMPARE(button->pos(), QPoint(x, y)); + QCOMPARE(button->pos(), QHighDpi::fromNativePixels(QPoint(x, y), window.windowHandle())); ia2Component->Release(); /***** Test IAccessibleAction *****/ @@ -3897,7 +3898,7 @@ void tst_QAccessibility::bridgeTest() /************************************************** * QWidget **************************************************/ - QWindow *windowHandle = window->windowHandle(); + QWindow *windowHandle = window.windowHandle(); QPlatformNativeInterface *platform = QGuiApplication::platformNativeInterface(); HWND hWnd = (HWND)platform->nativeResourceForWindow("handle", windowHandle); diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp index 9b0d5b6920..4395a04976 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp @@ -1252,7 +1252,7 @@ void tst_QSqlDatabase::psql_schemas() QString table = schemaName + '.' + qTableName("qtesttable", __FILE__, db); QVERIFY_SQL(q, exec("CREATE TABLE " + table + " (id int primary key, name varchar(20))")); - QVERIFY(db.tables().contains(table)); + QVERIFY(db.tables().contains(table, Qt::CaseInsensitive)); QSqlRecord rec = db.record(table); QCOMPARE(rec.count(), 2); diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index db86fba59c..6ad93b2666 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -96,6 +96,7 @@ private slots: void task248107_backButton(); void task255350_fieldObjectDestroyed(); void taskQTBUG_25691_fieldObjectDestroyed2(); + void taskQTBUG_46894_nextButtonShortcut(); /* Things that could be added: @@ -2700,5 +2701,24 @@ void tst_QWizard::taskQTBUG_25691_fieldObjectDestroyed2() ::taskQTBUG_25691_fieldObjectDestroyed2(); } +void tst_QWizard::taskQTBUG_46894_nextButtonShortcut() +{ + for (int i = 0; i < QWizard::NStyles; ++i) { + QWizard wizard; + QWizard::WizardStyle style = static_cast<QWizard::WizardStyle>(i); + wizard.setWizardStyle(style); + wizard.show(); + QVERIFY(QTest::qWaitForWindowExposed(&wizard)); + + if (wizard.button(QWizard::NextButton)->text() == "&Next") { + QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(), + QKeySequence(Qt::ALT | Qt::Key_Right)); + } else { + QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(), + QKeySequence::mnemonic(wizard.button(QWizard::NextButton)->text())); + } + } +} + QTEST_MAIN(tst_QWizard) #include "tst_qwizard.moc" diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index ac6362168e..4b3db6bd9c 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -62,6 +62,7 @@ private slots: void task229128TriggeredSignalWithoutActiongroup(); void task229128TriggeredSignalWhenInActiongroup(); void repeat(); + void setData(); void keysequence(); // QTBUG-53381 private: @@ -443,5 +444,20 @@ void tst_QAction::repeat() QCOMPARE(spy.count(), 2); } +void tst_QAction::setData() // QTBUG-62006 +{ + QAction act(nullptr); + QSignalSpy spy(&act, &QAction::changed); + QCOMPARE(act.data(), QVariant()); + QCOMPARE(spy.count(), 0); + act.setData(QVariant()); + QCOMPARE(spy.count(), 0); + + act.setData(-1); + QCOMPARE(spy.count(), 1); + act.setData(-1); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(tst_QAction) #include "tst_qaction.moc" diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 9a70208b94..bc50e4f1d8 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -719,9 +719,7 @@ void tst_QMenuBar::taskQTBUG56860_focus() #endif QMainWindow w; QMenuBar *mb = w.menuBar(); - - if (mb->platformMenuBar()) - QSKIP("This test requires the Qt menubar."); + mb->setNativeMenuBar(false); QMenu *em = mb->addMenu("&Edit"); em->setObjectName("EditMenu"); @@ -765,8 +763,7 @@ void tst_QMenuBar::check_homeKey() { // I'm temporarily shutting up this testcase. // Seems like the behaviour i'm expecting isn't ok. - QVERIFY( true ); - return; + QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)"); QEXPECT_FAIL( "0", "Popupmenu should respond to a Home key", Abort ); @@ -807,8 +804,7 @@ void tst_QMenuBar::check_endKey() { // I'm temporarily silenting this testcase. // Seems like the behaviour i'm expecting isn't ok. - QVERIFY( true ); - return; + QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)"); QEXPECT_FAIL( "0", "Popupmenu should respond to an End key", Abort ); diff --git a/tests/manual/widgets/widgets/bigmenucreator/bigmenucreator.pro b/tests/manual/widgets/widgets/bigmenucreator/bigmenucreator.pro new file mode 100644 index 0000000000..69fbea3834 --- /dev/null +++ b/tests/manual/widgets/widgets/bigmenucreator/bigmenucreator.pro @@ -0,0 +1,34 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-10-19T16:07:04 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = BigMenuCreator +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui diff --git a/tests/manual/widgets/widgets/bigmenucreator/main.cpp b/tests/manual/widgets/widgets/bigmenucreator/main.cpp new file mode 100644 index 0000000000..303552c1d5 --- /dev/null +++ b/tests/manual/widgets/widgets/bigmenucreator/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** 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 "mainwindow.h" +#include <QApplication> +#include <QCommandLineParser> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QCommandLineParser parser; + parser.setApplicationDescription("BigMenuCreator"); + parser.addHelpOption(); + parser.addOptions({ + { "new-menubar", QLatin1String("Use new menubar instead of QMainWindow's own.") }, + { "no-parent", QLatin1String("When using a new menubar, do *not* set its parent on construction.") } + }); + + parser.process(a); + + MainWindow::newMenubar = parser.isSet("new-menubar"); + MainWindow::parentlessMenubar = parser.isSet("no-parent"); + + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/tests/manual/widgets/widgets/bigmenucreator/mainwindow.cpp b/tests/manual/widgets/widgets/bigmenucreator/mainwindow.cpp new file mode 100644 index 0000000000..5b30c1be0b --- /dev/null +++ b/tests/manual/widgets/widgets/bigmenucreator/mainwindow.cpp @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** 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 "mainwindow.h" +#include "ui_mainwindow.h" + +bool MainWindow::newMenubar = false; +bool MainWindow::parentlessMenubar = false; + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + const int level = 3; + QMenuBar *mb; + if (newMenubar) + mb = new QMenuBar(parentlessMenubar ? nullptr : this); + else + mb = ui->menuBar; + populateMenu(mb, level); + if (newMenubar) + setMenuBar(mb); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +// We do all the permutations on the following 3 operations: +// +// A: Add action to parent menu +// P: Populate the submenu +// S: Set action submenu +// +// Recursing on menu population gives more combinations of +// creation and insertions. + +void MainWindow::populateMenu(QWidget *menu, int level) +{ + if (level > 0) { + --level; + doAPS(menu, level); + doASP(menu, level); + doPAS(menu, level); + doSPA(menu, level); + doSAP(menu, level); + doPSA(menu, level); + } else { + static int itemCounter = 0; + static const char *sym[] = { "Foo", "Bar", "Baz", "Quux" }; + for (uint i = 0; i < sizeof(sym) / sizeof(sym[0]); i++) { + QString title = QString::fromLatin1("%1 Item %2").arg(QLatin1String(sym[i])).arg(itemCounter); + menu->addAction(new QAction(title)); + } + ++itemCounter; + } +} + +void MainWindow::doAPS(QWidget *menu, int level) +{ + auto *action = new QAction("A P S"); + menu->addAction(action); + auto *submenu = new QMenu; + populateMenu(submenu, level); + action->setMenu(submenu); +} + +void MainWindow::doASP(QWidget *menu, int level) +{ + auto *action = new QAction("A S P"); + menu->addAction(action); + auto *submenu = new QMenu; + action->setMenu(submenu); + populateMenu(submenu, level); +} + +void MainWindow::doPAS(QWidget *menu, int level) +{ + auto *submenu = new QMenu; + populateMenu(submenu, level); + auto *action = new QAction("P A S"); + menu->addAction(action); + action->setMenu(submenu); +} + +void MainWindow::doSPA(QWidget *menu, int level) +{ + auto *action = new QAction("S P A"); + auto *submenu = new QMenu; + action->setMenu(submenu); + populateMenu(submenu, level); + menu->addAction(action); +} + +void MainWindow::doSAP(QWidget *menu, int level) +{ + auto *action = new QAction("S A P"); + auto *submenu = new QMenu; + action->setMenu(submenu); + menu->addAction(action); + populateMenu(submenu, level); +} + +void MainWindow::doPSA(QWidget *menu, int level) +{ + auto *action = new QAction("P S A"); + auto *submenu = new QMenu; + populateMenu(submenu, level); + action->setMenu(submenu); + menu->addAction(action); +} diff --git a/tests/manual/widgets/widgets/bigmenucreator/mainwindow.h b/tests/manual/widgets/widgets/bigmenucreator/mainwindow.h new file mode 100644 index 0000000000..2990f592e9 --- /dev/null +++ b/tests/manual/widgets/widgets/bigmenucreator/mainwindow.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void doAPS(QWidget *menu, int level); + void doASP(QWidget *menu, int level); + void doPAS(QWidget *menu, int level); + + void doSPA(QWidget *menu, int level); + void doSAP(QWidget *menu, int level); + void doPSA(QWidget *menu, int level); + + void populateMenu(QWidget *menu, int level); + + static bool newMenubar; + static bool parentlessMenubar; + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/tests/manual/widgets/widgets/bigmenucreator/mainwindow.ui b/tests/manual/widgets/widgets/bigmenucreator/mainwindow.ui new file mode 100644 index 0000000000..0668202ea5 --- /dev/null +++ b/tests/manual/widgets/widgets/bigmenucreator/mainwindow.ui @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>427</width> + <height>372</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="font"> + <font> + <pointsize>16</pointsize> + </font> + </property> + <property name="text"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'.SF NS Text'; font-size:16pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">We do all the permutations on the following 3 operations:</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;"> A</span><span style=" font-size:14pt;">: Add action to parent menu</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;"> P</span><span style=" font-size:14pt;">: Populate the submenu</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:600;"> S</span><span style=" font-size:14pt;">: Set action submenu</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">This gets repeated 2 menu levels from the menubar. All menus and items are enabled and should show as such.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">The order of menus is APS, ASP, PAS, SPA, SAP, PSA.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">The order of terminal items is &quot;Foo&quot;, &quot;Bar&quot;, &quot;Baz&quot;, &quot;Quux&quot;.</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:14pt;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">Rerun with &quot;--new-menubar&quot; and &quot;--no-parent&quot; to force using a new menubar instead of QMainWindow's own, with or without parent. QMainWindow::setMenuBar() will be called regardless of the parent option.</span></p></body></html></string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menuBar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>427</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QToolBar" name="mainToolBar"> + <attribute name="toolBarArea"> + <enum>TopToolBarArea</enum> + </attribute> + <attribute name="toolBarBreak"> + <bool>false</bool> + </attribute> + </widget> + <widget class="QStatusBar" name="statusBar"/> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> |