diff options
Diffstat (limited to 'tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp')
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp | 117 |
1 files changed, 53 insertions, 64 deletions
diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp index c6928ca28d..e7a8273115 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -1,31 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + #include <QtCore/QtCore> #include <QTest> #include <QTestEventLoop> @@ -437,7 +413,7 @@ void tst_QDBusMarshall::sendArrayOfArrays_data() QTest::newRow("emptyvariantlist") << QVariant::fromValue(variants) << "aav" << "[Argument: aav {}]"; variants << QVariantList(); - QTest::newRow("emptyvariantlist") << QVariant::fromValue(variants) << "aav" + QTest::newRow("variantlist-empty-variantlist-element") << QVariant::fromValue(variants) << "aav" << "[Argument: aav {[Argument: av {}]}]"; variants << (QVariantList() << QString("Hello") << QByteArray("World")) << (QVariantList() << 42 << -43.0 << 44U << Q_INT64_C(-45)) @@ -500,6 +476,17 @@ void tst_QDBusMarshall::sendMaps_data() QTest::newRow("gs-map") << QVariant::fromValue(gsmap) << "a{gs}" << "[Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]"; + QMap<QString, std::pair<int, int>> siimap; + QTest::newRow("empty-sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}" + << "[Argument: a{s(ii)} {}]"; + siimap["0,0"] = { 0, 0 }; + siimap["1,-1"] = { 1, -1 }; + QTest::newRow("sii-map") << QVariant::fromValue(siimap) << "a{s(ii)}" + << "[Argument: a{s(ii)} {" + "\"0,0\" = [Argument: (ii) 0, 0], " + "\"1,-1\" = [Argument: (ii) 1, -1]" + "}]"; + if (fileDescriptorPassing) { svmap["zzfiledescriptor"] = QVariant::fromValue(QDBusUnixFileDescriptor(fileDescriptorForTest())); QTest::newRow("sv-map1-fd") << QVariant::fromValue(svmap) << "a{sv}" @@ -594,8 +581,8 @@ void tst_QDBusMarshall::sendComplex_data() QTest::newRow("empty-lldtmap") << QVariant::fromValue(lldtmap) << "a{x((iii)(iiii)i)}" << "[Argument: a{x((iii)(iiii)i)} {}]"; lldtmap[0] = QDateTime(); - lldtmap[1] = QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC); - lldtmap[1150629776] = QDateTime(QDate(2006, 6, 18), QTime(11, 22, 56), Qt::UTC); + lldtmap[1] = QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), QTimeZone::UTC); + lldtmap[1150629776] = QDateTime(QDate(2006, 6, 18), QTime(11, 22, 56), QTimeZone::UTC); QTest::newRow("lldtmap") << QVariant::fromValue(lldtmap) << "a{x((iii)(iiii)i)}" << "[Argument: a{x((iii)(iiii)i)} {0 = [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], 1 = [Argument: ((iii)(iiii)i) [Argument: (iii) 1970, 1, 1], [Argument: (iiii) 0, 0, 1, 0], 1], 1150629776 = [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 11, 22, 56, 0], 1]}]"; @@ -738,14 +725,14 @@ void tst_QDBusMarshall::sendArgument_data() << QVariant::fromValue(QVariant::fromValue(QDBusVariant(1))); arg = QDBusArgument(); - arg.beginArray(QVariant::Int); + arg.beginArray(QMetaType::Int); arg << 1 << 2 << 3 << -4; arg.endArray(); QTest::newRow("array-of-int") << QVariant::fromValue(arg) << "ai" << int(QDBusArgument::ArrayType) << QVariant::fromValue(arg); arg = QDBusArgument(); - arg.beginMap(QVariant::Int, QVariant::UInt); + arg.beginMap(QMetaType::Int, QMetaType::UInt); arg.beginMapEntry(); arg << 1 << 2U; arg.endMapEntry(); @@ -782,9 +769,9 @@ void tst_QDBusMarshall::sendBasic() qPrintable(reply.errorName() + ": " + reply.errorMessage())); //qDebug() << reply; - QCOMPARE(reply.arguments().count(), msg.arguments().count()); + QCOMPARE(reply.arguments().size(), msg.arguments().size()); QTEST(reply.signature(), "sig"); - for (int i = 0; i < reply.arguments().count(); ++i) { + for (int i = 0; i < reply.arguments().size(); ++i) { QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); //printf("\n! %s\n* %s\n", qPrintable(qDBusArgumentToString(reply.arguments().at(i))), qPrintable(stringResult)); QCOMPARE(QDBusUtil::argumentToString(reply.arguments().at(i)), stringResult); @@ -806,9 +793,9 @@ void tst_QDBusMarshall::sendVariant() QDBusMessage reply = con.call(msg); // qDebug() << reply; - QCOMPARE(reply.arguments().count(), msg.arguments().count()); + QCOMPARE(reply.arguments().size(), msg.arguments().size()); QCOMPARE(reply.signature(), QString("v")); - for (int i = 0; i < reply.arguments().count(); ++i) + for (int i = 0; i < reply.arguments().size(); ++i) QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); } @@ -972,12 +959,12 @@ void tst_QDBusMarshall::sendCallErrors_data() << "org.qtproject.QtDBus.Error.InvalidMember" << "Invalid method name: this isn't valid" << ""; - QTest::newRow("invalid-variant1") << serviceName << objectPath << interfaceName << "ping" + QTest::newRow("invalid-variant") << serviceName << objectPath << interfaceName << "ping" << (QVariantList() << QVariant()) << "org.freedesktop.DBus.Error.Failed" << "Marshalling failed: Invalid QVariant passed in arguments" << "QDBusMarshaller: cannot add an invalid QVariant"; - QTest::newRow("invalid-variant1") << serviceName << objectPath << interfaceName << "ping" + QTest::newRow("invalid-qdbusvariant") << serviceName << objectPath << interfaceName << "ping" << (QVariantList() << QVariant::fromValue(QDBusVariant())) << "org.freedesktop.DBus.Error.Failed" << "Marshalling failed: Invalid QVariant passed in arguments" @@ -987,7 +974,7 @@ void tst_QDBusMarshall::sendCallErrors_data() << (QVariantList() << QLocale::c()) << "org.freedesktop.DBus.Error.Failed" << "Marshalling failed: Unregistered type QLocale passed in arguments" - << "QDBusMarshaller: type `QLocale' (18) is not registered with D-BUS. Use qDBusRegisterMetaType to register it"; + << "QDBusMarshaller: type 'QLocale' (18) is not registered with D-Bus. Use qDBusRegisterMetaType to register it"; // this type is known to the meta type system, but not registered with D-Bus qRegisterMetaType<UnregisteredType>(); @@ -995,7 +982,7 @@ void tst_QDBusMarshall::sendCallErrors_data() << (QVariantList() << QVariant::fromValue(UnregisteredType())) << "org.freedesktop.DBus.Error.Failed" << "Marshalling failed: Unregistered type UnregisteredType passed in arguments" - << QString("QDBusMarshaller: type `UnregisteredType' (%1) is not registered with D-BUS. Use qDBusRegisterMetaType to register it") + << QString("QDBusMarshaller: type 'UnregisteredType' (%1) is not registered with D-Bus. Use qDBusRegisterMetaType to register it") .arg(qMetaTypeId<UnregisteredType>()); QTest::newRow("invalid-object-path-arg") << serviceName << objectPath << interfaceName << "ping" @@ -1092,12 +1079,12 @@ typedef QScopedPointer<DBusConnection, DisconnectRawDBus> ScopedDBusConnection; typedef QScopedPointer<DBusMessage, UnrefDBusMessage> ScopedDBusMessage; typedef QScopedPointer<DBusPendingCall, UnrefDBusPendingCall> ScopedDBusPendingCall; -template <typename T> struct SetResetValue +template <typename T, typename T2 = T> struct SetResetValue { - const T oldValue; + const T2 oldValue; T &value; public: - SetResetValue(T &v, T newValue) : oldValue(v), value(v) + SetResetValue(T &v, T2 newValue) : oldValue(v), value(v) { value = newValue; } @@ -1107,7 +1094,7 @@ public: } }; -// mostly the same as qdbusintegrator.cpp:connectionCapabilies +// mostly the same as qdbusintegrator.cpp:connectionCapabilities static bool canSendUnixFd(DBusConnection *connection) { typedef dbus_bool_t (*can_send_type_t)(DBusConnection *, int); @@ -1144,8 +1131,8 @@ void tst_QDBusMarshall::receiveUnknownType() // make sure this QDBusConnection won't handle Unix file descriptors QAtomicInt &capabRef = QDBusConnectionPrivate::d(con)->capabilities; - SetResetValue<QAtomicInt> resetter(capabRef, - capabRef & ~QDBusConnection::UnixFileDescriptorPassing); + SetResetValue<QAtomicInt, int> resetter(capabRef, + capabRef & ~QDBusConnection::UnixFileDescriptorPassing); if (qstrcmp(QTest::currentDataTag(), "in-call") == 0) { // create a call back to us containing a file descriptor @@ -1170,6 +1157,7 @@ void tst_QDBusMarshall::receiveUnknownType() // now spin our event loop. We don't catch this call, so let's get the reply QEventLoop loop; QTimer::singleShot(200, &loop, SLOT(quit())); + QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: couldn't handle call to theSlot, no slot matched"); loop.exec(); // now try to receive the reply @@ -1230,7 +1218,7 @@ void tst_QDBusMarshall::receiveUnknownType() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); QCOMPARE(spy.list.size(), 1); - QCOMPARE(spy.list.at(0).arguments().count(), 1); + QCOMPARE(spy.list.at(0).arguments().size(), 1); QFETCH(int, receivedTypeId); //qDebug() << spy.list.at(0).arguments().at(0).typeName(); QCOMPARE(spy.list.at(0).arguments().at(0).userType(), receivedTypeId); @@ -1327,22 +1315,23 @@ void tst_QDBusMarshall::demarshallStrings_data() // All primitive types demarshall to null string types typedef QPair<QVariant, char> ValSigPair; - const QList<ValSigPair> nullStringTypes - = QList<ValSigPair>() - << ValSigPair(QVariant::fromValue(QString()), 's') - << ValSigPair(QVariant::fromValue(QDBusObjectPath()), 'o') - << ValSigPair(QVariant::fromValue(QDBusSignature()), 'g'); - foreach (ValSigPair valSigPair, nullStringTypes) { - QTest::newRow("bool(false)") << QVariant(false) << valSigPair.second << valSigPair.first; - QTest::newRow("bool(true)") << QVariant(true) << valSigPair.second << valSigPair.first; - QTest::newRow("byte") << QVariant::fromValue(uchar(1)) << valSigPair.second << valSigPair.first; - QTest::newRow("int16") << QVariant::fromValue(short(2)) << valSigPair.second << valSigPair.first; - QTest::newRow("uint16") << QVariant::fromValue(ushort(3)) << valSigPair.second << valSigPair.first; - QTest::newRow("int") << QVariant(1) << valSigPair.second << valSigPair.first; - QTest::newRow("uint") << QVariant(2U) << valSigPair.second << valSigPair.first; - QTest::newRow("int64") << QVariant(Q_INT64_C(3)) << valSigPair.second << valSigPair.first; - QTest::newRow("uint64") << QVariant(Q_UINT64_C(4)) << valSigPair.second << valSigPair.first; - QTest::newRow("double") << QVariant(42.5) << valSigPair.second << valSigPair.first; + const QList<ValSigPair> nullStringTypes = { + ValSigPair(QVariant::fromValue(QString()), 's'), + ValSigPair(QVariant::fromValue(QDBusObjectPath()), 'o'), + ValSigPair(QVariant::fromValue(QDBusSignature()), 'g') + }; + for (const auto &[v, charSymbol] : nullStringTypes) { + const char *name = v.typeName(); + QTest::addRow("bool(false)-%s", name) << QVariant(false) << charSymbol << v; + QTest::addRow("bool(true)-%s", name) << QVariant(true) << charSymbol << v; + QTest::addRow("byte-%s", name) << QVariant::fromValue(uchar(1)) << charSymbol << v; + QTest::addRow("int16-%s", name) << QVariant::fromValue(short(2)) << charSymbol << v; + QTest::addRow("uint16-%s", name) << QVariant::fromValue(ushort(3)) << charSymbol << v; + QTest::addRow("int-%s", name) << QVariant(1) << charSymbol << v; + QTest::addRow("uint-%s", name) << QVariant(2U) << charSymbol << v; + QTest::addRow("int64-%s", name) << QVariant(Q_INT64_C(3)) << charSymbol << v; + QTest::addRow("uint64-%s", name) << QVariant(Q_UINT64_C(4)) << charSymbol << v; + QTest::addRow("double-%s", name) << QVariant(42.5) << charSymbol << v; } // String types should demarshall to each other. This is a regression test |