diff options
Diffstat (limited to 'tests/auto/dbus/qdbusmarshall')
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/CMakeLists.txt | 15 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/common.h | 138 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qdbusmarshall.pro | 9 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qdbusmarshall/.prev_CMakeLists.txt | 29 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt | 15 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qdbusmarshall/qdbusmarshall.pro | 13 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp | 39 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/qpong/qpong.pro | 5 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp | 207 |
10 files changed, 216 insertions, 261 deletions
diff --git a/tests/auto/dbus/qdbusmarshall/CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/CMakeLists.txt index aabeae0f4a..db24390069 100644 --- a/tests/auto/dbus/qdbusmarshall/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmarshall/CMakeLists.txt @@ -1,4 +1,15 @@ -# Generated from qdbusmarshall.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -add_subdirectory(qpong) +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(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 44346cd6f2..9a7c1e1553 100644 --- a/tests/auto/dbus/qdbusmarshall/common.h +++ b/tests/auto/dbus/qdbusmarshall/common.h @@ -1,32 +1,17 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <qmath.h> // qIsNan -#include <qvariant.h> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtGlobal> +#include <QMap> +#include <QString> +#include <QVariant> +#include <QDateTime> +#include <QLine> +#include <QDBusObjectPath> +#include <QDBusSignature> +#include <QDBusUnixFileDescriptor> +#include <QDBusArgument> +#include <QDBusMetaType> #ifdef Q_OS_UNIX # include <private/qcore_unix_p.h> @@ -167,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> >(); @@ -203,7 +190,11 @@ inline QDBusIntrospection::Argument arg(const char* type, const char *name = 0) template<typename T> inline QMap<QString, T>& operator<<(QMap<QString, T>& map, const T& m) -{ map.insertMulti(m.name, m); return map; } +{ map.insert(m.name, m); return map; } + +template<typename T> +inline QMultiMap<QString, T>& operator<<(QMultiMap<QString, T>& map, const T& m) +{ map.insert(m.name, m); return map; } inline const char* mapName(const MethodMap&) { return "MethodMap"; } @@ -217,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; @@ -234,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; @@ -258,16 +252,16 @@ 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; } -template<typename T> -char* printableMap(const QMap<QString, T>& map) +template<typename Map> +char* printableMap(const Map& map) { QString contents = "\n"; - typename QMap<QString, T>::const_iterator it = map.begin(); + auto it = map.begin(); for ( ; it != map.end(); ++it) { if (it.key() != it.value().name) contents += it.value().name + ":"; @@ -345,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(); @@ -360,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(); @@ -382,13 +376,13 @@ inline bool compare(const QDBusArgument &arg, const QVariant &v2, T * = 0) bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) { - if (arg.currentSignature() != QDBusMetaType::typeToSignature(v2.userType())) + if (arg.currentSignature() != QDBusMetaType::typeToSignature(v2.metaType())) return false; // 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); @@ -396,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(); @@ -479,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); @@ -517,8 +513,8 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) } qWarning() << "Unexpected QVariant type" << v2.userType() - << QByteArray(QDBusMetaType::typeToSignature(v2.userType())) - << QMetaType::typeName(v2.userType()); + << QByteArray(QDBusMetaType::typeToSignature(v2.metaType())) + << v2.metaType().name(); return false; } @@ -527,7 +523,7 @@ template<> bool compare(const QVariant &v1, const QVariant &v2) // v1 is the one that came from the network // v2 is the one that we sent - if (v1.userType() == qMetaTypeId<QDBusArgument>()) + if (v1.metaType() == QMetaType::fromType<QDBusArgument>()) // this argument has been left un-demarshalled return compareToArgument(qvariant_cast<QDBusArgument>(v1), v2); @@ -535,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) @@ -649,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.pro b/tests/auto/dbus/qdbusmarshall/qdbusmarshall.pro deleted file mode 100644 index 033602d4e4..0000000000 --- a/tests/auto/dbus/qdbusmarshall/qdbusmarshall.pro +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusmarshall -TEMPLATE = subdirs -qdbusmarshall.depends = qpong -SUBDIRS = qpong qdbusmarshall - -QT = core-private testlib - -requires(qtConfig(private_tests)) diff --git a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/qdbusmarshall/.prev_CMakeLists.txt deleted file mode 100644 index fc5f59990f..0000000000 --- a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/.prev_CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Generated from qdbusmarshall.pro. - -##################################################################### -## tst_qdbusmarshall Test: -##################################################################### - -add_qt_test(tst_qdbusmarshall - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" - SOURCES - ../tst_qdbusmarshall.cpp - PUBLIC_LIBRARIES - Qt::CorePrivate - Qt::DBusPrivate -) - -## Scopes: -##################################################################### - -extend_target(tst_qdbusmarshall CONDITION QT_FEATURE_dbus_linked - DEFINES - QT_LINKED_LIBDBUS - PUBLIC_LIBRARIES - dbus-1 -) - -extend_target(tst_qdbusmarshall CONDITION NOT QT_FEATURE_dbus_linked - SOURCES - ../../../../../src/dbus/qdbus_symbols.cpp -) diff --git a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt index bd615ab900..daad23cdf5 100644 --- a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmarshall/qdbusmarshall/CMakeLists.txt @@ -1,14 +1,15 @@ -# Generated from qdbusmarshall.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusmarshall Test: ##################################################################### -add_qt_test(tst_qdbusmarshall +qt_internal_add_test(tst_qdbusmarshall OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES ../tst_qdbusmarshall.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::DBusPrivate ) @@ -16,18 +17,16 @@ add_qt_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 -extend_target(tst_qdbusmarshall CONDITION QT_FEATURE_dbus_linked +qt_internal_extend_target(tst_qdbusmarshall CONDITION QT_FEATURE_dbus_linked DEFINES QT_LINKED_LIBDBUS - PUBLIC_LIBRARIES + LIBRARIES dbus-1 ) -extend_target(tst_qdbusmarshall CONDITION NOT QT_FEATURE_dbus_linked +qt_internal_extend_target(tst_qdbusmarshall CONDITION NOT QT_FEATURE_dbus_linked SOURCES ../../../../../src/dbus/qdbus_symbols.cpp ) diff --git a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/qdbusmarshall.pro b/tests/auto/dbus/qdbusmarshall/qdbusmarshall/qdbusmarshall.pro deleted file mode 100644 index 031cc252c8..0000000000 --- a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/qdbusmarshall.pro +++ /dev/null @@ -1,13 +0,0 @@ -CONFIG += testcase -SOURCES += ../tst_qdbusmarshall.cpp -TARGET = ../tst_qdbusmarshall -DESTDIR = ./ - -QT = core-private dbus-private testlib - -qtConfig(dbus-linked) { - DEFINES += QT_LINKED_LIBDBUS - QMAKE_USE += dbus -} else { - SOURCES += ../../../../../src/dbus/qdbus_symbols.cpp -} diff --git a/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt b/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt index e53c11aabe..8cf4dc32cc 100644 --- a/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmarshall/qpong/CMakeLists.txt @@ -1,13 +1,14 @@ -# Generated from qpong.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qpong Binary: ##################################################################### -add_qt_executable(qpong +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 cfcd51da7d..3507ecb534 100644 --- a/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp +++ b/tests/auto/dbus/qdbusmarshall/qpong/qpong.cpp @@ -1,32 +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$ -** -****************************************************************************/ -#include <QtCore/QtCore> -#include <QtDBus/QtDBus> +// 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"; @@ -55,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/qpong/qpong.pro b/tests/auto/dbus/qdbusmarshall/qpong/qpong.pro deleted file mode 100644 index 97a5e7e19d..0000000000 --- a/tests/auto/dbus/qdbusmarshall/qpong/qpong.pro +++ /dev/null @@ -1,5 +0,0 @@ -SOURCES = qpong.cpp -TARGET = qpong -DESTDIR = ./ -QT = core dbus -CONFIG += cmdline diff --git a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp index 6b4ddeaba5..e7a8273115 100644 --- a/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp +++ b/tests/auto/dbus/qdbusmarshall/tst_qdbusmarshall.cpp @@ -1,34 +1,10 @@ -/**************************************************************************** -** -** 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 <QtTest/QtTest> -#include <QtDBus/QtDBus> +#include <QTest> +#include <QTestEventLoop> #include "common.h" #include <limits> @@ -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]}]"; @@ -640,92 +627,112 @@ void tst_QDBusMarshall::sendArgument_data() QTest::addColumn<QVariant>("value"); QTest::addColumn<QString>("sig"); QTest::addColumn<int>("classification"); + QTest::addColumn<QVariant>("unwrappedValue"); QDBusArgument(); QDBusArgument arg; arg = QDBusArgument(); arg << true; - QTest::newRow("bool") << QVariant::fromValue(arg) << "b" << int(QDBusArgument::BasicType);; + QTest::newRow("bool") << QVariant::fromValue(arg) << "b" << int(QDBusArgument::BasicType) + << QVariant::fromValue(true); arg = QDBusArgument(); arg << false; - QTest::newRow("bool2") << QVariant::fromValue(arg) << "b" << int(QDBusArgument::BasicType); + QTest::newRow("bool2") << QVariant::fromValue(arg) << "b" << int(QDBusArgument::BasicType) + << QVariant::fromValue(false); arg = QDBusArgument(); arg << uchar(1); - QTest::newRow("byte") << QVariant::fromValue(arg) << "y" << int(QDBusArgument::BasicType); + QTest::newRow("byte") << QVariant::fromValue(arg) << "y" << int(QDBusArgument::BasicType) + << QVariant::fromValue(uchar(1)); arg = QDBusArgument(); arg << short(2); - QTest::newRow("int16") << QVariant::fromValue(arg) << "n" << int(QDBusArgument::BasicType); + QTest::newRow("int16") << QVariant::fromValue(arg) << "n" << int(QDBusArgument::BasicType) + << QVariant::fromValue(short(2)); arg = QDBusArgument(); arg << ushort(3); - QTest::newRow("uint16") << QVariant::fromValue(arg) << "q" << int(QDBusArgument::BasicType); + QTest::newRow("uint16") << QVariant::fromValue(arg) << "q" << int(QDBusArgument::BasicType) + << QVariant::fromValue(ushort(3)); arg = QDBusArgument(); arg << 1; - QTest::newRow("int32") << QVariant::fromValue(arg) << "i" << int(QDBusArgument::BasicType); + QTest::newRow("int32") << QVariant::fromValue(arg) << "i" << int(QDBusArgument::BasicType) + << QVariant::fromValue(1); arg = QDBusArgument(); arg << 2U; - QTest::newRow("uint32") << QVariant::fromValue(arg) << "u" << int(QDBusArgument::BasicType); + QTest::newRow("uint32") << QVariant::fromValue(arg) << "u" << int(QDBusArgument::BasicType) + << QVariant::fromValue(2U); arg = QDBusArgument(); arg << Q_INT64_C(3); - QTest::newRow("int64") << QVariant::fromValue(arg) << "x" << int(QDBusArgument::BasicType); + QTest::newRow("int64") << QVariant::fromValue(arg) << "x" << int(QDBusArgument::BasicType) + << QVariant::fromValue(Q_INT64_C(3)); arg = QDBusArgument(); arg << Q_UINT64_C(4); - QTest::newRow("uint64") << QVariant::fromValue(arg) << "t" << int(QDBusArgument::BasicType); + QTest::newRow("uint64") << QVariant::fromValue(arg) << "t" << int(QDBusArgument::BasicType) + << QVariant::fromValue(Q_UINT64_C(4)); arg = QDBusArgument(); arg << 42.5; - QTest::newRow("double") << QVariant::fromValue(arg) << "d" << int(QDBusArgument::BasicType); + QTest::newRow("double") << QVariant::fromValue(arg) << "d" << int(QDBusArgument::BasicType) + << QVariant::fromValue(42.5); arg = QDBusArgument(); arg << QLatin1String("ping"); - QTest::newRow("string") << QVariant::fromValue(arg) << "s" << int(QDBusArgument::BasicType); + QTest::newRow("string") << QVariant::fromValue(arg) << "s" << int(QDBusArgument::BasicType) + << QVariant::fromValue(QString("ping")); arg = QDBusArgument(); arg << QDBusObjectPath("/org/kde"); - QTest::newRow("objectpath") << QVariant::fromValue(arg) << "o" << int(QDBusArgument::BasicType); + QTest::newRow("objectpath") << QVariant::fromValue(arg) << "o" << int(QDBusArgument::BasicType) + << QVariant::fromValue(QDBusObjectPath("/org/kde")); arg = QDBusArgument(); arg << QDBusSignature("g"); - QTest::newRow("signature") << QVariant::fromValue(arg) << "g" << int(QDBusArgument::BasicType); + QTest::newRow("signature") << QVariant::fromValue(arg) << "g" << int(QDBusArgument::BasicType) + << QVariant::fromValue(QDBusSignature("g")); arg = QDBusArgument(); arg << QLatin1String(""); - QTest::newRow("emptystring") << QVariant::fromValue(arg) << "s" << int(QDBusArgument::BasicType); + QTest::newRow("emptystring") << QVariant::fromValue(arg) << "s" << int(QDBusArgument::BasicType) + << QVariant::fromValue(QString("")); arg = QDBusArgument(); arg << QString(); - QTest::newRow("nullstring") << QVariant::fromValue(arg) << "s" << int(QDBusArgument::BasicType); + QTest::newRow("nullstring") << QVariant::fromValue(arg) << "s" << int(QDBusArgument::BasicType) + << QVariant::fromValue(QString()); if (fileDescriptorPassing) { arg = QDBusArgument(); arg << QDBusUnixFileDescriptor(fileDescriptorForTest()); - QTest::newRow("filedescriptor") << QVariant::fromValue(arg) << "h" << int(QDBusArgument::BasicType); + QTest::newRow("filedescriptor") << QVariant::fromValue(arg) << "h" << int(QDBusArgument::BasicType) + << QVariant::fromValue(QDBusUnixFileDescriptor(fileDescriptorForTest())); } arg = QDBusArgument(); arg << QDBusVariant(1); - QTest::newRow("variant") << QVariant::fromValue(arg) << "v" << int(QDBusArgument::VariantType); + QTest::newRow("variant") << QVariant::fromValue(arg) << "v" << int(QDBusArgument::VariantType) + << QVariant::fromValue(QDBusVariant(1)); arg = QDBusArgument(); arg << QDBusVariant(QVariant::fromValue(QDBusVariant(1))); - QTest::newRow("variant-variant") << QVariant::fromValue(arg) << "v" << int(QDBusArgument::VariantType); + QTest::newRow("variant-variant") << QVariant::fromValue(arg) << "v" << int(QDBusArgument::VariantType) + << 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); + 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(); @@ -733,13 +740,15 @@ void tst_QDBusMarshall::sendArgument_data() arg << 3 << 4U; arg.endMapEntry(); arg.endMap(); - QTest::newRow("map") << QVariant::fromValue(arg) << "a{iu}" << int(QDBusArgument::MapType); + QTest::newRow("map") << QVariant::fromValue(arg) << "a{iu}" << int(QDBusArgument::MapType) + << QVariant::fromValue(arg); arg = QDBusArgument(); arg.beginStructure(); arg << 1 << 2U << short(-3) << ushort(4) << 5.0 << false; arg.endStructure(); - QTest::newRow("structure") << QVariant::fromValue(arg) << "(iunqdb)" << int(QDBusArgument::StructureType); + QTest::newRow("structure") << QVariant::fromValue(arg) << "(iunqdb)" << int(QDBusArgument::StructureType) + << QVariant::fromValue(arg); } void tst_QDBusMarshall::sendBasic() @@ -760,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); @@ -784,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))); } @@ -819,6 +828,7 @@ void tst_QDBusMarshall::sendArgument() { QFETCH(QVariant, value); QFETCH(QString, sig); + QFETCH(QVariant, unwrappedValue); QDBusConnection con = QDBusConnection::sessionBus(); @@ -861,8 +871,18 @@ void tst_QDBusMarshall::sendArgument() QVERIFY(arg.atEnd()); QCOMPARE(arg.currentType(), QDBusArgument::UnknownType); - if (value.type() != QVariant::UserType) - QCOMPARE(extracted, value); + + QEXPECT_FAIL("variant-variant", "Needs more QVariant unwrapping", Continue); + if (extracted.metaType() == QMetaType::fromType<QDBusUnixFileDescriptor>()) { + auto fd1 = extracted.value<QDBusUnixFileDescriptor>(); + auto fd2 = unwrappedValue.value<QDBusUnixFileDescriptor>(); + QVERIFY(compare(fd1, fd2)); + } else if (extracted.metaType() != QMetaType::fromType<QDBusArgument>()) { + QCOMPARE(extracted, unwrappedValue); + } else { + QEXPECT_FAIL("", "Comparison logic needs to be fixed", Continue); + QVERIFY(compare(extracted, value)); + } } void tst_QDBusMarshall::sendSignalErrors() @@ -939,22 +959,22 @@ 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: Variant containing QVariant::Invalid passed in arguments" + << "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: Variant containing QVariant::Invalid passed in arguments" + << "Marshalling failed: Invalid QVariant passed in arguments" << "QDBusMarshaller: cannot add a null QDBusVariant"; QTest::newRow("builtin-unregistered") << serviceName << objectPath << interfaceName << "ping" << (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>(); @@ -962,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" @@ -1059,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; } @@ -1074,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); @@ -1110,8 +1130,9 @@ void tst_QDBusMarshall::receiveUnknownType() QSKIP("Your session bus does not allow sending Unix file descriptors"); // make sure this QDBusConnection won't handle Unix file descriptors - QDBusConnection::ConnectionCapabilities &capabRef = QDBusConnectionPrivate::d(con)->capabilities; - SetResetValue<QDBusConnection::ConnectionCapabilities> resetter(capabRef, capabRef & ~QDBusConnection::UnixFileDescriptorPassing); + QAtomicInt &capabRef = QDBusConnectionPrivate::d(con)->capabilities; + 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 @@ -1136,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 @@ -1196,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); @@ -1271,7 +1293,7 @@ void tst_QDBusMarshall::demarshallPrimitives() QCOMPARE(receiveArg.currentSignature(), sig); const QVariant receiveValue = demarshallPrimitiveAs(typeIndex, receiveArg); - if (receiveValue.type() == value.type()) { + if (receiveValue.metaType() == value.metaType()) { // Value type is the same, compare the values QCOMPARE(receiveValue, value); QVERIFY(receiveArg.atEnd()); @@ -1293,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 |