diff options
Diffstat (limited to 'tests/auto/dbus/qdbusmarshall')
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/CMakeLists.txt | 12 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/common.h | 104 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp | 33 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp | 117 |
6 files changed, 119 insertions, 161 deletions
diff --git a/tests/auto/dbus/qdbusmarshall/CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/CMakeLists.txt index 5d40035aee..db24390069 100644 --- a/tests/auto/dbus/qdbusmarshall/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmarshall/CMakeLists.txt @@ -1,7 +1,15 @@ -# Generated from qdbusmarshall.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusmarshall LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT QT_FEATURE_private_tests) return() endif() -add_subdirectory(qpong) add_subdirectory(qdbusmarshall) +add_subdirectory(qpong) +add_dependencies(tst_qdbusmarshall qpong) diff --git a/tests/auto/dbus/qdbusmarshall/common.h b/tests/auto/dbus/qdbusmarshall/common.h index 9bdc1ebe66..9a7c1e1553 100644 --- a/tests/auto/dbus/qdbusmarshall/common.h +++ b/tests/auto/dbus/qdbusmarshall/common.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGlobal> #include <QMap> @@ -177,7 +152,9 @@ void commonInit() qDBusRegisterMetaType<QMap<QDBusObjectPath, QString> >(); qDBusRegisterMetaType<QMap<qlonglong, QDateTime> >(); qDBusRegisterMetaType<QMap<QDBusSignature, QString> >(); + qDBusRegisterMetaType<QMap<QString, std::pair<int, int>>>(); + qDBusRegisterMetaType<std::pair<int, int>>(); qDBusRegisterMetaType<MyStruct>(); qDBusRegisterMetaType<MyVariantMapStruct>(); qDBusRegisterMetaType<QList<MyVariantMapStruct> >(); @@ -231,15 +208,17 @@ inline const char* mapName(const PropertyMap&) QString printable(const QDBusIntrospection::Method& m) { QString result = "method " + m.name + "("; - foreach (QDBusIntrospection::Argument arg, m.inputArgs) + for (QDBusIntrospection::Argument arg : m.inputArgs) { result += QString("in %1 %2, ") .arg(arg.type, arg.name); - foreach (QDBusIntrospection::Argument arg, m.outputArgs) + } + for (QDBusIntrospection::Argument arg : m.outputArgs) { result += QString("out %1 %2, ") .arg(arg.type, arg.name); + } AnnotationsMap::const_iterator it = m.annotations.begin(); for ( ; it != m.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); + result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value().value); result += ")"; return result; @@ -248,12 +227,13 @@ QString printable(const QDBusIntrospection::Method& m) QString printable(const QDBusIntrospection::Signal& s) { QString result = "signal " + s.name + "("; - foreach (QDBusIntrospection::Argument arg, s.outputArgs) + for (QDBusIntrospection::Argument arg : s.outputArgs) { result += QString("out %1 %2, ") .arg(arg.type, arg.name); + } AnnotationsMap::const_iterator it = s.annotations.begin(); for ( ; it != s.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); + result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value().value); result += ")"; return result; @@ -272,7 +252,7 @@ QString printable(const QDBusIntrospection::Property& p) AnnotationsMap::const_iterator it = p.annotations.begin(); for ( ; it != p.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); + result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value().value); return result; } @@ -359,7 +339,7 @@ bool compare(const QDBusVariant &s1, const QDBusVariant &s2) template<typename T> bool compare(const QList<T> &l1, const QList<T> &l2) { - if (l1.count() != l2.count()) + if (l1.size() != l2.size()) return false; typename QList<T>::ConstIterator it1 = l1.constBegin(); @@ -374,7 +354,7 @@ bool compare(const QList<T> &l1, const QList<T> &l2) template<typename Key, typename T> bool compare(const QMap<Key, T> &m1, const QMap<Key, T> &m2) { - if (m1.count() != m2.size()) + if (m1.size() != m2.size()) return false; typename QMap<Key, T>::ConstIterator i1 = m1.constBegin(); typename QMap<Key, T>::ConstIterator end = m1.constEnd(); @@ -402,7 +382,7 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) // try to demarshall the arg according to v2 switch (v2.userType()) { - case QVariant::Bool: + case QMetaType::Bool: return compare<bool>(arg, v2); case QMetaType::UChar: return compare<uchar>(arg, v2); @@ -410,45 +390,45 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) return compare<short>(arg, v2); case QMetaType::UShort: return compare<ushort>(arg, v2); - case QVariant::Int: + case QMetaType::Int: return compare<int>(arg, v2); - case QVariant::UInt: + case QMetaType::UInt: return compare<uint>(arg, v2); - case QVariant::LongLong: + case QMetaType::LongLong: return compare<qlonglong>(arg, v2); - case QVariant::ULongLong: + case QMetaType::ULongLong: return compare<qulonglong>(arg, v2); - case QVariant::Double: + case QMetaType::Double: return compare<double>(arg, v2); - case QVariant::String: + case QMetaType::QString: return compare<QString>(arg, v2); - case QVariant::ByteArray: + case QMetaType::QByteArray: return compare<QByteArray>(arg, v2); - case QVariant::List: + case QMetaType::QVariantList: return compare<QVariantList>(arg, v2); - case QVariant::Map: + case QMetaType::QVariantMap: return compare<QVariantMap>(arg, v2); - case QVariant::Point: + case QMetaType::QPoint: return compare<QPoint>(arg, v2); - case QVariant::PointF: + case QMetaType::QPointF: return compare<QPointF>(arg, v2); - case QVariant::Size: + case QMetaType::QSize: return compare<QSize>(arg, v2); - case QVariant::SizeF: + case QMetaType::QSizeF: return compare<QSizeF>(arg, v2); - case QVariant::Line: + case QMetaType::QLine: return compare<QLine>(arg, v2); - case QVariant::LineF: + case QMetaType::QLineF: return compare<QLineF>(arg, v2); - case QVariant::Rect: + case QMetaType::QRect: return compare<QRect>(arg, v2); - case QVariant::RectF: + case QMetaType::QRectF: return compare<QRectF>(arg, v2); - case QVariant::Date: + case QMetaType::QDate: return compare<QDate>(arg, v2); - case QVariant::Time: + case QMetaType::QTime: return compare<QTime>(arg, v2); - case QVariant::DateTime: + case QMetaType::QDateTime: return compare<QDateTime>(arg, v2); default: int id = v2.userType(); @@ -493,6 +473,8 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) return compare<QMap<qlonglong, QDateTime> >(arg, v2); else if (id == qMetaTypeId<QMap<QDBusSignature, QString> >()) return compare<QMap<QDBusSignature, QString> >(arg, v2); + else if (id == qMetaTypeId<QMap<QString, std::pair<int, int>>>()) + return compare<QMap<QString, std::pair<int, int>>>(arg, v2); else if (id == qMetaTypeId<QList<QByteArray> >()) return compare<QList<QByteArray> >(arg, v2); @@ -549,16 +531,16 @@ template<> bool compare(const QVariant &v1, const QVariant &v2) return false; int id = v1.userType(); - if (id == QVariant::List) + if (id == QMetaType::QVariantList) return compare(v1.toList(), v2.toList()); - else if (id == QVariant::Map) + else if (id == QMetaType::QVariantMap) return compare(v1.toMap(), v2.toMap()); - else if (id == QVariant::String) + else if (id == QMetaType::QString) return compare(v1.toString(), v2.toString()); - else if (id == QVariant::ByteArray) + else if (id == QMetaType::QByteArray) return compare(v1.toByteArray(), v2.toByteArray()); else if (id == QMetaType::UChar) @@ -663,7 +645,7 @@ template<> bool compare(const QVariant &v1, const QVariant &v2) else if (id == qMetaTypeId<MyStruct>()) // (is) return qvariant_cast<MyStruct>(v1) == qvariant_cast<MyStruct>(v2); - else if (id < int(QVariant::UserType)) // yes, v1.type() + else if (id < int(QMetaType::User)) // yes, v1.type() // QVariant can compare return v1 == v2; diff --git a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt index 2019292184..daad23cdf5 100644 --- a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qdbusmarshall.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusmarshall Test: @@ -8,7 +9,7 @@ qt_internal_add_test(tst_qdbusmarshall OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES ../tst_qdbusmarshall.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::DBusPrivate ) @@ -16,14 +17,12 @@ qt_internal_add_test(tst_qdbusmarshall ## Scopes: ##################################################################### -# special case begin # This test case interacts with dbus code directly via the private # headers. The include path is also not exposed via Qt:DBus. -# special case end qt_internal_extend_target(tst_qdbusmarshall CONDITION QT_FEATURE_dbus_linked DEFINES QT_LINKED_LIBDBUS - PUBLIC_LIBRARIES + LIBRARIES dbus-1 ) diff --git a/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt index 527d464b74..8cf4dc32cc 100644 --- a/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qpong.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qpong Binary: @@ -8,6 +9,6 @@ qt_internal_add_executable(qpong OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" SOURCES qpong.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp b/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp index 7333f5961d..3507ecb534 100644 --- a/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp +++ b/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp @@ -1,34 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QCoreApplication> #include <QDBusMessage> #include <QDBusConnection> +#include <QLoggingCategory> static const char serviceName[] = "org.qtproject.autotests.qpong"; static const char objectPath[] = "/org/qtproject/qpong"; @@ -57,6 +33,9 @@ int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); + // Silence many warnings from findSlot() about ping() not having the expected argument types + QLoggingCategory::setFilterRules("qt.dbus.integration=false"); + QDBusConnection con = QDBusConnection::sessionBus(); if (!con.isConnected()) exit(1); 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 |