diff options
Diffstat (limited to 'tests')
9 files changed, 131 insertions, 46 deletions
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 1379c788d1..40023d7fea 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -465,16 +465,6 @@ void tst_qstandardpaths::testRuntimeDirectory() #ifdef Q_XDG_PLATFORM const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QVERIFY(!runtimeDir.isEmpty()); - - // Check that it can automatically fix permissions - QFile file(runtimeDir); - const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser; - const QFile::Permissions additionalPerms = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; - QCOMPARE(file.permissions(), wantedPerms | additionalPerms); - QVERIFY(file.setPermissions(wantedPerms | QFile::ExeGroup)); - const QString runtimeDirAgain = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); - QCOMPARE(runtimeDirAgain, runtimeDir); - QCOMPARE(QFile(runtimeDirAgain).permissions(), wantedPerms | additionalPerms); #endif } @@ -516,11 +506,27 @@ void tst_qstandardpaths::testCustomRuntimeDirectory() const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir)); - // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should warn (QTBUG-48771) - qputenv("XDG_RUNTIME_DIR", "does_not_exist"); - QTest::ignoreMessage(QtWarningMsg, "QStandardPaths: XDG_RUNTIME_DIR points to non-existing path 'does_not_exist', please create it with 0700 permissions."); + // When $XDG_RUNTIME_DIR points to a directory with wrong permissions, QStandardPaths should warn + const QByteArray wrongPermissionFileName = "wrong_permissions"; + QDir::current().mkdir(wrongPermissionFileName); + QFile wrongPermissionFile(wrongPermissionFileName); + const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser; + QVERIFY(wrongPermissionFile.setPermissions(wantedPerms | QFile::ExeGroup)); + + qputenv("XDG_RUNTIME_DIR", wrongPermissionFileName); + QTest::ignoreMessage(QtWarningMsg, + qPrintable(QString::fromLatin1("QStandardPaths: wrong permissions on runtime directory " + wrongPermissionFileName + ", 7710 instead of 7700"))); + const QString wrongPermissionRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + QVERIFY(wrongPermissionRuntimeDir.isEmpty()); + QDir::current().rmdir(wrongPermissionFileName); + + // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should create it first + const QByteArray nonExistingDir = "does_not_exist"; + qputenv("XDG_RUNTIME_DIR", nonExistingDir); const QString nonExistingRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); - QVERIFY2(nonExistingRuntimeDir.isEmpty(), qPrintable(nonExistingRuntimeDir)); + QVERIFY2(!nonExistingRuntimeDir.compare(nonExistingDir), qPrintable(nonExistingRuntimeDir)); + QVERIFY(QDir::current().exists(nonExistingRuntimeDir)); + QDir::current().rmdir(nonExistingRuntimeDir); // When $XDG_RUNTIME_DIR points to a file, QStandardPaths should warn const QString file = QFINDTESTDATA("tst_qstandardpaths.cpp"); diff --git a/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp b/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp index c931016a61..cf5ead1220 100644 --- a/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp +++ b/tests/auto/corelib/serialization/qdatastream_core_pixmap/tst_qdatastream_core_pixmap.cpp @@ -27,13 +27,8 @@ ****************************************************************************/ #include <QtTest/QtTest> -#include <QtGui/QBitmap> -#include <QtGui/QPalette> #include <QtGui/QPixmap> -#include <QtGui/QPicture> -#include <QtGui/QTextLength> -#include <QtGui/QPainter> -#include <QtGui/QPen> +#include <QtGui/QImage> class tst_QDataStream : public QObject { @@ -41,16 +36,20 @@ Q_OBJECT private slots: void stream_with_pixmap(); - }; void tst_QDataStream::stream_with_pixmap() { // This is a QVariantMap with a 3x3 red QPixmap and two strings inside - const QByteArray ba = QByteArray::fromBase64("AAAAAwAAAAIAegAAAAoAAAAACgB0AGgAZQByAGUAAAACAHAAAABBAAAAAAGJUE5HDQoaCgAAAA1JSERSAAAAAwAAAAMIAgAAANlKIugAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAQSURBVAiZY/zPAAVMDJgsAB1bAQXZn5ieAAAAAElFTkSuQmCCAAAAAgBhAAAACgAAAAAKAGgAZQBsAGwAbw=="); + const QByteArray ba = QByteArray::fromBase64( + "AAAAAwAAAAIAegAAAAoAAAAACgB0AGgAZQByAGUAAAACAHAAAABBAAAAAAGJUE5H" + "DQoaCgAAAA1JSERSAAAAAwAAAAMIAgAAANlKIugAAAAJcEhZcwAADsQAAA7EAZUr" + "DhsAAAAQSURBVAiZY/zPAAVMDJgsAB1bAQXZn5ieAAAAAElFTkSuQmCCAAAAAgBh" + "AAAACgAAAAAKAGgAZQBsAGwAbw=="); QImage dummy; // Needed to make sure qtGui is loaded - QTest::ignoreMessage(QtWarningMsg, "QPixmap::fromImageInPlace: QPixmap cannot be created without a QGuiApplication"); + QTest::ignoreMessage(QtWarningMsg, "QPixmap::fromImageInPlace: " + "QPixmap cannot be created without a QGuiApplication"); QVariantMap map; QDataStream d(ba); @@ -58,11 +57,11 @@ void tst_QDataStream::stream_with_pixmap() d >> map; QCOMPARE(map["a"].toString(), QString("hello")); - QCOMPARE(map["p"].value<QPixmap>(), QPixmap()); // the pixmap is null because this is not a QGuiApplication + // The pixmap is null because this is not a QGuiApplication: + QCOMPARE(map["p"].value<QPixmap>(), QPixmap()); QCOMPARE(map["z"].toString(), QString("there")); } QTEST_GUILESS_MAIN(tst_QDataStream) #include "tst_qdatastream_core_pixmap.moc" - diff --git a/tests/auto/corelib/serialization/serialization.pro b/tests/auto/corelib/serialization/serialization.pro index 9638178cdc..f4a5a3c5b1 100644 --- a/tests/auto/corelib/serialization/serialization.pro +++ b/tests/auto/corelib/serialization/serialization.pro @@ -11,7 +11,8 @@ SUBDIRS = \ qxmlstream !qtHaveModule(gui): SUBDIRS -= \ - qdatastream + qdatastream \ + qdatastream_core_pixmap !qtHaveModule(network): SUBDIRS -= \ qtextstream diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index e97848fb1c..0fe24ed5cb 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -40,6 +40,7 @@ #include "nontracked.h" #include "wrapper.h" +#include <array> #include <memory> #include <stdlib.h> #include <time.h> @@ -105,12 +106,15 @@ private slots: void sharedFromThis(); void constructorThrow(); + void overloads(); void threadStressTest_data(); void threadStressTest(); void validConstructs(); void invalidConstructs_data(); void invalidConstructs(); + + // let invalidConstructs be the last test, because it's the slowest; // add new tests above this block public slots: @@ -2250,6 +2254,11 @@ void tst_QSharedPointer::invalidConstructs_data() << &QTest::QExternalTest::tryCompileFail << "QSharedPointer<Data> ptr(new Data, [](int *) {});\n"; #endif + + QTest::newRow("incompatible-overload") + << &QTest::QExternalTest::tryCompileFail + << "void foo(QSharedPointer<DerivedData>) {}\n" + "void bar() { foo(QSharedPointer<Data>()); }\n"; } void tst_QSharedPointer::invalidConstructs() @@ -2748,5 +2757,50 @@ void tst_QSharedPointer::reentrancyWhileDestructing() ReentrancyWhileDestructing::A obj; } +namespace { +struct Base1 {}; +struct Base2 {}; + +struct Child1 : Base1 {}; +struct Child2 : Base2 {}; + +template<template<typename> class SmartPtr> +struct Overloaded +{ + std::array<int, 1> call(const SmartPtr<const Base1> &) + { + return {}; + } + std::array<int, 2> call(const SmartPtr<const Base2> &) + { + return {}; + } + static const Q_CONSTEXPR uint base1Called = sizeof(std::array<int, 1>); + static const Q_CONSTEXPR uint base2Called = sizeof(std::array<int, 2>); + + void test() + { +#define QVERIFY_CALLS(expr, base) Q_STATIC_ASSERT(sizeof(call(expr)) == base##Called) + QVERIFY_CALLS(SmartPtr<Base1>{}, base1); + QVERIFY_CALLS(SmartPtr<Base2>{}, base2); + QVERIFY_CALLS(SmartPtr<const Base1>{}, base1); + QVERIFY_CALLS(SmartPtr<const Base2>{}, base2); + QVERIFY_CALLS(SmartPtr<Child1>{}, base1); + QVERIFY_CALLS(SmartPtr<Child2>{}, base2); + QVERIFY_CALLS(SmartPtr<const Child1>{}, base1); + QVERIFY_CALLS(SmartPtr<const Child2>{}, base2); +#undef QVERIFY_CALLS + } +}; +} + +void tst_QSharedPointer::overloads() +{ + Overloaded<QSharedPointer> sharedOverloaded; + sharedOverloaded.test(); + Overloaded<QWeakPointer> weakOverloaded; + weakOverloaded.test(); +} + QTEST_MAIN(tst_QSharedPointer) #include "tst_qsharedpointer.moc" diff --git a/tests/auto/other/other.pro b/tests/auto/other/other.pro index c5426202e8..cc6b1887a3 100644 --- a/tests/auto/other/other.pro +++ b/tests/auto/other/other.pro @@ -68,7 +68,4 @@ winrt|!qtHaveModule(gui)|!qtConfig(accessibility): SUBDIRS -= qaccessibility android: SUBDIRS += \ android -qtConfig(xkbcommon): { - SUBDIRS += \ - xkbkeyboard -} +qtHaveModule(gui):qtConfig(xkbcommon): SUBDIRS += xkbkeyboard diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 784d0a70d7..fd7f24f308 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -196,8 +196,7 @@ private slots: void task_250026_data() { generic_data("QODBC"); } void task_250026(); - void task_205701_data() { generic_data("QMYSQL"); } - void task_205701(); + void crashQueryOnCloseDatabase(); void task_233829_data() { generic_data("QPSQL"); } void task_233829(); @@ -311,6 +310,8 @@ void tst_QSqlQuery::init() void tst_QSqlQuery::cleanup() { + if (QTest::currentTestFunction() == QLatin1String("crashQueryOnCloseDatabase")) + return; QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); @@ -3448,19 +3449,17 @@ void tst_QSqlQuery::task_250026() QCOMPARE( q.value( 0 ).toString().length(), data1026.length() ); } -void tst_QSqlQuery::task_205701() +void tst_QSqlQuery::crashQueryOnCloseDatabase() { - QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest"); - qsdb.setHostName("test"); - qsdb.setDatabaseName("test"); - qsdb.setUserName("test"); - qsdb.setPassword("test"); - qsdb.open(); - -// { - QSqlQuery query(qsdb); -// } - QSqlDatabase::removeDatabase("atest"); + for (const auto &dbName : qAsConst(dbs.dbNames)) { + QSqlDatabase clonedDb = QSqlDatabase::cloneDatabase( + QSqlDatabase::database(dbName), "crashTest"); + qDebug() << "Testing crash in sqlquery dtor for driver" << clonedDb.driverName(); + QVERIFY(clonedDb.open()); + QSqlQuery q(clonedDb); + clonedDb.close(); + QSqlDatabase::removeDatabase("crashTest"); + } } #ifdef NOT_READY_YET diff --git a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp index 78fe448bdb..843a30df16 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp @@ -156,6 +156,14 @@ void tst_QGraphicsPixmapItem::contains() QFETCH(QPointF, point); QFETCH(bool, contains); + // At the time of writing, by default pixmaps will have: + // - The same pixel format of the primary screen (which is platform dependent and may contain alpha) + // - Uninitialized pixels, potentially including an alpha channel + // - A ShapeMode of Mask (which mean it will use the alpha channel as a mask for contains()) + // This means that in order to prevent undefined behavior in this test, we either need to set + // the shapeMode to something else, or set the pixels of the pixmap. + pixmap.fill(); // Filling the pixmap to be on the safe side. + SubQGraphicsPixmapItem item(pixmap); QCOMPARE(item.contains(point), contains); } diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 46f1d5df5c..4f8741a5aa 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -3685,8 +3685,6 @@ void tst_QGraphicsScene::changedSignal() qApp->processEvents(); QCOMPARE(cl.changes.size(), 2); QCOMPARE(cl.changes.at(1).size(), 2); - QCOMPARE(cl.changes.at(1).first(), QRectF(0, 0, 10, 10)); - QCOMPARE(cl.changes.at(1).last(), QRectF(20, 0, 10, 10)); QCOMPARE(scene.sceneRect(), QRectF(0, 0, 30, 10)); diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index a95d6e76b3..ebf08883fd 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -399,6 +399,7 @@ private slots: void tabletTracking(); void closeEvent(); + void closeWithChildWindow(); private: bool ensureScreenSize(int width, int height); @@ -11115,5 +11116,27 @@ void tst_QWidget::closeEvent() QCOMPARE(widget.closeCount, 1); } +void tst_QWidget::closeWithChildWindow() +{ + QWidget widget; + auto childWidget = new QWidget(&widget); + childWidget->setAttribute(Qt::WA_NativeWindow); + childWidget->windowHandle()->create(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + widget.windowHandle()->close(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + // Check that the child window inside the window is now visible + QVERIFY(childWidget->isVisible()); + + // Now explicitly hide the childWidget + childWidget->hide(); + widget.windowHandle()->close(); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QVERIFY(!childWidget->isVisible()); +} + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" |