diff options
Diffstat (limited to 'tests')
20 files changed, 660 insertions, 51 deletions
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index fcda3cf6756..820a7b4bdb5 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -7,7 +7,6 @@ #include <qfile.h> #include <qdatetime.h> #include <qdir.h> -#include <qset.h> #include <qstandardpaths.h> #include <qstring.h> #include <qtemporarydir.h> @@ -15,6 +14,7 @@ #include <QtTest/private/qtesthelpers_p.h> +#include <QtCore/private/qduplicatetracker_p.h> #include <QtCore/qscopeguard.h> #if defined(Q_OS_WIN) @@ -551,9 +551,9 @@ void tst_QTemporaryFile::openOnRootDrives() void tst_QTemporaryFile::stressTest() { - const int iterations = 1000; + constexpr int iterations = 1000; - QSet<QString> names; + QDuplicateTracker<QString, iterations> names; const auto remover = qScopeGuard([&] { for (const QString &s : std::as_const(names)) @@ -564,8 +564,7 @@ void tst_QTemporaryFile::stressTest() QTemporaryFile file; file.setAutoRemove(false); QVERIFY2(file.open(), qPrintable(file.errorString())); - QVERIFY(!names.contains(file.fileName())); - names.insert(file.fileName()); + QVERIFY(!names.hasSeen(file.fileName())); } } @@ -826,37 +825,26 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename() #if defined(Q_OS_VXWORKS) QSKIP("QTBUG-130066"); #endif - struct CleanOnReturn - { - ~CleanOnReturn() - { + + QString tempName; + auto cleaner = qScopeGuard([&] { if (!tempName.isEmpty()) QFile::remove(tempName); - } - - void reset() - { - tempName.clear(); - } - - QString tempName; - }; - - CleanOnReturn cleaner; + }); { QTemporaryFile file; QVERIFY( file.open() ); - cleaner.tempName = file.fileName(); + tempName = file.fileName(); - QVERIFY( QFile::exists(cleaner.tempName) ); + QVERIFY(QFile::exists(tempName)); QVERIFY( !QFileInfo("i-do-not-exist").isDir() ); QVERIFY( !file.rename("i-do-not-exist/file.txt") ); - QVERIFY( QFile::exists(cleaner.tempName) ); + QVERIFY(QFile::exists(tempName)); } - QVERIFY( !QFile::exists(cleaner.tempName) ); - cleaner.reset(); + QVERIFY(!QFile::exists(tempName)); + cleaner.dismiss(); // would fail: file is known to no longer exist } void tst_QTemporaryFile::createNativeFile_data() diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index 0254cbd1360..65714036e2d 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -23,6 +23,8 @@ #include "../../../network-settings.h" #include <QtTest/private/qemulationdetector_p.h> +using namespace Qt::StringLiterals; + QT_BEGIN_NAMESPACE template<> struct QMetaTypeId<QIODevice::OpenModeFlag> { enum { Defined = 1 }; static inline int qt_metatype_id() { return QMetaType::Int; } }; @@ -1379,12 +1381,12 @@ void tst_QTextStream::pos2() // ------------------------------------------------------------------------------ void tst_QTextStream::pos3LargeFile() { + // NOTE: The unusual spacing is to ensure non-1-character whitespace. + constexpr auto lineString = " 0 1 2\t3 4\t \t5 6 7 8 9 \n"_L1; { QFile file(testFileName); QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out( &file ); - // NOTE: The unusual spacing is to ensure non-1-character whitespace. - QString lineString = " 0 1 2\t3 4\t \t5 6 7 8 9 \n"; // Approximately 5kb text file (more is too slow (QTBUG-138435)) const int NbLines = (5 * 1024) / lineString.size() + 1; for (int line = 0; line < NbLines; ++line) @@ -1395,8 +1397,15 @@ void tst_QTextStream::pos3LargeFile() QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); QTextStream in( &file ); constexpr int testValues[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + qint64 expectedLineEnd = 0; +#ifdef Q_OS_WIN // CRLF platform + constexpr int crlfAdjustment = 1; +#else + constexpr int crlfAdjustment = 0; +#endif + const auto expectedLineLength = lineString.size() + crlfAdjustment; + QCOMPARE(in.pos(), 0); while (true) { - in.pos(); for (size_t i = 0; i < std::size(testValues); ++i) { int value = -42; if (!(in >> value)) { @@ -1407,6 +1416,9 @@ void tst_QTextStream::pos3LargeFile() } QCOMPARE(value, testValues[i]); } + expectedLineEnd += expectedLineLength; + // Final space and newline are not consumed until next read. + QCOMPARE(in.pos(), expectedLineEnd - 2 - crlfAdjustment); } } @@ -2997,14 +3009,41 @@ void tst_QTextStream::int_write_with_locale_data() QTest::addColumn<int>("numberFlags"); QTest::addColumn<int>("input"); QTest::addColumn<QString>("output"); + QTest::addColumn<int>("fieldWidth"); + QTest::addColumn<QTextStream::FieldAlignment>("fieldAlignment"); + + const auto alignDefault = QTextStream().fieldAlignment(); + constexpr int forceSign = QTextStream::ForceSign; + + QTest::newRow("C -123") << u"C"_s << 0 << -123 << u"-123"_s << 0 << alignDefault; + QTest::newRow("C +123") << u"C"_s << forceSign << 123 << u"+123"_s << 0 << alignDefault; + QTest::newRow("C 12345") << u"C"_s << 0 << 12345 << u"12345"_s << 0 << alignDefault; - QTest::newRow("C -123") << QString("C") << 0 << -123 << QString("-123"); - QTest::newRow("C +123") << QString("C") << (int)QTextStream::ForceSign << 123 << QString("+123"); - QTest::newRow("C 12345") << QString("C") << 0 << 12345 << QString("12345"); + QTest::newRow("de_DE -123") << u"de_DE"_s << 0 << -123 << u"-123"_s << 0 << alignDefault; + QTest::newRow("de_DE +123") << u"de_DE"_s << forceSign << 123 << u"+123"_s << 0 << alignDefault; + QTest::newRow("de_DE 12345") << u"de_DE"_s << 0 << 12345 << u"12.345"_s << 0 << alignDefault; - QTest::newRow("de_DE -123") << QString("de_DE") << 0 << -123 << QString("-123"); - QTest::newRow("de_DE +123") << QString("de_DE") << (int)QTextStream::ForceSign << 123 << QString("+123"); - QTest::newRow("de_DE 12345") << QString("de_DE") << 0 << 12345 << QString("12.345"); + constexpr auto alignAccountingStyle = QTextStream::FieldAlignment::AlignAccountingStyle; + + { + const QLocale loc("ar_EG"_L1); + // Arabic as spoken in Egypt has a two-code-point negativeSign(): + const auto minus = loc.negativeSign(); + QCOMPARE(minus.size(), 2); + // ditto positiveSign(): + const auto plus = loc.positiveSign(); + QCOMPARE(plus.size(), 2); + + QTest::addRow("ar_EG -123") << u"ar_EG"_s << 0 << -123 + << (minus + u" ١٢٣") + << 10 << alignAccountingStyle; + QTest::newRow("ar_EG +123") << u"ar_EG"_s << forceSign << 123 + << (plus + u" ١٢٣") + << 10 << alignAccountingStyle; + QTest::newRow("ar_EG 12345") << u"ar_EG"_s << 0 << 12345 + << u" ١٢٬٣٤٥"_s + << 10 << alignAccountingStyle; + } } void tst_QTextStream::int_write_with_locale() @@ -3013,12 +3052,18 @@ void tst_QTextStream::int_write_with_locale() QFETCH(int, numberFlags); QFETCH(int, input); QFETCH(QString, output); + QFETCH(const int, fieldWidth); + QFETCH(const QTextStream::FieldAlignment, fieldAlignment); QString result; QTextStream stream(&result); stream.setLocale(QLocale(locale)); + stream.setFieldAlignment(fieldAlignment); if (numberFlags) stream.setNumberFlags(QTextStream::NumberFlags(numberFlags)); + if (fieldWidth) + stream.setFieldWidth(fieldWidth); + QVERIFY(stream << input); QCOMPARE(result, output); } diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index bfc6074689b..50e17728cf3 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -78,6 +78,9 @@ private slots: void negativeZero_data(); void negativeZero(); + void signsNeverCompareEqualToNullCharacter_data() { testNames_data(); } + void signsNeverCompareEqualToNullCharacter(); + void dayOfWeek(); void dayOfWeek_data(); void formatDate(); @@ -2114,6 +2117,19 @@ void tst_QLocale::negativeZero() QCOMPARE(locale.toString(std::copysign(0.0, -1.0)), expect); } +void tst_QLocale::signsNeverCompareEqualToNullCharacter() // otherwise QTextStream has a problem +{ + QFETCH(QLocale::Language, language); + QFETCH(const QLocale::Territory, country); + + if (language == QLocale::AnyLanguage && country == QLocale::AnyTerritory) + language = QLocale::C; + + const QLocale loc(language, country); + QCOMPARE_NE(loc.negativeSign(), QChar()); + QCOMPARE_NE(loc.positiveSign(), QChar()); +} + void tst_QLocale::dayOfWeek_data() { QTest::addColumn<QDate>("date"); diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 2cd1398e7f9..c7f4c35f413 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -22,8 +22,9 @@ #include <qstringmatcher.h> #include <qbytearraymatcher.h> #include <qvariant.h> - #include <qlocale.h> +#include <QtCore/qxptype_traits.h> + #include <locale.h> #include <qhash.h> #include <private/qtools_p.h> @@ -623,6 +624,7 @@ private slots: void fromUcs4(); void toUcs4(); void arg(); + void arg_negative_tests(); void number(); void number_double_data(); void number_double(); @@ -6981,6 +6983,26 @@ void tst_QString::arg() u"\u0660\u0660\u0661\u0662\u0663\u066c\u0664\u0665\u0666\u066c\u0667\u0668\u0669"); // ٠٠١٢٣٬٤٥٦٬٧٨٩ } +template <typename S, typename...Ts> +using arg_compile_test = decltype(std::declval<S>().arg(std::declval<Ts>()...)); +template <typename S, typename...Ts> +constexpr bool arg_compiles_v = qxp::is_detected_v<arg_compile_test, S, Ts...>; + +void tst_QString::arg_negative_tests() +{ + static_assert(!arg_compiles_v<QString&, QObject*>); + // QLatin1StringView::arg() is unconstrained... + // static_assert(!arg_compiles_v<QLatin1StringView&, QObject*>); + + // integral type called like an FP overload: + static_assert(!arg_compiles_v<QString&, int, int, char, int, QChar>); + static_assert(!arg_compiles_v<QString&, long, int, char, int, char16_t>); + + // strong enums don't match: + enum class Strong {}; + static_assert(!arg_compiles_v<QString&, Strong>); +} + void tst_QString::number() { QCOMPARE(QString::number(int(0)), QLatin1String("0")); diff --git a/tests/auto/dbus/qdbusconnection/CMakeLists.txt b/tests/auto/dbus/qdbusconnection/CMakeLists.txt index 56ae21f2911..cbbe76a7dc7 100644 --- a/tests/auto/dbus/qdbusconnection/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection/CMakeLists.txt @@ -19,3 +19,15 @@ qt_internal_add_test(tst_qdbusconnection TESTDATA tst_qdbusconnection.conf ) + +qt_internal_add_executable(qdbusdelayeddeliveryreenablehelper + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" + SOURCES + qdbusdelayeddeliveryreenablehelper.cpp + LIBRARIES + Qt::DBus +) + +add_dependencies(tst_qdbusconnection + qdbusdelayeddeliveryreenablehelper +) diff --git a/tests/auto/dbus/qdbusconnection/qdbusdelayeddeliveryreenablehelper.cpp b/tests/auto/dbus/qdbusconnection/qdbusdelayeddeliveryreenablehelper.cpp new file mode 100644 index 00000000000..cd916d5b639 --- /dev/null +++ b/tests/auto/dbus/qdbusconnection/qdbusdelayeddeliveryreenablehelper.cpp @@ -0,0 +1,56 @@ +// Copyright (C) 2025 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtCore/QTimer> +#include <QtCore/QCoreApplication> +#include <QtDBus/QDBusConnection> +#include <QtDBus/QDBusMessage> + +#include <stdio.h> + +using namespace Qt::StringLiterals; +using namespace std::chrono_literals; + +static QString myInterface() +{ + return u"local.qdbusdelayeddeliveryreenablehelper"_s; +} + +static void makeSynchronousCall(QDBusConnection &conn) +{ + QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.DBus", "/", + "org.freedesktop.DBus.Peer", "Ping"); + conn.call(msg); +} + +static void emitSignal(QDBusConnection &conn) +{ + QDBusMessage msg = QDBusMessage::createSignal("/", myInterface(), "quit"); + conn.send(msg); +} + +int main(int argc, char **argv) +{ + // Open a connection to the bus *before* QCoreApplication exists; + // this will put the connection in delayed delivery mode + QDBusConnection session = QDBusConnection::sessionBus(); + if (!session.isConnected()) { + fprintf(stderr, "Session bus did not connect!"); + return 1; + } + makeSynchronousCall(session); + + QCoreApplication app(argc, argv); + QTimer::singleShot(15s, qApp, [] { + fprintf(stderr, "Did not receive signal.\n"); + qApp->exit(1); + }); + + // connect a remote, wildcard signal to qApp->quit() + session.connect(QString(), QString(), myInterface(), "quit", &app, SLOT(quit())); + + // send ourselves the signal to quit, via D-Bus + emitSignal(session); + + return app.exec(); +} diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp index ab750dff330..fe9214c5513 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp @@ -13,11 +13,6 @@ #include <QDBusInterface> #include <QDBusConnectionInterface> -#ifdef Q_OS_UNIX -# include <sys/types.h> -# include <signal.h> -#endif - void MyObject::method(const QDBusMessage &msg) { path = msg.path(); @@ -1473,6 +1468,31 @@ void tst_QDBusConnection::parentClassSignal() QTRY_COMPARE(recv.signalsReceived, 2); } +// see also tst_qdbusconnection_delayed +void tst_QDBusConnection::delayedDeliveryReenabledAfterUsedInMainThread() +{ +#if !QT_CONFIG(process) + QSKIP("Test requires QProcess"); +#elif defined(HAS_HOOKSETUPFUNCTION) + QSKIP("No difference to run by tst_QDBusConnection"); +#else +# if defined(Q_OS_WIN) +# define EXE ".exe" +# else +# define EXE "" +# endif + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + + QProcess process; + process.start(QFINDTESTDATA("qdbusdelayeddeliveryreenablehelper" EXE)); + QVERIFY2(process.waitForFinished(25000), qPrintable(process.errorString())); + QCOMPARE(process.readAllStandardError(), QString()); + QCOMPARE(process.exitCode(), 0); +# undef EXE +#endif +} + QString MyObject::path; QString MyObjectWithoutInterface::path; QString MyObjectWithoutInterface::interface; diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h index 4137859414c..dc37e3157b4 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h @@ -126,6 +126,8 @@ private slots: void parentClassSignal(); + void delayedDeliveryReenabledAfterUsedInMainThread(); + public: QString serviceName() const { return "org.qtproject.Qt.Autotests.QDBusConnection"; } bool callMethod(const QDBusConnection &conn, const QString &path); diff --git a/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt b/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt index 52e11b3dbd9..f68df406d68 100644 --- a/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt +++ b/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt @@ -16,4 +16,5 @@ qt_internal_add_test(tst_qdbuspendingreply tst_qdbuspendingreply.cpp LIBRARIES Qt::DBus + Qt::DBusPrivate ) diff --git a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp index da25f768d05..361bff0143a 100644 --- a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp +++ b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp @@ -11,6 +11,8 @@ #include <QDBusAbstractAdaptor> #include <QDBusPendingReply> +#include <private/qdbuspendingcall_p.h> + typedef QMap<int,QString> IntStringMap; Q_DECLARE_METATYPE(IntStringMap) @@ -67,6 +69,14 @@ private slots: void synchronousSimpleTypes(); void errors(); + + void getResultFromAnotherInstance_data(); + void getResultFromAnotherInstance(); + + void moveSemantics(); + + void copyPreservesReplySignature(); + void movePreservesReplySignature(); }; class TypesInterface: public QDBusAbstractAdaptor @@ -561,6 +571,248 @@ void tst_QDBusPendingReply::errors() QCOMPARE(dummystring, QString()); } +void tst_QDBusPendingReply::getResultFromAnotherInstance_data() +{ + QTest::addColumn<bool>("shouldMove"); + + QTest::newRow("copy") << false; + QTest::newRow("move") << true; +} + +void tst_QDBusPendingReply::getResultFromAnotherInstance() +{ + QFETCH(const bool, shouldMove); + + // void + { + QDBusPendingReply<> r = iface->asyncCall("retrieveVoid"); + + QDBusPendingReply<> other; + if (shouldMove) + other = std::move(r); + else + other = r; + other.waitForFinished(); + + QVERIFY(other.isFinished()); + QVERIFY(!other.isError()); + QCOMPARE_EQ(other.count(), 0); + } + + // multiple parameters + { + QDBusPendingReply<int, int> r = iface->asyncCall("retrieveIntInt"); + + QDBusPendingReply<int, int> other; + if (shouldMove) + other = std::move(r); + else + other = r; + other.waitForFinished(); + + QVERIFY(other.isFinished()); + QVERIFY(!other.isError()); + QCOMPARE(other.count(), 2); + + int i1 = 0; + int i2 = 0; + adaptor->retrieveIntInt(i1, i2); + + QCOMPARE_EQ(other.argumentAt<0>(), i1); + QCOMPARE_EQ(other.argumentAt<1>(), i2); + } + + // complex types + { + QDBusPendingReply<IntStringMap> r = iface->asyncCall("retrieveIntStringMap"); + + QDBusPendingReply<IntStringMap> other; + if (shouldMove) + other = std::move(r); + else + other = r; + other.waitForFinished(); + + QVERIFY(other.isFinished()); + QVERIFY(!other.isError()); + QCOMPARE_EQ(other.count(), 1); + QCOMPARE_EQ(other.value(), adaptor->retrieveIntStringMap()); + } +} + +void tst_QDBusPendingReply::moveSemantics() +{ + // void + { + QDBusPendingReply<> r = iface->asyncCall("retrieveVoid"); + r.waitForFinished(); + QVERIFY(r.isFinished()); + + QDBusPendingReply<> copy = r; + + QDBusPendingReply<> other = std::move(copy); + QCOMPARE_EQ(other.d, r.d); + + copy = std::move(other); + QCOMPARE_EQ(copy.d, r.d); + } + + // multiple parameters + { + QDBusPendingReply<int, int> r = iface->asyncCall("retrieveIntInt"); + r.waitForFinished(); + QVERIFY(r.isFinished()); + + QDBusPendingReply<int, int> copy = r; + + QDBusPendingReply<int, int> other = std::move(copy); + QCOMPARE_EQ(other.d, r.d); + + copy = std::move(other); + QCOMPARE_EQ(copy.d, r.d); + } + + // complex types + { + QDBusPendingReply<IntStringMap> r = iface->asyncCall("retrieveIntStringMap"); + r.waitForFinished(); + QVERIFY(r.isFinished()); + + QDBusPendingReply<IntStringMap> copy = r; + + QDBusPendingReply<IntStringMap> other = std::move(copy); + QCOMPARE_EQ(other.d, r.d); + + copy = std::move(other); + QCOMPARE_EQ(copy.d, r.d); + } +} + +void tst_QDBusPendingReply::copyPreservesReplySignature() +{ + // void + { + QDBusPendingCall c = iface->asyncCall("retrieveVoid"); + c.waitForFinished(); + QVERIFY(c.isFinished()); + + // QDBusPendingCall does not initialize reply signature + QVERIFY(c.d->expectedReplySignature.isNull()); + + // copy-construct + { + QDBusPendingReply<> r = c; + QVERIFY(!r.d->expectedReplySignature.isNull()); + QVERIFY(r.d->expectedReplySignature.isEmpty()); + + QDBusPendingReply<> other = r; + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + + // copy-assign + { + QDBusPendingReply<> r; + r = c; + QVERIFY(!r.d->expectedReplySignature.isNull()); + QVERIFY(r.d->expectedReplySignature.isEmpty()); + + QDBusPendingReply<> other; + other = r; + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + } + + // complex types + { + QDBusPendingCall c = iface->asyncCall("retrieveIntStringMap"); + c.waitForFinished(); + QVERIFY(c.isFinished()); + + // QDBusPendingCall does not initialize reply signature + QVERIFY(c.d->expectedReplySignature.isNull()); + + // copy-construct + { + QDBusPendingReply<IntStringMap> r = c; + QVERIFY(!r.d->expectedReplySignature.isEmpty()); + + QDBusPendingReply<IntStringMap> other = r; + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + + // copy-assign + { + QDBusPendingReply<IntStringMap> r; + r = c; + QVERIFY(!r.d->expectedReplySignature.isEmpty()); + + QDBusPendingReply<IntStringMap> other; + other = r; + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + } +} + +void tst_QDBusPendingReply::movePreservesReplySignature() +{ + // void + { + QDBusPendingCall c = iface->asyncCall("retrieveVoid"); + c.waitForFinished(); + QVERIFY(c.isFinished()); + + // QDBusPendingCall does not initialize reply signature + QVERIFY(c.d->expectedReplySignature.isNull()); + + QDBusPendingReply<> r = c; + QVERIFY(!r.d->expectedReplySignature.isNull()); + QVERIFY(r.d->expectedReplySignature.isEmpty()); + + // move-construct + { + QDBusPendingReply<> copy = r; + QDBusPendingReply<> other = std::move(copy); + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + + // move-assign + { + QDBusPendingReply<> copy = r; + QDBusPendingReply<> other; + other = std::move(copy); + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + } + + // complex types + { + QDBusPendingCall c = iface->asyncCall("retrieveIntStringMap"); + c.waitForFinished(); + QVERIFY(c.isFinished()); + + // QDBusPendingCall does not initialize reply signature + QVERIFY(c.d->expectedReplySignature.isNull()); + + QDBusPendingReply<IntStringMap> r = c; + QVERIFY(!r.d->expectedReplySignature.isEmpty()); + + // move-construct + { + QDBusPendingReply<IntStringMap> copy = r; + QDBusPendingReply<IntStringMap> other = std::move(copy); + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + + // move-assign + { + QDBusPendingReply<IntStringMap> copy = r; + QDBusPendingReply<IntStringMap> other; + other = std::move(copy); + QCOMPARE_EQ(other.d->expectedReplySignature, r.d->expectedReplySignature); + } + } +} + QTEST_MAIN(tst_QDBusPendingReply) #include "tst_qdbuspendingreply.moc" diff --git a/tests/auto/other/android/deployment_settings/tst_android_deployment_settings.cpp b/tests/auto/other/android/deployment_settings/tst_android_deployment_settings.cpp index 571570e370f..9297958ba31 100644 --- a/tests/auto/other/android/deployment_settings/tst_android_deployment_settings.cpp +++ b/tests/auto/other/android/deployment_settings/tst_android_deployment_settings.cpp @@ -87,7 +87,8 @@ void tst_android_deployment_settings::DeploymentSettings_data() << "permissions" << "[{\"maxSdkVersion\":\"34\",\"minSdkVersion\":\"32\",\"name\":\"PERMISSION_WITH_" "ATTRIBUTES\"},{\"name\":\"PERMISSION_WITHOUT_ATTRIBUTES\"},{\"name\":\"android." - "permission.INTERNET\"},{\"name\":\"android.permission.WRITE_EXTERNAL_STORAGE\"}]"; + "permission.WRITE_EXTERNAL_STORAGE\"},{\"name\":\"android." + "permission.INTERNET\"}]"; } void tst_android_deployment_settings::DeploymentSettings() diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 011852c28e4..95bcc9b20e2 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -929,6 +929,27 @@ void tst_QAccessibility::actionTest() QCOMPARE(click_count, 1); } QTestAccessibility::clearEvents(); + + { + QCOMPARE(QAccessibleActionInterface::showMenuAction(), QString(QStringLiteral("ShowMenu"))); + + auto widgetHolder = std::make_unique<QWidget>(); + auto widget = widgetHolder.get(); + widget->addAction(new QAction("Foo")); + widget->addAction(new QAction("Bar")); + widget->show(); + + QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(widget); + QVERIFY(interface); + QVERIFY(interface->isValid()); + QAccessibleActionInterface *actions = interface->actionInterface(); + QVERIFY(actions); + + QCOMPARE(actions->actionNames(), QStringList()); + widget->setContextMenuPolicy(Qt::ActionsContextMenu); + QCOMPARE(actions->actionNames(), QStringList(QAccessibleActionInterface::showMenuAction())); + } + QTestAccessibility::clearEvents(); } void tst_QAccessibility::applicationTest() @@ -3701,7 +3722,7 @@ void tst_QAccessibility::dockWidgetTest() // 1 close button // 2 float button QVERIFY(accDock1); - QCOMPARE(accDock1->role(), QAccessible::Window); + QCOMPARE(accDock1->role(), QAccessible::Pane); QCOMPARE(accDock1->text(QAccessible::Name), dock1->windowTitle()); QCOMPARE(accDock1->childCount(), 3); @@ -3731,7 +3752,7 @@ void tst_QAccessibility::dockWidgetTest() QVERIFY(!dock1Float->state().invisible); QVERIFY(accDock2); - QCOMPARE(accDock2->role(), QAccessible::Window); + QCOMPARE(accDock2->role(), QAccessible::Pane); QCOMPARE(accDock2->text(QAccessible::Name), dock2->windowTitle()); QCOMPARE(accDock2->childCount(), 3); @@ -3779,7 +3800,7 @@ void tst_QAccessibility::dockWidgetTest() QAccessibleInterface *accDock3 = accMainWindow->child(4); QVERIFY(accDock3); - QCOMPARE(accDock3->role(), QAccessible::Window); + QCOMPARE(accDock3->role(), QAccessible::Pane); QCOMPARE(accDock3->text(QAccessible::Name), dock3->windowTitle()); QCOMPARE(accDock3->childCount(), 2); QAccessibleInterface *titleWidget = accDock3->child(1); @@ -3788,6 +3809,14 @@ void tst_QAccessibility::dockWidgetTest() QAccessibleInterface *dock3Widget = accDock3->child(0); QCOMPARE(dock3Widget->text(QAccessible::Name), pb3->text()); + // check role is changed to QAccessible::Window when dock window is undocked + // and a corresponding event is sent + QTestAccessibility::clearEvents(); + dock3->setFloating(true); + QCOMPARE(accDock3->role(), QAccessible::Window); + QAccessibleEvent roleChangedEvent(dock3, QAccessible::RoleChanged); + QVERIFY(QTestAccessibility::containsEvent(&roleChangedEvent)); + QTestAccessibility::clearEvents(); #endif // QT_CONFIG(dockwidget) } diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index e10dd6da885..8787cc54bf6 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> +#include <QtCore/qatomicscopedvaluerollback.h> #include <QtCore/QCoreApplication> #include <QtCore/QTimer> #ifdef QT_GUI_LIB @@ -15,6 +16,8 @@ #endif #include <QSet> #include <vector> + +using namespace std::chrono_literals; using namespace Qt::StringLiterals; /* XPM test data for QPixmap, QImage tests (use drag cursors as example) */ @@ -105,6 +108,9 @@ public: enum class MyClassEnum { MyClassEnumValue1, MyClassEnumValue2 }; Q_ENUM(MyClassEnum) +private: + void defaultTryTimeoutData(); + private slots: void compare_unregistered_enums(); void compare_registered_enums(); @@ -152,6 +158,10 @@ private slots: void tryVerify(); void tryVerify2(); void verifyExplicitOperatorBool(); + void defaultTryVerifyTimeout_data(); + void defaultTryVerifyTimeout(); + void defaultTryCompareTimeout_data(); + void defaultTryCompareTimeout(); }; enum MyUnregisteredEnum { MyUnregisteredEnumValue1, MyUnregisteredEnumValue2 }; @@ -841,5 +851,56 @@ void tst_Cmptest::verifyExplicitOperatorBool() QVERIFY(!val2); } +void tst_Cmptest::defaultTryTimeoutData() +{ + QTest::addColumn<std::chrono::milliseconds>("timeout"); + QTest::addRow("times-out") << 1ms; + QTest::addRow("ample-time") << 1000ms; +} + +void tst_Cmptest::defaultTryVerifyTimeout_data() +{ + defaultTryTimeoutData(); +} + +void tst_Cmptest::defaultTryVerifyTimeout() +{ + QFETCH(const std::chrono::milliseconds, timeout); + + // Check that the default is what expect. + QCOMPARE(QTest::defaultTryTimeout.load(std::memory_order_relaxed), 5s); + + { + DeferredFlag trueEventually; + const auto innerScope = QAtomicScopedValueRollback(QTest::defaultTryTimeout, timeout, std::memory_order_relaxed); + QEXPECT_FAIL("times-out", "The timeout (std::chrono::milliseconds) is deliberately too short", Continue); + QTRY_VERIFY(trueEventually); + } + + // innerScope has now been destroyed, so the timeout should be back to its default. + QCOMPARE(QTest::defaultTryTimeout.load(std::memory_order_relaxed), 5s); +} + +void tst_Cmptest::defaultTryCompareTimeout_data() +{ + defaultTryTimeoutData(); +} + +void tst_Cmptest::defaultTryCompareTimeout() +{ + QFETCH(const std::chrono::milliseconds, timeout); + + DeferredFlag trueAlready(true); + { + DeferredFlag trueEventually; + const auto innerScope = QAtomicScopedValueRollback(QTest::defaultTryTimeout, timeout, std::memory_order_relaxed); + QEXPECT_FAIL("times-out", "The timeout (std::chrono::milliseconds) is deliberately too short", Continue); + QTRY_COMPARE(trueEventually, trueAlready); + } + + // innerScope has now been destroyed, so the timeout should be back to its default. + QCOMPARE(QTest::defaultTryTimeout.load(std::memory_order_relaxed), 5s); +} + QTEST_MAIN(tst_Cmptest) #include "tst_cmptest.moc" diff --git a/tests/auto/testlib/selftests/expected_cmptest.junitxml b/tests/auto/testlib/selftests/expected_cmptest.junitxml index ce6a1c0c76e..232b86117af 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.junitxml +++ b/tests/auto/testlib/selftests/expected_cmptest.junitxml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<testsuite name="tst_Cmptest" timestamp="@TEST_START_TIME@" hostname="@HOSTNAME@" tests="74" failures="51" errors="0" skipped="0" time="@TEST_DURATION@"> +<testsuite name="tst_Cmptest" timestamp="@TEST_START_TIME@" hostname="@HOSTNAME@" tests="78" failures="51" errors="0" skipped="0" time="@TEST_DURATION@"> <properties> <property name="QTestVersion" value="@INSERT_QT_VERSION_HERE@"/> <property name="QtVersion" value="@INSERT_QT_VERSION_HERE@"/> @@ -321,5 +321,17 @@ <failure type="fail" message="'!c' returned FALSE. (Should time out and fail)"/> </testcase> <testcase name="verifyExplicitOperatorBool" classname="tst_Cmptest" time="@TEST_DURATION@"/> + <testcase name="defaultTryVerifyTimeout(times-out)" classname="tst_Cmptest" time="@TEST_DURATION@"> + <system-out> + <![CDATA[The timeout (std::chrono::milliseconds) is deliberately too short]]> + </system-out> + </testcase> + <testcase name="defaultTryVerifyTimeout(ample-time)" classname="tst_Cmptest" time="@TEST_DURATION@"/> + <testcase name="defaultTryCompareTimeout(times-out)" classname="tst_Cmptest" time="@TEST_DURATION@"> + <system-out> + <![CDATA[The timeout (std::chrono::milliseconds) is deliberately too short]]> + </system-out> + </testcase> + <testcase name="defaultTryCompareTimeout(ample-time)" classname="tst_Cmptest" time="@TEST_DURATION@"/> <testcase name="cleanupTestCase" classname="tst_Cmptest" time="@TEST_DURATION@"/> </testsuite> diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml index 9919dde3241..b31bc2aef7d 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.lightxml +++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml @@ -486,6 +486,32 @@ <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> </TestFunction> + <TestFunction name="defaultTryVerifyTimeout"> + <Incident type="xfail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + <Description><![CDATA[The timeout (std::chrono::milliseconds) is deliberately too short]]></Description> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[ample-time]]></DataTag> + </Incident> + <Duration msecs="0"/> + </TestFunction> + <TestFunction name="defaultTryCompareTimeout"> + <Incident type="xfail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + <Description><![CDATA[The timeout (std::chrono::milliseconds) is deliberately too short]]></Description> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[ample-time]]></DataTag> + </Incident> + <Duration msecs="0"/> + </TestFunction> <TestFunction name="cleanupTestCase"> <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> diff --git a/tests/auto/testlib/selftests/expected_cmptest.tap b/tests/auto/testlib/selftests/expected_cmptest.tap index 77118713717..180567f2112 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.tap +++ b/tests/auto/testlib/selftests/expected_cmptest.tap @@ -719,8 +719,30 @@ not ok 72 - tryVerify2() line: 0 ... ok 73 - verifyExplicitOperatorBool() -ok 74 - cleanupTestCase() -1..74 -# tests 74 -# pass 23 +not ok 74 - defaultTryVerifyTimeout(times-out) # TODO The timeout (std::chrono::milliseconds) is deliberately too short + --- + extensions: + messages: + - severity: xfail + message: The timeout (std::chrono::milliseconds) is deliberately too short + at: tst_Cmptest::defaultTryVerifyTimeout() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0) + file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp + line: 0 + ... +ok 75 - defaultTryVerifyTimeout(ample-time) +not ok 76 - defaultTryCompareTimeout(times-out) # TODO The timeout (std::chrono::milliseconds) is deliberately too short + --- + extensions: + messages: + - severity: xfail + message: The timeout (std::chrono::milliseconds) is deliberately too short + at: tst_Cmptest::defaultTryCompareTimeout() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0) + file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp + line: 0 + ... +ok 77 - defaultTryCompareTimeout(ample-time) +ok 78 - cleanupTestCase() +1..78 +# tests 78 +# pass 27 # fail 51 diff --git a/tests/auto/testlib/selftests/expected_cmptest.teamcity b/tests/auto/testlib/selftests/expected_cmptest.teamcity index c48262e0376..f88e44f3ee2 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.teamcity +++ b/tests/auto/testlib/selftests/expected_cmptest.teamcity @@ -216,6 +216,16 @@ ##teamcity[testFinished name='tryVerify2()' flowId='tst_Cmptest'] ##teamcity[testStarted name='verifyExplicitOperatorBool()' flowId='tst_Cmptest'] ##teamcity[testFinished name='verifyExplicitOperatorBool()' flowId='tst_Cmptest'] +##teamcity[testStarted name='defaultTryVerifyTimeout(times-out)' flowId='tst_Cmptest'] +##teamcity[testStdOut name='defaultTryVerifyTimeout(times-out)' out='XFAIL |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]: The timeout (std::chrono::milliseconds) is deliberately too short' flowId='tst_Cmptest'] +##teamcity[testFinished name='defaultTryVerifyTimeout(times-out)' flowId='tst_Cmptest'] +##teamcity[testStarted name='defaultTryVerifyTimeout(ample-time)' flowId='tst_Cmptest'] +##teamcity[testFinished name='defaultTryVerifyTimeout(ample-time)' flowId='tst_Cmptest'] +##teamcity[testStarted name='defaultTryCompareTimeout(times-out)' flowId='tst_Cmptest'] +##teamcity[testStdOut name='defaultTryCompareTimeout(times-out)' out='XFAIL |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]: The timeout (std::chrono::milliseconds) is deliberately too short' flowId='tst_Cmptest'] +##teamcity[testFinished name='defaultTryCompareTimeout(times-out)' flowId='tst_Cmptest'] +##teamcity[testStarted name='defaultTryCompareTimeout(ample-time)' flowId='tst_Cmptest'] +##teamcity[testFinished name='defaultTryCompareTimeout(ample-time)' flowId='tst_Cmptest'] ##teamcity[testStarted name='cleanupTestCase()' flowId='tst_Cmptest'] ##teamcity[testFinished name='cleanupTestCase()' flowId='tst_Cmptest'] ##teamcity[testSuiteFinished name='tst_Cmptest' flowId='tst_Cmptest'] diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt index efb305654f4..4c4b340a5ca 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.txt +++ b/tests/auto/testlib/selftests/expected_cmptest.txt @@ -252,6 +252,14 @@ FAIL! : tst_Cmptest::tryVerify() '!c' returned FALSE. () FAIL! : tst_Cmptest::tryVerify2() '!c' returned FALSE. (Should time out and fail) Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] PASS : tst_Cmptest::verifyExplicitOperatorBool() +XFAIL : tst_Cmptest::defaultTryVerifyTimeout(times-out) The timeout (std::chrono::milliseconds) is deliberately too short + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +PASS : tst_Cmptest::defaultTryVerifyTimeout(times-out) +PASS : tst_Cmptest::defaultTryVerifyTimeout(ample-time) +XFAIL : tst_Cmptest::defaultTryCompareTimeout(times-out) The timeout (std::chrono::milliseconds) is deliberately too short + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +PASS : tst_Cmptest::defaultTryCompareTimeout(times-out) +PASS : tst_Cmptest::defaultTryCompareTimeout(ample-time) PASS : tst_Cmptest::cleanupTestCase() -Totals: 23 passed, 51 failed, 0 skipped, 0 blacklisted, 0ms +Totals: 27 passed, 51 failed, 0 skipped, 0 blacklisted, 0ms ********* Finished testing of tst_Cmptest ********* diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml index f6ed03b0e9f..5ec93c5ce7e 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.xml +++ b/tests/auto/testlib/selftests/expected_cmptest.xml @@ -488,6 +488,32 @@ <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> </TestFunction> + <TestFunction name="defaultTryVerifyTimeout"> + <Incident type="xfail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + <Description><![CDATA[The timeout (std::chrono::milliseconds) is deliberately too short]]></Description> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[ample-time]]></DataTag> + </Incident> + <Duration msecs="0"/> + </TestFunction> + <TestFunction name="defaultTryCompareTimeout"> + <Incident type="xfail" file="qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + <Description><![CDATA[The timeout (std::chrono::milliseconds) is deliberately too short]]></Description> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[times-out]]></DataTag> + </Incident> + <Incident type="pass" file="" line="0"> + <DataTag><![CDATA[ample-time]]></DataTag> + </Incident> + <Duration msecs="0"/> + </TestFunction> <TestFunction name="cleanupTestCase"> <Incident type="pass" file="" line="0" /> <Duration msecs="0"/> diff --git a/tests/manual/wasm/eventloop/suspendresumecontrol_auto/main.cpp b/tests/manual/wasm/eventloop/suspendresumecontrol_auto/main.cpp index 59f1f00cc59..1fd6e0a0c4f 100644 --- a/tests/manual/wasm/eventloop/suspendresumecontrol_auto/main.cpp +++ b/tests/manual/wasm/eventloop/suspendresumecontrol_auto/main.cpp @@ -7,7 +7,7 @@ using namespace emscripten; -const int timerTimeout = 10; +const std::chrono::milliseconds timerTimeout{10}; // Test QWasmSuspendResumeControl suspend/resume and event processing, // via QWasmTimer native timer events. |