diff options
Diffstat (limited to 'tests/auto/dbus')
104 files changed, 1314 insertions, 1769 deletions
diff --git a/tests/auto/dbus/CMakeLists.txt b/tests/auto/dbus/CMakeLists.txt index 1b5022454a..d67877a0b3 100644 --- a/tests/auto/dbus/CMakeLists.txt +++ b/tests/auto/dbus/CMakeLists.txt @@ -1,10 +1,12 @@ -# Generated from dbus.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qdbusconnection_delayed) add_subdirectory(qdbusconnection) add_subdirectory(qdbusconnection_no_app) add_subdirectory(qdbusconnection_no_bus) add_subdirectory(qdbusconnection_no_libdbus) +add_subdirectory(qdbusconnection_signalorder) add_subdirectory(qdbusconnection_spyhook) add_subdirectory(qdbuscontext) add_subdirectory(qdbuslocalcalls) diff --git a/tests/auto/dbus/dbus.pro b/tests/auto/dbus/dbus.pro deleted file mode 100644 index 6878c9341d..0000000000 --- a/tests/auto/dbus/dbus.pro +++ /dev/null @@ -1,39 +0,0 @@ -TEMPLATE=subdirs - -# Run this test first -SUBDIRS=\ - qdbusconnection_delayed - -SUBDIRS+=\ - qdbusabstractadaptor \ - qdbusabstractinterface \ - qdbusconnection \ - qdbusconnection_no_app \ - qdbusconnection_no_bus \ - qdbusconnection_no_libdbus \ - qdbusconnection_spyhook \ - qdbuscontext \ - qdbusinterface \ - qdbuslocalcalls \ - qdbusmarshall \ - qdbusmetaobject \ - qdbusmetatype \ - qdbuspendingcall \ - qdbuspendingreply \ - qdbusreply \ - qdbusservicewatcher \ - qdbustype \ - qdbusthreading \ - qdbusxmlparser - -!qtConfig(private_tests): SUBDIRS -= \ - qdbusmarshall \ - -!qtConfig(process): SUBDIRS -= \ - qdbusabstractadaptor \ - qdbusabstractinterface \ - qdbusinterface \ - qdbusmarshall - -!qtHaveModule(xml): SUBDIRS -= \ - qdbusxmlparser diff --git a/tests/auto/dbus/qdbusabstractadaptor/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusabstractadaptor/.prev_CMakeLists.txt deleted file mode 100644 index 9a8132d115..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/.prev_CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Generated from qdbusabstractadaptor.pro. - -add_subdirectory(qmyserver) -add_subdirectory(qdbusabstractadaptor) diff --git a/tests/auto/dbus/qdbusabstractadaptor/BLACKLIST b/tests/auto/dbus/qdbusabstractadaptor/BLACKLIST deleted file mode 100644 index d3d970f4f4..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[overloadedSignalEmission] -linux diff --git a/tests/auto/dbus/qdbusabstractadaptor/CMakeLists.txt b/tests/auto/dbus/qdbusabstractadaptor/CMakeLists.txt index 0f6d732b09..01cc7613ff 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/CMakeLists.txt +++ b/tests/auto/dbus/qdbusabstractadaptor/CMakeLists.txt @@ -1,9 +1,15 @@ -# Generated from qdbusabstractadaptor.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_qdbusabstractadaptor LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(qmyserver) -# special case begin -qt_add_test(tst_qdbusabstractadaptor +qt_internal_add_test(tst_qdbusabstractadaptor SOURCES myobject.h tst_qdbusabstractadaptor.cpp @@ -11,4 +17,4 @@ qt_add_test(tst_qdbusabstractadaptor Qt::CorePrivate Qt::DBus ) -# special case end +add_dependencies(tst_qdbusabstractadaptor qmyserver) diff --git a/tests/auto/dbus/qdbusabstractadaptor/myobject.h b/tests/auto/dbus/qdbusabstractadaptor/myobject.h index fe3f6f3dd2..d6e332ac1c 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/myobject.h +++ b/tests/auto/dbus/qdbusabstractadaptor/myobject.h @@ -1,36 +1,14 @@ -/**************************************************************************** -** -** 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 #ifndef MYOBJECT_H #define MYOBJECT_H -#include <QtCore/QObject> -#include <QtDBus/QtDBus> +#include <QObject> +#include <QVariant> +#include <QUrl> +#include <QDBusMessage> +#include <QDBusAbstractAdaptor> extern const char *slotSpy; extern QString valueSpy; @@ -48,7 +26,7 @@ public slots: signature = msg.signature(); path = msg.path(); value.clear(); - if (msg.arguments().count()) + if (msg.arguments().size()) value = msg.arguments().at(0); } @@ -198,15 +176,15 @@ public: void emitSignal(const QString &, const QVariant &value) { - switch (value.type()) + switch (value.metaType().id()) { - case QVariant::Invalid: + case QMetaType::UnknownType: emit signal(); break; - case QVariant::Int: + case QMetaType::Int: emit signal(value.toInt()); break; - case QVariant::String: + case QMetaType::QString: emit signal(value.toString()); break; default: diff --git a/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor.pro b/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor.pro deleted file mode 100644 index 9b63dab068..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusabstractadaptor -QT = core core-private testlib -TEMPLATE = subdirs - -qdbusabstractadaptor.depends = qmyserver -SUBDIRS = qmyserver qdbusabstractadaptor diff --git a/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor/BLACKLIST b/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor/BLACKLIST deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor/BLACKLIST +++ /dev/null diff --git a/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor/qdbusabstractadaptor.pro b/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor/qdbusabstractadaptor.pro deleted file mode 100644 index c05a575acf..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/qdbusabstractadaptor/qdbusabstractadaptor.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -SOURCES += ../tst_qdbusabstractadaptor.cpp -HEADERS += ../myobject.h -TARGET = ../tst_qdbusabstractadaptor -DESTDIR = ./ - -QT = core core-private dbus testlib diff --git a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusabstractadaptor/qmyserver/.prev_CMakeLists.txt deleted file mode 100644 index 32af66f30c..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/.prev_CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Generated from qmyserver.pro. - -##################################################################### -## qmyserver Binary: -##################################################################### - -qt_add_executable(qmyserver - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - SOURCES - ../myobject.h - qmyserver.cpp - PUBLIC_LIBRARIES - Qt::DBus -) diff --git a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/CMakeLists.txt b/tests/auto/dbus/qdbusabstractadaptor/qmyserver/CMakeLists.txt index d2bdb4434d..4e33775bf1 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/CMakeLists.txt +++ b/tests/auto/dbus/qdbusabstractadaptor/qmyserver/CMakeLists.txt @@ -1,15 +1,16 @@ -# Generated from qmyserver.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qmyserver Binary: ##################################################################### -qt_add_executable(qmyserver +qt_internal_add_executable(qmyserver OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - NO_INSTALL # special case + NO_INSTALL SOURCES ../myobject.h qmyserver.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.cpp b/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.cpp index 1ea476e580..fb7b659d9f 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.cpp +++ b/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.cpp @@ -1,33 +1,13 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <QtCore/QtCore> -#include <QtDBus/QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QCoreApplication> +#include <QDBusServer> +#include <QDBusContext> +#include <QDBusConnection> +#include <QDBusVariant> +#include <QDBusServer> #include "../myobject.h" @@ -46,7 +26,7 @@ class MyServer : public QDBusServer, protected QDBusContext Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qmyserver") public: - MyServer(QObject* parent = 0) + MyServer(QObject* parent = nullptr) : QDBusServer(parent), m_conn("none"), obj(NULL) diff --git a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.pro b/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.pro deleted file mode 100644 index 8f2d261899..0000000000 --- a/tests/auto/dbus/qdbusabstractadaptor/qmyserver/qmyserver.pro +++ /dev/null @@ -1,6 +0,0 @@ -SOURCES = qmyserver.cpp -HEADERS = ../myobject.h -TARGET = qmyserver -DESTDIR = ./ -QT = core dbus -CONFIG -= app_bundle diff --git a/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp b/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp index 0f266200af..173e6e6765 100644 --- a/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp +++ b/tests/auto/dbus/qdbusabstractadaptor/tst_qdbusabstractadaptor.cpp @@ -1,37 +1,15 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <qcoreapplication.h> -#include <qdebug.h> - -#include <QtTest/QtTest> - -#include <QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QDebug> +#include <QCoreApplication> +#include <QProcess> +#include <QTimer> +#include <QDBusConnection> +#include <QDBusInterface> +#include <QDBusConnectionInterface> #include "../qdbusmarshall/common.h" #include "myobject.h" @@ -890,7 +868,7 @@ void tst_QDBusAbstractAdaptor::readProperties() properties.call(QDBus::BlockWithGui, "Get", "local." + name, propname); QVariant value = reply; - QCOMPARE(value.userType(), int(QVariant::String)); + QCOMPARE(value.userType(), int(QMetaType::QString)); QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); } } @@ -953,7 +931,7 @@ void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterface() continue; } - QCOMPARE(int(reply.value().type()), int(QVariant::String)); + QCOMPARE(reply.value().userType(), int(QMetaType::QString)); if (it.value().isValid()) QCOMPARE(reply.value().toString(), it.value().toString()); } @@ -979,7 +957,7 @@ void tst_QDBusAbstractAdaptor::readAllProperties() qPrintable(propname + " on " + name)); QVariant value = reply.value().value(propname); - QCOMPARE(value.userType(), int(QVariant::String)); + QCOMPARE(value.userType(), int(QMetaType::QString)); QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); } } @@ -1081,12 +1059,6 @@ void tst_QDBusAbstractAdaptor::methodCallsPeer_data() void tst_QDBusAbstractAdaptor::methodCallsPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); - if (QSysInfo::productType().compare("opensuse", Qt::CaseInsensitive) == 0 - && QSysInfo::productVersion() == QLatin1String("42.1") - && qgetenv("QTEST_ENVIRONMENT").split(' ').contains("ci")) { - QSKIP("This test is occasionally hanging in the CI"); - } QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1149,7 +1121,6 @@ void tst_QDBusAbstractAdaptor::methodCallsPeer() void tst_QDBusAbstractAdaptor::methodCallScriptablePeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1169,7 +1140,6 @@ void tst_QDBusAbstractAdaptor::signalEmissionsPeer_data() void tst_QDBusAbstractAdaptor::signalEmissionsPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QFETCH(QString, interface); QFETCH(QString, name); QFETCH(QVariant, parameter); @@ -1234,7 +1204,6 @@ void tst_QDBusAbstractAdaptor::signalEmissionsPeer() void tst_QDBusAbstractAdaptor::sameSignalDifferentPathsPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1263,7 +1232,6 @@ void tst_QDBusAbstractAdaptor::sameSignalDifferentPathsPeer() void tst_QDBusAbstractAdaptor::sameObjectDifferentPathsPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1286,8 +1254,7 @@ void tst_QDBusAbstractAdaptor::sameObjectDifferentPathsPeer() void tst_QDBusAbstractAdaptor::scriptableSignalOrNotPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); - QDBusConnection con("peer");; + QDBusConnection con("peer"); QVERIFY(con.isConnected()); { @@ -1358,7 +1325,6 @@ void tst_QDBusAbstractAdaptor::overloadedSignalEmissionPeer_data() void tst_QDBusAbstractAdaptor::overloadedSignalEmissionPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1410,7 +1376,6 @@ void tst_QDBusAbstractAdaptor::overloadedSignalEmissionPeer() void tst_QDBusAbstractAdaptor::readPropertiesPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1427,7 +1392,7 @@ void tst_QDBusAbstractAdaptor::readPropertiesPeer() properties.call(QDBus::BlockWithGui, "Get", "local." + name, propname); QVariant value = reply; - QCOMPARE(value.userType(), int(QVariant::String)); + QCOMPARE(value.userType(), int(QMetaType::QString)); QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); } } @@ -1435,7 +1400,6 @@ void tst_QDBusAbstractAdaptor::readPropertiesPeer() void tst_QDBusAbstractAdaptor::readPropertiesInvalidInterfacePeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1456,7 +1420,6 @@ void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterfacePeer_data() void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterfacePeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1479,7 +1442,7 @@ void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterfacePeer() continue; } - QCOMPARE(int(reply.value().type()), int(QVariant::String)); + QCOMPARE(int(reply.value().userType()), int(QMetaType::QString)); if (it.value().isValid()) QCOMPARE(reply.value().toString(), it.value().toString()); } @@ -1487,7 +1450,6 @@ void tst_QDBusAbstractAdaptor::readPropertiesEmptyInterfacePeer() void tst_QDBusAbstractAdaptor::readAllPropertiesPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1506,7 +1468,7 @@ void tst_QDBusAbstractAdaptor::readAllPropertiesPeer() qPrintable(propname + " on " + name)); QVariant value = reply.value().value(propname); - QCOMPARE(value.userType(), int(QVariant::String)); + QCOMPARE(value.userType(), int(QMetaType::QString)); QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); } } @@ -1514,7 +1476,6 @@ void tst_QDBusAbstractAdaptor::readAllPropertiesPeer() void tst_QDBusAbstractAdaptor::readAllPropertiesInvalidInterfacePeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1580,7 +1541,6 @@ void tst_QDBusAbstractAdaptor::readAllPropertiesEmptyInterfacePeer() void tst_QDBusAbstractAdaptor::writePropertiesPeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1862,10 +1822,9 @@ void tst_QDBusAbstractAdaptor::typeMatching() reply = iface.call(QDBus::BlockWithGui, "retrieve" + basename); QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); - const QVariant &retval = reply.arguments().at(0); - QVERIFY(compare(retval, value)); + QVERIFY(compare(reply.arguments().at(0), value)); } void tst_QDBusAbstractAdaptor::methodWithMoreThanOneReturnValue() @@ -1880,19 +1839,18 @@ void tst_QDBusAbstractAdaptor::methodWithMoreThanOneReturnValue() QDBusInterface remote(con.baseService(), "/", "local.Interface3", con); QDBusMessage reply = remote.call(QDBus::BlockWithGui, "methodStringString", testString); - QCOMPARE(reply.arguments().count(), 2); + QCOMPARE(reply.arguments().size(), 2); QDBusReply<int> intreply = reply; QVERIFY(intreply.isValid()); QCOMPARE(intreply.value(), 42); - QCOMPARE(reply.arguments().at(1).userType(), int(QVariant::String)); + QCOMPARE(reply.arguments().at(1).userType(), int(QMetaType::QString)); QCOMPARE(qdbus_cast<QString>(reply.arguments().at(1)), testString); } void tst_QDBusAbstractAdaptor::methodWithMoreThanOneReturnValuePeer() { - QSKIP("Test is currently too flaky (QTBUG-66223)"); QDBusConnection con("peer"); QVERIFY(con.isConnected()); @@ -1903,13 +1861,13 @@ void tst_QDBusAbstractAdaptor::methodWithMoreThanOneReturnValuePeer() QDBusInterface remote(QString(), "/", "local.Interface3", con); QDBusMessage reply = remote.call(QDBus::BlockWithGui, "methodStringString", testString); - QCOMPARE(reply.arguments().count(), 2); + QCOMPARE(reply.arguments().size(), 2); QDBusReply<int> intreply = reply; QVERIFY(intreply.isValid()); QCOMPARE(intreply.value(), 42); - QCOMPARE(reply.arguments().at(1).userType(), int(QVariant::String)); + QCOMPARE(reply.arguments().at(1).userType(), int(QMetaType::QString)); QCOMPARE(qdbus_cast<QString>(reply.arguments().at(1)), testString); } diff --git a/tests/auto/dbus/qdbusabstractinterface/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusabstractinterface/.prev_CMakeLists.txt deleted file mode 100644 index 111012aba9..0000000000 --- a/tests/auto/dbus/qdbusabstractinterface/.prev_CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Generated from qdbusabstractinterface.pro. - -add_subdirectory(qpinger) -add_subdirectory(qdbusabstractinterface) diff --git a/tests/auto/dbus/qdbusabstractinterface/CMakeLists.txt b/tests/auto/dbus/qdbusabstractinterface/CMakeLists.txt index ec49268777..4010ae5682 100644 --- a/tests/auto/dbus/qdbusabstractinterface/CMakeLists.txt +++ b/tests/auto/dbus/qdbusabstractinterface/CMakeLists.txt @@ -1,9 +1,13 @@ -# Generated from qdbusabstractinterface.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -add_subdirectory(qpinger) +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusabstractinterface LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() -# special case begin -qt_add_test(tst_qdbusabstractinterface +qt_internal_add_test(tst_qdbusabstractinterface SOURCES interface.cpp tst_qdbusabstractinterface.cpp @@ -12,7 +16,7 @@ qt_add_test(tst_qdbusabstractinterface Qt::DBus ) -qt_extend_target(tst_qdbusabstractinterface +qt_internal_extend_target(tst_qdbusabstractinterface DBUS_INTERFACE_SOURCES org.qtproject.QtDBus.Pinger.xml DBUS_INTERFACE_BASENAME @@ -21,4 +25,5 @@ qt_extend_target(tst_qdbusabstractinterface -i interface.h ) -# special case end +add_subdirectory(qpinger) +add_dependencies(tst_qdbusabstractinterface qpinger) diff --git a/tests/auto/dbus/qdbusabstractinterface/interface.cpp b/tests/auto/dbus/qdbusabstractinterface/interface.cpp index ef1ff74734..1226e5bb49 100644 --- a/tests/auto/dbus/qdbusabstractinterface/interface.cpp +++ b/tests/auto/dbus/qdbusabstractinterface/interface.cpp @@ -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 "interface.h" #include <QThread> @@ -33,16 +8,9 @@ Interface::Interface() { } -// Export the sleep function -// TODO QT5: remove this class, QThread::msleep is now public -class FriendlySleepyThread : public QThread { -public: - using QThread::msleep; -}; - int Interface::sleepMethod(int msec) { - FriendlySleepyThread::msleep(msec); + QThread::sleep(std::chrono::milliseconds{msec}); return 42; } diff --git a/tests/auto/dbus/qdbusabstractinterface/interface.h b/tests/auto/dbus/qdbusabstractinterface/interface.h index 209c7d359c..53744998d0 100644 --- a/tests/auto/dbus/qdbusabstractinterface/interface.h +++ b/tests/auto/dbus/qdbusabstractinterface/interface.h @@ -1,37 +1,12 @@ -/**************************************************************************** -** -** 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 #ifndef INTERFACE_H #define INTERFACE_H -#include <QtCore/QObject> -#include <QtCore/QHash> -#include <QtDBus/QDBusArgument> +#include <QObject> +#include <QHash> +#include <QDBusArgument> struct RegisteredType { diff --git a/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml b/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml index ad61351cb2..70d5a4e9c3 100644 --- a/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml +++ b/tests/auto/dbus/qdbusabstractinterface/org.qtproject.QtDBus.Pinger.xml @@ -12,7 +12,7 @@ </signal> <signal name="complexSignal"> <arg name="" type="(s)"/> - <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="RegisteredType"/> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="RegisteredType"/> </signal> <method name="voidMethod" /> <method name="sleepMethod"> diff --git a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface.pro b/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface.pro deleted file mode 100644 index 26991e2514..0000000000 --- a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusabstractinterface -TEMPLATE = subdirs -qdbusabstractinterface.depends = qpinger -SUBDIRS = qpinger qdbusabstractinterface -OTHER_FILES += org.qtproject.QtDBus.Pinger.xml diff --git a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/.prev_CMakeLists.txt deleted file mode 100644 index 6db0362e59..0000000000 --- a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/.prev_CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Generated from qdbusabstractinterface.pro. - -##################################################################### -## tst_qdbusabstractinterface Test: -##################################################################### - -qt_add_test(tst_qdbusabstractinterface - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" - SOURCES - ../interface.cpp ../interface.h - ../tst_qdbusabstractinterface.cpp - DBUS_INTERFACE_SOURCES - ../org.qtproject.QtDBus.Pinger.xml - DBUS_INTERFACE_FLAGS - "-i" "../interface.h" - PUBLIC_LIBRARIES - Qt::DBus -) diff --git a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/CMakeLists.txt b/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/CMakeLists.txt index 3df1ff8177..55634f0677 100644 --- a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/CMakeLists.txt +++ b/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/CMakeLists.txt @@ -1,9 +1,8 @@ -# Generated from qdbusabstractinterface.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusabstractinterface Test: ##################################################################### -# special case begin # this test can not be generated here. It needs to be set up in the # parent directory -# special case end diff --git a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/qdbusabstractinterface.pro b/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/qdbusabstractinterface.pro deleted file mode 100644 index 702c81ff54..0000000000 --- a/tests/auto/dbus/qdbusabstractinterface/qdbusabstractinterface/qdbusabstractinterface.pro +++ /dev/null @@ -1,12 +0,0 @@ -CONFIG += testcase -SOURCES += ../tst_qdbusabstractinterface.cpp ../interface.cpp -HEADERS += ../interface.h - -TARGET = ../tst_qdbusabstractinterface -DESTDIR = ./ - -QT = core testlib -QT += dbus - -DBUS_INTERFACES = ../org.qtproject.QtDBus.Pinger.xml -QDBUSXML2CPP_INTERFACE_HEADER_FLAGS += -i ../interface.h diff --git a/tests/auto/dbus/qdbusabstractinterface/qpinger/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusabstractinterface/qpinger/.prev_CMakeLists.txt deleted file mode 100644 index 7f65f85afb..0000000000 --- a/tests/auto/dbus/qdbusabstractinterface/qpinger/.prev_CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Generated from qpinger.pro. - -##################################################################### -## qpinger Binary: -##################################################################### - -qt_add_executable(qpinger - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - SOURCES - ../interface.cpp ../interface.h - qpinger.cpp - PUBLIC_LIBRARIES - Qt::DBus -) diff --git a/tests/auto/dbus/qdbusabstractinterface/qpinger/CMakeLists.txt b/tests/auto/dbus/qdbusabstractinterface/qpinger/CMakeLists.txt index 5ebb914c01..362928712d 100644 --- a/tests/auto/dbus/qdbusabstractinterface/qpinger/CMakeLists.txt +++ b/tests/auto/dbus/qdbusabstractinterface/qpinger/CMakeLists.txt @@ -1,15 +1,16 @@ -# Generated from qpinger.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qpinger Binary: ##################################################################### -qt_add_executable(qpinger +qt_internal_add_executable(qpinger OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - NO_INSTALL # special case + NO_INSTALL SOURCES ../interface.cpp ../interface.h qpinger.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.cpp b/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.cpp index e92f173fae..47e5becc15 100644 --- a/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.cpp +++ b/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.cpp @@ -1,33 +1,15 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <QtCore/QtCore> -#include <QtDBus/QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QCoreApplication> + +#include <QDBusServer> +#include <QDBusContext> +#include <QDBusMetaType> +#include <QDBusConnection> +#include <QDBusMessage> + #include "../interface.h" static const char serviceName[] = "org.qtproject.autotests.qpinger"; @@ -39,7 +21,7 @@ class PingerServer : public QDBusServer, protected QDBusContext Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qpinger") public: - PingerServer(QObject* parent = 0) + PingerServer(QObject *parent = nullptr) : QDBusServer(parent), m_conn("none") { diff --git a/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.pro b/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.pro deleted file mode 100644 index a876cbfa33..0000000000 --- a/tests/auto/dbus/qdbusabstractinterface/qpinger/qpinger.pro +++ /dev/null @@ -1,6 +0,0 @@ -SOURCES = qpinger.cpp ../interface.cpp -HEADERS = ../interface.h -TARGET = qpinger -DESTDIR = ./ -CONFIG += cmdline -QT = core dbus diff --git a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index 11896d2f15..ec585948d7 100644 --- a/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/dbus/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -1,38 +1,18 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <qcoreapplication.h> -#include <qdebug.h> -#include <qsharedpointer.h> - -#include <QtTest/QtTest> - -#include <QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QTestEventLoop> +#include <QDebug> +#include <QCoreApplication> +#include <QSharedPointer> +#include <QSignalSpy> +#include <QProcess> +#include <QSemaphore> +#include <QDBusMetaType> +#include <QDBusConnectionInterface> +#include <QDBusInterface> #include "interface.h" #include "pinger_interface.h" @@ -487,7 +467,7 @@ public: wait(); } - void run() + void run() override { QDBusConnection con = QDBusConnection::connectToBus(QDBusConnection::SessionBus, "ThreadConnection"); if (!con.isConnected()) @@ -884,7 +864,7 @@ void tst_QDBusAbstractInterface::getStringSignal() QCOMPARE(s.size(), 1); QCOMPARE(s[0].size(), 1); - QCOMPARE(s[0][0].userType(), int(QVariant::String)); + QCOMPARE(s[0][0].userType(), int(QMetaType::QString)); QCOMPARE(s[0][0].toString(), expectedValue); } @@ -966,7 +946,7 @@ void tst_QDBusAbstractInterface::getStringSignalPeer() QCOMPARE(s.size(), 1); QCOMPARE(s[0].size(), 1); - QCOMPARE(s[0][0].userType(), int(QVariant::String)); + QCOMPARE(s[0][0].userType(), int(QMetaType::QString)); QCOMPARE(s[0][0].toString(), expectedValue); } diff --git a/tests/auto/dbus/qdbusconnection/CMakeLists.txt b/tests/auto/dbus/qdbusconnection/CMakeLists.txt index e40f18387e..56ae21f291 100644 --- a/tests/auto/dbus/qdbusconnection/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection/CMakeLists.txt @@ -1,12 +1,21 @@ -# Generated from qdbusconnection.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusconnection Test: ##################################################################### -qt_add_test(tst_qdbusconnection +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection SOURCES tst_qdbusconnection.cpp tst_qdbusconnection.h - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus + TESTDATA + tst_qdbusconnection.conf ) diff --git a/tests/auto/dbus/qdbusconnection/qdbusconnection.pro b/tests/auto/dbus/qdbusconnection/qdbusconnection.pro deleted file mode 100644 index 3fcf3e076b..0000000000 --- a/tests/auto/dbus/qdbusconnection/qdbusconnection.pro +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusconnection -QT = core dbus testlib -SOURCES += tst_qdbusconnection.cpp -HEADERS += tst_qdbusconnection.h diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.conf b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.conf new file mode 100644 index 0000000000..7dec73d0d7 --- /dev/null +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.conf @@ -0,0 +1,23 @@ +<!-- This configuration file for tst_qdbusconnection. +--> + +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + <type>tst_qdbusconnection</type> + + <listen>unix:tmpdir=/tmp</listen> + + <auth>EXTERNAL</auth> + + <policy context="default"> + <!-- Allow everything to be sent --> + <allow send_destination="*" eavesdrop="true"/> + <!-- Allow everything to be received --> + <allow eavesdrop="true"/> + <!-- Allow anyone to own anything --> + <allow own="*"/> + </policy> + + <limit name="max_completed_connections">0</limit> +</busconfig> diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp index 77ae6f154d..ab750dff33 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp @@ -1,39 +1,17 @@ -/**************************************************************************** -** -** 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 "tst_qdbusconnection.h" -#include <qcoreapplication.h> -#include <qdebug.h> - -#include <QtTest/QtTest> -#include <QtDBus/QtDBus> +#include <QTest> +#include <QDebug> +#include <QProcess> +#include <QCoreApplication> +#include <QDBusConnection> +#include <QDBusReply> +#include <QDBusInterface> +#include <QDBusConnectionInterface> #ifdef Q_OS_UNIX # include <sys/types.h> @@ -136,7 +114,7 @@ void tst_QDBusConnection::sendSignalToName() QVERIFY(con.send(msg)); - QTRY_COMPARE(spy.args.count(), 1); + QTRY_COMPARE(spy.args.size(), 1); QCOMPARE(spy.args.at(0).toString(), QString("ping")); } @@ -161,7 +139,7 @@ void tst_QDBusConnection::sendSignalToOtherName() QTest::qWait(1000); - QCOMPARE(spy.args.count(), 0); + QCOMPARE(spy.args.size(), 0); } void tst_QDBusConnection::send() @@ -175,7 +153,7 @@ void tst_QDBusConnection::send() QDBusMessage reply = con.call(msg); - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); QCOMPARE(reply.arguments().at(0).typeName(), "QStringList"); QVERIFY(reply.arguments().at(0).toStringList().contains(con.baseService())); } @@ -194,7 +172,7 @@ void tst_QDBusConnection::sendWithGui() QDBusMessage reply = con.call(msg, QDBus::BlockWithGui); - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); QCOMPARE(reply.arguments().at(0).typeName(), "QStringList"); QVERIFY(reply.arguments().at(0).toStringList().contains(con.baseService())); } @@ -213,7 +191,7 @@ void tst_QDBusConnection::sendAsync() "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); QVERIFY(con.callWithCallback(msg, &spy, SLOT(asyncReply(QDBusMessage)))); - QTRY_COMPARE(spy.args.count(), 1); + QTRY_COMPARE(spy.args.size(), 1); QCOMPARE(spy.args.value(0).typeName(), "QStringList"); QVERIFY(spy.args.at(0).toStringList().contains(con.baseService())); } @@ -236,7 +214,7 @@ void tst_QDBusConnection::connect() QVERIFY(con.send(msg)); - QTRY_COMPARE(spy.args.count(), 1); + QTRY_COMPARE(spy.args.size(), 1); QCOMPARE(spy.args.at(0).toString(), QString("ping")); } @@ -1048,7 +1026,7 @@ void tst_QDBusConnection::multipleInterfacesInQObject() "local.BaseObject", "anotherMethod"); QDBusMessage reply = con.call(msg, QDBus::Block); QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - QCOMPARE(reply.arguments().count(), 0); + QCOMPARE(reply.arguments().size(), 0); QVERIFY_HOOKCALLED(); } @@ -1434,6 +1412,67 @@ void tst_QDBusConnection::pendingCallWhenDisconnected() #endif } +void tst_QDBusConnection::connectionLimit() +{ +#if !QT_CONFIG(process) + QSKIP("Test requires QProcess"); +#else + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + + QProcess daemon; + daemon.start("dbus-daemon", + QStringList() << "--config-file" << QFINDTESTDATA("../qdbusconnection/tst_qdbusconnection.conf") + << "--nofork" + << "--print-address"); + QVERIFY2(daemon.waitForReadyRead(2000), + "Daemon didn't print its address in time; error: \"" + daemon.errorString().toLocal8Bit() + + "\"; stderr:\n" + daemon.readAllStandardError()); + + QString address = QString::fromLocal8Bit(daemon.readAll().trimmed()); + QDBusConnection con = QDBusConnection::connectToBus(address, "connectionLimit"); + QVERIFY2(!con.isConnected(), "Unexpected successful connection"); + QCOMPARE(con.lastError().type(), QDBusError::LimitsExceeded); + + // kill the bus + daemon.terminate(); + daemon.waitForFinished(); +#endif +} + +void tst_QDBusConnection::emptyServerAddress() +{ + QDBusServer server({}, nullptr); +} + +void tst_QDBusConnection::parentClassSignal() +{ + if (!QCoreApplication::instance()) + QSKIP("Test requires a QCoreApplication"); + + const QString path = "/path"; + + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + + // register one object at root: + MyObject obj; + QVERIFY(con.registerObject(path, &obj, QDBusConnection::ExportAllContents)); + QCOMPARE(con.objectRegisteredAt(path), static_cast<QObject *>(&obj)); + + SignalReceiver recv; + QVERIFY(con.connect(con.baseService(), path, "local.BaseObject", "baseObjectSignal", &recv, + SLOT(oneSlot()))); + QVERIFY(con.connect(con.baseService(), path, "local.MyObject", "myObjectSignal", &recv, + SLOT(oneSlot()))); + + emit obj.baseObjectSignal(); + QTRY_COMPARE(recv.signalsReceived, 1); + + emit obj.myObjectSignal(); + QTRY_COMPARE(recv.signalsReceived, 2); +} + 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 b4d689e6f4..4137859414 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.h @@ -1,59 +1,44 @@ -/**************************************************************************** -** -** 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 #ifndef TST_QDBUSCONNECTION_H #define TST_QDBUSCONNECTION_H #include <QObject> -#include <QtDBus/QtDBus> -#include <QtTest/QtTest> +#include <QTest> +#include <QTestEventLoop> +#include <QDBusMessage> +#include <QDBusConnection> +#include <QDBusServer> +#include <QDBusVirtualObject> class BaseObject: public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "local.BaseObject") public: - BaseObject(QObject *parent = 0) : QObject(parent) { } + BaseObject(QObject *parent = nullptr) : QObject(parent) { } public slots: void anotherMethod() { } +signals: + void baseObjectSignal(); }; class MyObject: public BaseObject { Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "local.MyObject") public slots: void method(const QDBusMessage &msg); public: static QString path; int callCount; - MyObject(QObject *parent = 0) : BaseObject(parent), callCount(0) {} + MyObject(QObject *parent = nullptr) : BaseObject(parent), callCount(0) {} + +signals: + void myObjectSignal(); }; class MyObjectWithoutInterface: public QObject @@ -66,7 +51,7 @@ public: static QString path; static QString interface; int callCount; - MyObjectWithoutInterface(QObject *parent = 0) : QObject(parent), callCount(0) {} + MyObjectWithoutInterface(QObject *parent = nullptr) : QObject(parent), callCount(0) {} }; class SignalReceiver : public QObject @@ -135,6 +120,11 @@ private slots: void callVirtualObject(); void callVirtualObjectLocal(); void pendingCallWhenDisconnected(); + void connectionLimit(); + + void emptyServerAddress(); + + void parentClassSignal(); public: QString serviceName() const { return "org.qtproject.Qt.Autotests.QDBusConnection"; } @@ -175,7 +165,7 @@ public: bool registerObject() { - Q_FOREACH (const QString &name, m_connections) { + for (const QString &name : std::as_const(m_connections)) { if (!registerObject(QDBusConnection(name))) return false; } @@ -184,7 +174,7 @@ public: void unregisterObject() { - Q_FOREACH (const QString &name, m_connections) { + for (const QString &name : std::as_const(m_connections)) { QDBusConnection c(name); c.unregisterObject(m_path); } @@ -238,7 +228,7 @@ class TestObject : public QObject { Q_OBJECT public: - TestObject(QObject *parent = 0) : QObject(parent) {} + TestObject(QObject *parent = nullptr) : QObject(parent) {} ~TestObject() {} QString func; @@ -270,12 +260,12 @@ class VirtualObject: public QDBusVirtualObject public: VirtualObject() :success(true) {} - QString introspect(const QString & /* path */) const + QString introspect(const QString & /* path */) const override { return QString(); } - bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) { + bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) override { ++callCount; lastMessage = message; diff --git a/tests/auto/dbus/qdbusconnection_delayed/CMakeLists.txt b/tests/auto/dbus/qdbusconnection_delayed/CMakeLists.txt index 793c7907e5..d25c57f37f 100644 --- a/tests/auto/dbus/qdbusconnection_delayed/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection_delayed/CMakeLists.txt @@ -1,14 +1,19 @@ -# Generated from qdbusconnection_delayed.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusconnection_delayed Test: ##################################################################### -qt_add_test(tst_qdbusconnection_delayed +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection_delayed LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection_delayed SOURCES tst_qdbusconnection_delayed.cpp - DEFINES - SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\" - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusconnection_delayed/qdbusconnection_delayed.pro b/tests/auto/dbus/qdbusconnection_delayed/qdbusconnection_delayed.pro deleted file mode 100644 index 71a75c644d..0000000000 --- a/tests/auto/dbus/qdbusconnection_delayed/qdbusconnection_delayed.pro +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbusconnection_delayed -QT = core dbus testlib -SOURCES += tst_qdbusconnection_delayed.cpp -DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/dbus/qdbusconnection_delayed/tst_qdbusconnection_delayed.cpp b/tests/auto/dbus/qdbusconnection_delayed/tst_qdbusconnection_delayed.cpp index 5f54dff39b..1ce59749f7 100644 --- a/tests/auto/dbus/qdbusconnection_delayed/tst_qdbusconnection_delayed.cpp +++ b/tests/auto/dbus/qdbusconnection_delayed/tst_qdbusconnection_delayed.cpp @@ -1,33 +1,10 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include <QtDBus> -#include <QtTest> +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QTestEventLoop> +#include <QDBusConnection> +#include <QDBusConnectionInterface> #ifdef Q_OS_WIN # include <process.h> diff --git a/tests/auto/dbus/qdbusconnection_no_app/CMakeLists.txt b/tests/auto/dbus/qdbusconnection_no_app/CMakeLists.txt index aad766362c..3368ce33f0 100644 --- a/tests/auto/dbus/qdbusconnection_no_app/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection_no_app/CMakeLists.txt @@ -1,16 +1,22 @@ -# Generated from qdbusconnection_no_app.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusconnection_no_app Test: ##################################################################### -qt_add_test(tst_qdbusconnection_no_app +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection_no_app LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection_no_app SOURCES ../qdbusconnection/tst_qdbusconnection.h tst_qdbusconnection_no_app.cpp DEFINES - SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\" tst_QDBusConnection=tst_QDBusConnection_NoApplication - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusconnection_no_app/qdbusconnection_no_app.pro b/tests/auto/dbus/qdbusconnection_no_app/qdbusconnection_no_app.pro deleted file mode 100644 index ba3a13caa9..0000000000 --- a/tests/auto/dbus/qdbusconnection_no_app/qdbusconnection_no_app.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusconnection_no_app -QT = core dbus testlib -SOURCES += tst_qdbusconnection_no_app.cpp -HEADERS += ../qdbusconnection/tst_qdbusconnection.h -DEFINES += SRCDIR=\\\"$$PWD/\\\" tst_QDBusConnection=tst_QDBusConnection_NoApplication diff --git a/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp b/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp index c7f4805ca0..4b0157e83c 100644 --- a/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp +++ b/tests/auto/dbus/qdbusconnection_no_app/tst_qdbusconnection_no_app.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // Ugly hack, look away #include "../qdbusconnection/tst_qdbusconnection.cpp" diff --git a/tests/auto/dbus/qdbusconnection_no_bus/CMakeLists.txt b/tests/auto/dbus/qdbusconnection_no_bus/CMakeLists.txt index 111f8907c8..d6954e4c4b 100644 --- a/tests/auto/dbus/qdbusconnection_no_bus/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection_no_bus/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbusconnection_no_bus.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusconnection_no_bus Test: ##################################################################### -qt_add_test(tst_qdbusconnection_no_bus +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection_no_bus LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection_no_bus SOURCES tst_qdbusconnection_no_bus.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusconnection_no_bus/qdbusconnection_no_bus.pro b/tests/auto/dbus/qdbusconnection_no_bus/qdbusconnection_no_bus.pro deleted file mode 100644 index 1998cc6df7..0000000000 --- a/tests/auto/dbus/qdbusconnection_no_bus/qdbusconnection_no_bus.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbusconnection_no_bus -QT = core dbus testlib -SOURCES += tst_qdbusconnection_no_bus.cpp diff --git a/tests/auto/dbus/qdbusconnection_no_bus/tst_qdbusconnection_no_bus.cpp b/tests/auto/dbus/qdbusconnection_no_bus/tst_qdbusconnection_no_bus.cpp index f97f891ff8..abc3749304 100644 --- a/tests/auto/dbus/qdbusconnection_no_bus/tst_qdbusconnection_no_bus.cpp +++ b/tests/auto/dbus/qdbusconnection_no_bus/tst_qdbusconnection_no_bus.cpp @@ -1,35 +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 <qcoreapplication.h> -#include <qdebug.h> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <QtTest/QtTest> -#include <QtDBus/QtDBus> +#include <QTest> +#include <QDebug> +#include <QCoreApplication> +#include <QDBusConnection> #include <stdlib.h> diff --git a/tests/auto/dbus/qdbusconnection_no_libdbus/CMakeLists.txt b/tests/auto/dbus/qdbusconnection_no_libdbus/CMakeLists.txt index 2a7e1dc80d..879572f3bd 100644 --- a/tests/auto/dbus/qdbusconnection_no_libdbus/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection_no_libdbus/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qdbusconnection_no_libdbus.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusconnection_no_libdbus Test: ##################################################################### -qt_add_test(tst_qdbusconnection_no_libdbus +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection_no_libdbus LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection_no_libdbus SOURCES ../qdbusconnection_no_bus/tst_qdbusconnection_no_bus.cpp DEFINES SIMULATE_LOAD_FAIL tst_QDBusConnectionNoBus=tst_QDBusConnectionNoLibDBus1 - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusconnection_no_libdbus/qdbusconnection_no_libdbus.pro b/tests/auto/dbus/qdbusconnection_no_libdbus/qdbusconnection_no_libdbus.pro deleted file mode 100644 index d1b27ee8c0..0000000000 --- a/tests/auto/dbus/qdbusconnection_no_libdbus/qdbusconnection_no_libdbus.pro +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbusconnection_no_libdbus -QT = core dbus testlib -DEFINES += SIMULATE_LOAD_FAIL tst_QDBusConnectionNoBus=tst_QDBusConnectionNoLibDBus1 -SOURCES += ../qdbusconnection_no_bus/tst_qdbusconnection_no_bus.cpp diff --git a/tests/auto/dbus/qdbusconnection_no_libdbus/tst_qdbusconnection_no_libdbus.cpp b/tests/auto/dbus/qdbusconnection_no_libdbus/tst_qdbusconnection_no_libdbus.cpp index e93b8aa609..0a1287e725 100644 --- a/tests/auto/dbus/qdbusconnection_no_libdbus/tst_qdbusconnection_no_libdbus.cpp +++ b/tests/auto/dbus/qdbusconnection_no_libdbus/tst_qdbusconnection_no_libdbus.cpp @@ -1,35 +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.h> #include <qdebug.h> -#include <QtTest/QtTest> -#include <QtDBus/QtDBus> +#include <QTest> + #include <stdlib.h> diff --git a/tests/auto/dbus/qdbusconnection_signalorder/CMakeLists.txt b/tests/auto/dbus/qdbusconnection_signalorder/CMakeLists.txt new file mode 100644 index 0000000000..182007da92 --- /dev/null +++ b/tests/auto/dbus/qdbusconnection_signalorder/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_qdbusconnection_signalorder Test: +##################################################################### + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection_signalorder LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection_signalorder + SOURCES + tst_qdbusconnection_signalorder.cpp + LIBRARIES + Qt::DBus +) diff --git a/tests/auto/dbus/qdbusconnection_signalorder/tst_qdbusconnection_signalorder.cpp b/tests/auto/dbus/qdbusconnection_signalorder/tst_qdbusconnection_signalorder.cpp new file mode 100644 index 0000000000..06dc451ac6 --- /dev/null +++ b/tests/auto/dbus/qdbusconnection_signalorder/tst_qdbusconnection_signalorder.cpp @@ -0,0 +1,103 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QCoreApplication> +#include <QDBusConnection> +#include <QDBusMessage> +#include <QObject> +#include <QTest> +#include <QTimer> + +using namespace Qt::StringLiterals; + +static constexpr int MAX_TEST_DURATION_MS = 10000; +static constexpr int NUM_MESSAGES = 20; + +class SignalReceiver : public QObject +{ + Q_OBJECT +public: + explicit SignalReceiver(QDBusConnection &connection, const QString &serviceName); + + int nextValue() const { return m_nextValue; } + bool inOrder() const { return m_inOrder; } + +Q_SIGNALS: + void testSignal(int); + void done(); + +private Q_SLOTS: + void testSlot(int number); + +private: + int m_nextValue = 0; + bool m_inOrder = true; +}; + +SignalReceiver::SignalReceiver(QDBusConnection &connection, const QString &serviceName) +{ + connection.connect(serviceName, "/", {}, "testSignal", this, SLOT(testSlot(int))); +} + +void SignalReceiver::testSlot(int number) +{ + if (m_nextValue != number) { + m_inOrder = false; + qWarning("Message out of sequence, expected: %d, received: %d", m_nextValue, number); + } + + m_nextValue++; + + if (m_nextValue == NUM_MESSAGES) { + Q_EMIT done(); + } +} + +class tst_QDBusConnection_SignalOrder : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void signalOrder(); +}; + +// This is a regression test for QTBUG-105457. The bug is a race condition, +// so it cannot be reliably triggered at each test execution. +void tst_QDBusConnection_SignalOrder::signalOrder() +{ + int argc = 1; + static char appName[] = "tst_qdbusconnection_signalorder"; + char *argv[] = { appName, 0 }; + QCoreApplication app(argc, argv); + + const QString serviceName = + u"org.qtproject.tst_dbusconnection_signalorder_%1"_s.arg(app.applicationPid()); + + auto connection = QDBusConnection::sessionBus(); + + QVERIFY(connection.isConnected()); + QVERIFY(connection.registerService(serviceName)); + + // Limit the test execution time in case if something goes wrong inside + // the signal receiver. + QTimer::singleShot(MAX_TEST_DURATION_MS, &app, &QCoreApplication::quit); + + SignalReceiver signalReceiver(connection, serviceName); + connect(&signalReceiver, &SignalReceiver::done, &app, &QCoreApplication::quit); + + QVERIFY(connection.registerObject("/", &signalReceiver, QDBusConnection::ExportAllSlots)); + + for (int i = 0; i < NUM_MESSAGES; i++) { + auto testSignal = QDBusMessage::createSignal("/", serviceName, "testSignal"); + testSignal << i; + QVERIFY(connection.send(testSignal)); + } + + app.exec(); + + QVERIFY(signalReceiver.inOrder()); + QCOMPARE(signalReceiver.nextValue(), NUM_MESSAGES); +} + +QTEST_APPLESS_MAIN(tst_QDBusConnection_SignalOrder) + +#include "tst_qdbusconnection_signalorder.moc" diff --git a/tests/auto/dbus/qdbusconnection_spyhook/BLACKLIST b/tests/auto/dbus/qdbusconnection_spyhook/BLACKLIST deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/auto/dbus/qdbusconnection_spyhook/BLACKLIST +++ /dev/null diff --git a/tests/auto/dbus/qdbusconnection_spyhook/CMakeLists.txt b/tests/auto/dbus/qdbusconnection_spyhook/CMakeLists.txt index a3b1d8d10c..80417296a0 100644 --- a/tests/auto/dbus/qdbusconnection_spyhook/CMakeLists.txt +++ b/tests/auto/dbus/qdbusconnection_spyhook/CMakeLists.txt @@ -1,16 +1,22 @@ -# Generated from qdbusconnection_spyhook.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusconnection_spyhook Test: ##################################################################### -qt_add_test(tst_qdbusconnection_spyhook +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusconnection_spyhook LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusconnection_spyhook SOURCES ../qdbusconnection/tst_qdbusconnection.h tst_qdbusconnection_spyhook.cpp DEFINES - SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/\\\" tst_QDBusConnection=tst_QDBusConnection_SpyHook - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusconnection_spyhook/qdbusconnection_spyhook.pro b/tests/auto/dbus/qdbusconnection_spyhook/qdbusconnection_spyhook.pro deleted file mode 100644 index 020d30380d..0000000000 --- a/tests/auto/dbus/qdbusconnection_spyhook/qdbusconnection_spyhook.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusconnection_spyhook -QT = core dbus testlib -SOURCES += tst_qdbusconnection_spyhook.cpp -HEADERS += ../qdbusconnection/tst_qdbusconnection.h -DEFINES += SRCDIR=\\\"$$PWD/\\\" tst_QDBusConnection=tst_QDBusConnection_SpyHook -include(../dbus-testcase.pri) diff --git a/tests/auto/dbus/qdbusconnection_spyhook/tst_qdbusconnection_spyhook.cpp b/tests/auto/dbus/qdbusconnection_spyhook/tst_qdbusconnection_spyhook.cpp index 92bbbe1ef3..57466afc04 100644 --- a/tests/auto/dbus/qdbusconnection_spyhook/tst_qdbusconnection_spyhook.cpp +++ b/tests/auto/dbus/qdbusconnection_spyhook/tst_qdbusconnection_spyhook.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** 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 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtDBus/QDBusMessage> diff --git a/tests/auto/dbus/qdbuscontext/CMakeLists.txt b/tests/auto/dbus/qdbuscontext/CMakeLists.txt index ee84e633af..28bb3ebbc7 100644 --- a/tests/auto/dbus/qdbuscontext/CMakeLists.txt +++ b/tests/auto/dbus/qdbuscontext/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbuscontext.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbuscontext Test: ##################################################################### -qt_add_test(tst_qdbuscontext +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbuscontext LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbuscontext SOURCES tst_qdbuscontext.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbuscontext/qdbuscontext.pro b/tests/auto/dbus/qdbuscontext/qdbuscontext.pro deleted file mode 100644 index 42cf425d52..0000000000 --- a/tests/auto/dbus/qdbuscontext/qdbuscontext.pro +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbuscontext -QT = core dbus testlib -SOURCES += tst_qdbuscontext.cpp - diff --git a/tests/auto/dbus/qdbuscontext/tst_qdbuscontext.cpp b/tests/auto/dbus/qdbuscontext/tst_qdbuscontext.cpp index cd49a7c742..b44e353365 100644 --- a/tests/auto/dbus/qdbuscontext/tst_qdbuscontext.cpp +++ b/tests/auto/dbus/qdbuscontext/tst_qdbuscontext.cpp @@ -1,32 +1,11 @@ -/**************************************************************************** -** -** 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 <QtDBus> -#include <QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QDBusContext> +#include <QDBusConnection> +#include <QDBusInterface> +#include <QDBusReply> const char errorName[] = "org.qtproject.tst_QDBusContext.Error"; const char errorMsg[] = "A generic error"; diff --git a/tests/auto/dbus/qdbusinterface/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusinterface/.prev_CMakeLists.txt deleted file mode 100644 index ae79490a83..0000000000 --- a/tests/auto/dbus/qdbusinterface/.prev_CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -# Generated from qdbusinterface.pro. - -add_subdirectory(qmyserver) -add_subdirectory(qdbusinterface) diff --git a/tests/auto/dbus/qdbusinterface/CMakeLists.txt b/tests/auto/dbus/qdbusinterface/CMakeLists.txt index 321c61a627..56439f9ef6 100644 --- a/tests/auto/dbus/qdbusinterface/CMakeLists.txt +++ b/tests/auto/dbus/qdbusinterface/CMakeLists.txt @@ -1,41 +1,44 @@ -# Generated from qdbusinterface.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_qdbusinterface LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(qmyserver) -# special case begin ##################################################################### ## ../tst_qdbusinterface Test: ##################################################################### -add_qt_test(tst_qdbusinterface +qt_internal_add_test(tst_qdbusinterface SOURCES myobject.h tst_qdbusinterface.cpp LIBRARIES Qt::CorePrivate Qt::DBusPrivate - PUBLIC_LIBRARIES + LIBRARIES Qt::Core Qt::DBus ) -#### Keys ignored in scope 1:.:.:qdbusinterface.pro:<TRUE>: -# CONFIG = "testcase" -# DESTDIR = "./" - ## Scopes: ##################################################################### -extend_target(tst_qdbusinterface CONDITION QT_FEATURE_dbus_linked +qt_internal_extend_target(tst_qdbusinterface CONDITION QT_FEATURE_dbus_linked DEFINES QT_LINKED_LIBDBUS - PUBLIC_LIBRARIES + LIBRARIES dbus-1 ) -extend_target(tst_qdbusinterface CONDITION NOT QT_FEATURE_dbus_linked +qt_internal_extend_target(tst_qdbusinterface CONDITION NOT QT_FEATURE_dbus_linked SOURCES ../../../../src/dbus/qdbus_symbols.cpp ) -# special case end +add_dependencies(tst_qdbusinterface qmyserver_qdbusinterface) + diff --git a/tests/auto/dbus/qdbusinterface/myobject.h b/tests/auto/dbus/qdbusinterface/myobject.h index 32da7348f2..355d4d3752 100644 --- a/tests/auto/dbus/qdbusinterface/myobject.h +++ b/tests/auto/dbus/qdbusinterface/myobject.h @@ -1,37 +1,13 @@ -/**************************************************************************** -** -** 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 #ifndef MYOBJECT_H #define MYOBJECT_H -#include <QtCore/QObject> -#include <QtDBus/QtDBus> - +#include <QObject> +#include <QDBusMessage> +#include <QDBusContext> +#include <QDBusConnection> class MyObject: public QObject, protected QDBusContext { diff --git a/tests/auto/dbus/qdbusinterface/qdbusinterface.pro b/tests/auto/dbus/qdbusinterface/qdbusinterface.pro deleted file mode 100644 index bc9cf5ffaf..0000000000 --- a/tests/auto/dbus/qdbusinterface/qdbusinterface.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusinterface -QT = core testlib -TEMPLATE = subdirs -qdbusinterface.depends = qmyserver -SUBDIRS = qmyserver qdbusinterface diff --git a/tests/auto/dbus/qdbusinterface/qdbusinterface/qdbusinterface.pro b/tests/auto/dbus/qdbusinterface/qdbusinterface/qdbusinterface.pro deleted file mode 100644 index 67709105a6..0000000000 --- a/tests/auto/dbus/qdbusinterface/qdbusinterface/qdbusinterface.pro +++ /dev/null @@ -1,14 +0,0 @@ -CONFIG += testcase -SOURCES += ../tst_qdbusinterface.cpp -HEADERS += ../myobject.h -TARGET = ../tst_qdbusinterface -DESTDIR = ./ - -QT = core core-private dbus 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/qdbusinterface/qmyserver/.prev_CMakeLists.txt b/tests/auto/dbus/qdbusinterface/qmyserver/.prev_CMakeLists.txt deleted file mode 100644 index 9c898fecf6..0000000000 --- a/tests/auto/dbus/qdbusinterface/qmyserver/.prev_CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Generated from qmyserver.pro. - -##################################################################### -## qmyserver_qdbusinterface Binary: -##################################################################### - -qt_add_executable(qmyserver_qdbusinterface - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - SOURCES - ../myobject.h - qmyserver.cpp - PUBLIC_LIBRARIES - Qt::DBus -) diff --git a/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt b/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt index 916735bf59..55eb2c39cc 100644 --- a/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt +++ b/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt @@ -1,15 +1,16 @@ -# Generated from qmyserver.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## qmyserver_qdbusinterface Binary: ##################################################################### -qt_add_executable(qmyserver_qdbusinterface +qt_internal_add_executable(qmyserver_qdbusinterface OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - NO_INSTALL # special case + NO_INSTALL SOURCES ../myobject.h qmyserver.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp index 535d2f756b..5d8692d9a6 100644 --- a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp +++ b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp @@ -1,33 +1,9 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <QtCore/QtCore> -#include <QtDBus/QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QCoreApplication> +#include <QDBusServer> #include "../myobject.h" @@ -44,7 +20,7 @@ class MyServer : public QDBusServer, protected QDBusContext Q_CLASSINFO("D-Bus Interface", "org.qtproject.autotests.qmyserver") public: - MyServer(QObject* parent = 0) + MyServer(QObject *parent = nullptr) : QDBusServer(parent), m_conn("none") { diff --git a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.pro b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.pro deleted file mode 100644 index 406f3d7d36..0000000000 --- a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.pro +++ /dev/null @@ -1,6 +0,0 @@ -SOURCES = qmyserver.cpp -HEADERS = ../myobject.h -TARGET = qmyserver_qdbusinterface -DESTDIR = ./ -QT = core dbus -CONFIG -= app_bundle diff --git a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp index e416266b5f..803ae4fa0f 100644 --- a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp +++ b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp @@ -1,44 +1,27 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -/* -*- C++ -*- - */ - -#include <qcoreapplication.h> -#include <qmetatype.h> -#include <QtTest/QtTest> -#include <QtCore/qregularexpression.h> -#include <QtCore/qvariant.h> -#include <QtDBus/QtDBus> -#include <QtDBus/private/qdbus_symbols_p.h> -#include <qdebug.h> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QDebug> +#include <QTestEventLoop> +#include <QCoreApplication> +#include <QMetaType> +#include <QRegularExpression> +#include <QVariant> +#include <QVersionNumber> +#include <QProcess> +#include <QTimer> +#include <QDBusInterface> +#include <QDBusConnectionInterface> +#include <QDBusVirtualObject> + +#include <private/qdbus_symbols_p.h> + #include "../qdbusmarshall/common.h" #include "myobject.h" +using namespace Qt::StringLiterals; + #define TEST_INTERFACE_NAME "org.qtproject.QtDBus.MyObject" #define TEST_SIGNAL_NAME "somethingHappened" @@ -217,6 +200,10 @@ private slots: void complexPropertyWritePeer(); void interactiveAuthorizationRequired(); + + void interfaceNameFallback_data(); + void interfaceNameFallback(); + private: QProcess proc; }; @@ -325,6 +312,13 @@ void tst_QDBusInterface::notValid() QVERIFY(!interface.isValid()); QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); + + // With a connection, but empty/null service and path specified + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY(con.isConnected()); + QDBusInterface iface({}, {}, {}, con); + QVERIFY(!iface.isValid()); + QVERIFY(!QMetaObject::invokeMethod(&interface, "ListNames", Qt::DirectConnection)); } void tst_QDBusInterface::notValidDerived() @@ -405,7 +399,8 @@ class VirtualObject: public QDBusVirtualObject public: VirtualObject() :success(true) {} - QString introspect(const QString &path) const { + QString introspect(const QString &path) const override + { Q_ASSERT(QThread::currentThread() == thread()); if (path == "/some/path/superNode") return "zitroneneis"; @@ -416,7 +411,8 @@ public: return QString(); } - bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) { + bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) override + { Q_ASSERT(QThread::currentThread() == thread()); ++callCount; lastMessage = message; @@ -478,17 +474,17 @@ void tst_QDBusInterface::callMethod() QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); QVariant v = MyObject::callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("foo")); // verify reply - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); v = reply.arguments().at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("foo")); // call an INVOKABLE method @@ -497,17 +493,17 @@ void tst_QDBusInterface::callMethod() QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); v = MyObject::callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("bar")); // verify reply - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); v = reply.arguments().at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("bar")); } @@ -525,10 +521,10 @@ void tst_QDBusInterface::invokeMethod() QCOMPARE(MyObject::callCount, 1); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); QVariant v = MyObject::callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("foo")); // make the INVOKABLE call without a return type @@ -537,10 +533,10 @@ void tst_QDBusInterface::invokeMethod() QCOMPARE(MyObject::callCount, 2); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); v = MyObject::callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("bar")); } @@ -559,10 +555,10 @@ void tst_QDBusInterface::invokeMethodWithReturn() QCOMPARE(MyObject::callCount, 1); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); QVariant v = MyObject::callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg.variant().toString()); // verify that we got the reply as expected @@ -574,10 +570,10 @@ void tst_QDBusInterface::invokeMethodWithReturn() QCOMPARE(MyObject::callCount, 2); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); v = MyObject::callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg2.variant().toString()); // verify that we got the reply as expected @@ -603,15 +599,15 @@ void tst_QDBusInterface::invokeMethodWithMultiReturn() QCOMPARE(MyObject::callCount, 1); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 2); + QCOMPARE(MyObject::callArgs.size(), 2); QVariant v = MyObject::callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg.variant().toString()); v = MyObject::callArgs.at(1); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg2.variant().toString()); // verify that we got the replies as expected @@ -628,15 +624,15 @@ void tst_QDBusInterface::invokeMethodWithMultiReturn() QCOMPARE(MyObject::callCount, 2); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 2); + QCOMPARE(MyObject::callArgs.size(), 2); v = MyObject::callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg3.variant().toString()); v = MyObject::callArgs.at(1); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg4.variant().toString()); // verify that we got the replies as expected @@ -659,7 +655,7 @@ void tst_QDBusInterface::invokeMethodWithComplexReturn() QCOMPARE(MyObject::callCount, 1); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); QVariant v = MyObject::callArgs.at(0); QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); QCOMPARE(qdbus_cast<QList<int> >(v), arg); @@ -673,7 +669,7 @@ void tst_QDBusInterface::invokeMethodWithComplexReturn() QCOMPARE(MyObject::callCount, 2); // verify what the callee received - QCOMPARE(MyObject::callArgs.count(), 1); + QCOMPARE(MyObject::callArgs.size(), 1); v = MyObject::callArgs.at(0); QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); QCOMPARE(qdbus_cast<QList<int> >(v), arg2); @@ -713,17 +709,17 @@ void tst_QDBusInterface::callMethodPeer() // verify what the callee received QVariantList callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); QVariant v = callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("foo")); // verify reply - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); v = reply.arguments().at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("foo")); // call an INVOKABLE method @@ -733,17 +729,17 @@ void tst_QDBusInterface::callMethodPeer() // verify what the callee received callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); v = callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("bar")); // verify reply - QCOMPARE(reply.arguments().count(), 1); + QCOMPARE(reply.arguments().size(), 1); v = reply.arguments().at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("bar")); } @@ -762,10 +758,10 @@ void tst_QDBusInterface::invokeMethodPeer() // verify what the callee received QVariantList callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); QVariant v = callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("foo")); // make the INVOKABLE call without a return type @@ -775,10 +771,10 @@ void tst_QDBusInterface::invokeMethodPeer() // verify what the callee received callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); v = callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), QString("bar")); } @@ -798,10 +794,10 @@ void tst_QDBusInterface::invokeMethodWithReturnPeer() // verify what the callee received QVariantList callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); QVariant v = callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg.variant().toString()); // verify that we got the reply as expected @@ -814,10 +810,10 @@ void tst_QDBusInterface::invokeMethodWithReturnPeer() // verify what the callee received callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); v = callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg2.variant().toString()); // verify that we got the reply as expected @@ -844,15 +840,15 @@ void tst_QDBusInterface::invokeMethodWithMultiReturnPeer() // verify what the callee received QVariantList callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 2); + QCOMPARE(callArgs.size(), 2); QVariant v = callArgs.at(0); QDBusVariant dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg.variant().toString()); v = callArgs.at(1); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg2.variant().toString()); // verify that we got the replies as expected @@ -870,15 +866,15 @@ void tst_QDBusInterface::invokeMethodWithMultiReturnPeer() // verify what the callee received callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 2); + QCOMPARE(callArgs.size(), 2); v = callArgs.at(0); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg3.variant().toString()); v = callArgs.at(1); dv = qdbus_cast<QDBusVariant>(v); - QCOMPARE(dv.variant().type(), QVariant::String); + QCOMPARE(dv.variant().userType(), QMetaType::QString); QCOMPARE(dv.variant().toString(), arg4.variant().toString()); // verify that we got the replies as expected @@ -902,7 +898,7 @@ void tst_QDBusInterface::invokeMethodWithComplexReturnPeer() // verify what the callee received QVariantList callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); QVariant v = callArgs.at(0); QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); QCOMPARE(qdbus_cast<QList<int> >(v), arg); @@ -917,7 +913,7 @@ void tst_QDBusInterface::invokeMethodWithComplexReturnPeer() // verify what the callee received callArgs = callArgsPeer(); - QCOMPARE(callArgs.count(), 1); + QCOMPARE(callArgs.size(), 1); v = callArgs.at(0); QCOMPARE(v.userType(), qMetaTypeId<QDBusArgument>()); QCOMPARE(qdbus_cast<QList<int> >(v), arg2); @@ -1019,7 +1015,7 @@ void tst_QDBusInterface::propertyRead() QVariant v = iface.property("prop1"); QVERIFY(v.isValid()); - QCOMPARE(v.userType(), int(QVariant::Int)); + QCOMPARE(v.userType(), int(QMetaType::Int)); QCOMPARE(v.toInt(), arg); QCOMPARE(MyObject::callCount, 1); } @@ -1082,7 +1078,7 @@ void tst_QDBusInterface::propertyReadPeer() QVariant v = iface.property("prop1"); QVERIFY(v.isValid()); - QCOMPARE(v.userType(), int(QVariant::Int)); + QCOMPARE(v.userType(), int(QMetaType::Int)); QCOMPARE(v.toInt(), arg); QCOMPARE(callCountPeer(), 1); } @@ -1157,6 +1153,60 @@ void tst_QDBusInterface::interactiveAuthorizationRequired() QVERIFY(reply.arguments().at(0).toBool()); } +class TestObject : public QObject +{ + Q_OBJECT +public Q_SLOTS: + void test() { } +}; + +void tst_QDBusInterface::interfaceNameFallback_data() +{ + QTest::addColumn<QString>("appName"); + QTest::addColumn<QString>("orgDomain"); + QTest::addColumn<QString>("interfaceName"); + + QTest::addRow("empty.empty") << "" << "" << "local.tst_qdbusinterface"; + QTest::addRow("with-domain") << "" << "qt-project.org" << "org.qt_project.tst_qdbusinterface"; + QTest::addRow("numbers") << "prog42" << "7-zip.org" << "org._7_zip.prog42"; + QTest::addRow("non-latin1") << u"\u00e6"_s << u"\u00e5"_s << "xn__5ca.xn__6ca"; +} + +void tst_QDBusInterface::interfaceNameFallback() +{ + QFETCH(QString, appName); + QFETCH(QString, orgDomain); + QFETCH(QString, interfaceName); + + auto app = QCoreApplication::instance(); + auto oldApplicationName = app->applicationName(); + auto oldOrganizationDomain = app->organizationDomain(); + + app->setApplicationName(appName); + app->setOrganizationDomain(orgDomain); + auto obj = new TestObject; + + auto cleanup = qScopeGuard([&] { + obj->deleteLater(); + app->setApplicationName(oldApplicationName); + app->setOrganizationDomain(oldOrganizationDomain); + }); + + auto con = QDBusConnection::sessionBus(); + const QString path = "/interfaceNameFallback"_L1; + + QVERIFY(con.registerObject(path, obj, QDBusConnection::ExportAllContents)); + + QDBusInterface interface(con.baseService(), path, "org.freedesktop.DBus.Introspectable"_L1, + con); + auto reply = interface.call("Introspect"); + + QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); + QString tag = u"<interface name=\"%1.TestObject\">"_s.arg(interfaceName); + auto result = reply.arguments().at(0).toString(); + QVERIFY2(result.contains(tag), qUtf8Printable(u"Tag '%1' not found\n%2"_s.arg(tag, result))); +} + QTEST_MAIN(tst_QDBusInterface) #include "tst_qdbusinterface.moc" diff --git a/tests/auto/dbus/qdbuslocalcalls/CMakeLists.txt b/tests/auto/dbus/qdbuslocalcalls/CMakeLists.txt index 378475dc46..bf1ee7953f 100644 --- a/tests/auto/dbus/qdbuslocalcalls/CMakeLists.txt +++ b/tests/auto/dbus/qdbuslocalcalls/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbuslocalcalls.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbuslocalcalls Test: ##################################################################### -qt_add_test(tst_qdbuslocalcalls +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbuslocalcalls LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbuslocalcalls SOURCES tst_qdbuslocalcalls.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbuslocalcalls/qdbuslocalcalls.pro b/tests/auto/dbus/qdbuslocalcalls/qdbuslocalcalls.pro deleted file mode 100644 index 3577210b86..0000000000 --- a/tests/auto/dbus/qdbuslocalcalls/qdbuslocalcalls.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbuslocalcalls -QT = core dbus testlib -SOURCES += tst_qdbuslocalcalls.cpp diff --git a/tests/auto/dbus/qdbuslocalcalls/tst_qdbuslocalcalls.cpp b/tests/auto/dbus/qdbuslocalcalls/tst_qdbuslocalcalls.cpp index 90e0421883..35e3471bbe 100644 --- a/tests/auto/dbus/qdbuslocalcalls/tst_qdbuslocalcalls.cpp +++ b/tests/auto/dbus/qdbuslocalcalls/tst_qdbuslocalcalls.cpp @@ -1,37 +1,15 @@ -/**************************************************************************** -** -** 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/QObject> -#include <QtCore/QVariant> -#include <QtCore/QList> -#include <QtCore/QList> -#include <QtTest/QtTest> -#include <QtDBus> - +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QTestEventLoop> +#include <QObject> +#include <QVariant> +#include <QList> +#include <QDBusConnection> +#include <QDBusVariant> +#include <QDBusPendingCallWatcher> +#include <QDBusMetaType> class tst_QDBusLocalCalls: public QObject { @@ -131,20 +109,20 @@ void tst_QDBusLocalCalls::makeInvalidCalls() QDBusMessage callMsg = QDBusMessage::createMethodCall(conn.baseService(), "/", QString(), "echo"); QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ErrorMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ErrorMessage); QDBusError error(replyMsg); - QCOMPARE(int(error.type()), int(QDBusError::UnknownMethod)); + QCOMPARE(error.type(), QDBusError::UnknownMethod); } { QDBusMessage callMsg = QDBusMessage::createMethodCall(conn.baseService(), "/no_object", QString(), "echo"); QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ErrorMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ErrorMessage); QDBusError error(replyMsg); - QCOMPARE(int(error.type()), int(QDBusError::UnknownObject)); + QCOMPARE(error.type(), QDBusError::UnknownObject); } } @@ -156,10 +134,10 @@ void tst_QDBusLocalCalls::makeCalls() callMsg << value; QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ReplyMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ReplyMessage); QVariantList replyArgs = replyMsg.arguments(); - QCOMPARE(replyArgs.count(), 1); + QCOMPARE(replyArgs.size(), 1); QCOMPARE(replyArgs.at(0), value); } @@ -171,10 +149,10 @@ void tst_QDBusLocalCalls::makeCallsVariant() callMsg << QVariant::fromValue(QDBusVariant(value)); QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ReplyMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ReplyMessage); QVariantList replyArgs = replyMsg.arguments(); - QCOMPARE(replyArgs.count(), 1); + QCOMPARE(replyArgs.size(), 1); const QVariant &reply = replyArgs.at(0); QCOMPARE(reply.userType(), qMetaTypeId<QDBusVariant>()); @@ -188,10 +166,10 @@ void tst_QDBusLocalCalls::makeCallsTwoRets() callMsg << (QStringList() << "One" << "Two"); QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ReplyMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ReplyMessage); QVariantList replyArgs = replyMsg.arguments(); - QCOMPARE(replyArgs.count(), 2); + QCOMPARE(replyArgs.size(), 2); QCOMPARE(replyArgs.at(0).toString(), QString::fromLatin1("One")); QCOMPARE(replyArgs.at(1).toString(), QString::fromLatin1("Two")); } @@ -208,10 +186,10 @@ void tst_QDBusLocalCalls::makeCallsComplex() callMsg << QVariant::fromValue(value); QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ReplyMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ReplyMessage); QVariantList replyArgs = replyMsg.arguments(); - QCOMPARE(replyArgs.count(), 1); + QCOMPARE(replyArgs.size(), 1); const QVariant &reply = replyArgs.at(0); QCOMPARE(reply.userType(), qMetaTypeId<QDBusArgument>()); QCOMPARE(qdbus_cast<QList<int> >(reply), value); @@ -223,10 +201,10 @@ void tst_QDBusLocalCalls::makeDelayedCalls() "/", QString(), "delayed"); QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: cannot call local method 'delayed' at object / (with signature '') on blocking mode"); QDBusMessage replyMsg = doCall(callMsg); - QCOMPARE(int(replyMsg.type()), int(QDBusMessage::ErrorMessage)); + QCOMPARE(replyMsg.type(), QDBusMessage::ErrorMessage); QDBusError error(replyMsg); - QCOMPARE(int(error.type()), int(QDBusError::InternalError)); + QCOMPARE(error.type(), QDBusError::InternalError); } void tst_QDBusLocalCalls::asyncReplySignal() 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 7a42e8f97f..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> >(); @@ -221,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; @@ -238,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; @@ -262,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; } @@ -349,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(); @@ -364,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(); @@ -386,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); @@ -400,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(); @@ -483,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); @@ -521,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; } @@ -531,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); @@ -539,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) @@ -653,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 9130f434b5..0000000000 --- a/tests/auto/dbus/qdbusmarshall/qdbusmarshall/.prev_CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Generated from qdbusmarshall.pro. - -##################################################################### -## tst_qdbusmarshall Test: -##################################################################### - -qt_add_test(tst_qdbusmarshall - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" - SOURCES - ../tst_qdbusmarshall.cpp - PUBLIC_LIBRARIES - Qt::CorePrivate - Qt::DBusPrivate -) - -## Scopes: -##################################################################### - -qt_extend_target(tst_qdbusmarshall CONDITION QT_FEATURE_dbus_linked - DEFINES - QT_LINKED_LIBDBUS - PUBLIC_LIBRARIES - dbus-1 -) - -qt_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 86ef627276..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: ##################################################################### -qt_add_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 @@ qt_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_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 ) -qt_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 28e96caf15..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: ##################################################################### -qt_add_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 b483372ead..355a65bc59 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> @@ -185,7 +161,9 @@ void basicStringTypes_data() { QTest::newRow("string") << QVariant("ping") << "s" << "\"ping\""; QTest::newRow("objectpath") << QVariant::fromValue(QDBusObjectPath("/org/kde")) << "o" << "[ObjectPath: /org/kde]"; + QTest::newRow("emptysignature") << QVariant::fromValue(QDBusSignature(QString())) << "g" << "[Signature: ]"; QTest::newRow("signature") << QVariant::fromValue(QDBusSignature("g")) << "g" << "[Signature: g]"; + QTest::newRow("multisignature") << QVariant::fromValue(QDBusSignature("bit")) << "g" << "[Signature: bit]"; QTest::newRow("emptystring") << QVariant("") << "s" << "\"\""; QTest::newRow("nullstring") << QVariant(QString()) << "s" << "\"\""; } @@ -437,7 +415,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 +478,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 +583,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 +629,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 +742,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 +771,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 +795,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 +830,7 @@ void tst_QDBusMarshall::sendArgument() { QFETCH(QVariant, value); QFETCH(QString, sig); + QFETCH(QVariant, unwrappedValue); QDBusConnection con = QDBusConnection::sessionBus(); @@ -861,8 +873,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() @@ -887,7 +909,7 @@ void tst_QDBusMarshall::sendSignalErrors() QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal to service \"\" path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid object path passed in arguments"); QVERIFY(!con.send(msg)); - QDBusSignature sig; + QDBusSignature sig(QChar(0)); msg.setArguments(QVariantList() << QVariant::fromValue(sig)); QTest::ignoreMessage(QtWarningMsg, "QDBusConnection: error: could not send signal to service \"\" path \"/foo\" interface \"local.interfaceName\" member \"signalName\": Marshalling failed: Invalid signature passed in arguments"); QVERIFY(!con.send(msg)); @@ -939,22 +961,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 +984,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" @@ -972,7 +994,7 @@ void tst_QDBusMarshall::sendCallErrors_data() << ""; QTest::newRow("invalid-signature-arg") << serviceName << objectPath << interfaceName << "ping" - << (QVariantList() << QVariant::fromValue(QDBusSignature())) + << (QVariantList() << QVariant::fromValue(QDBusSignature(QChar(0)))) << "org.freedesktop.DBus.Error.Failed" << "Marshalling failed: Invalid signature passed in arguments" << ""; @@ -1059,12 +1081,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 +1096,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); @@ -1111,8 +1133,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 @@ -1137,6 +1159,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 @@ -1197,7 +1220,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); @@ -1272,7 +1295,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()); @@ -1294,22 +1317,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 diff --git a/tests/auto/dbus/qdbusmetaobject/CMakeLists.txt b/tests/auto/dbus/qdbusmetaobject/CMakeLists.txt index 9fe730c533..2107d334e0 100644 --- a/tests/auto/dbus/qdbusmetaobject/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmetaobject/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbusmetaobject.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusmetaobject Test: ##################################################################### -qt_add_test(tst_qdbusmetaobject +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusmetaobject LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusmetaobject SOURCES tst_qdbusmetaobject.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBusPrivate ) diff --git a/tests/auto/dbus/qdbusmetaobject/qdbusmetaobject.pro b/tests/auto/dbus/qdbusmetaobject/qdbusmetaobject.pro deleted file mode 100644 index 1302263e2d..0000000000 --- a/tests/auto/dbus/qdbusmetaobject/qdbusmetaobject.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbusmetaobject -QT = core dbus-private testlib -SOURCES += tst_qdbusmetaobject.cpp diff --git a/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp b/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp index 1d2e776fca..898667d5d5 100644 --- a/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp +++ b/tests/auto/dbus/qdbusmetaobject/tst_qdbusmetaobject.cpp @@ -1,35 +1,14 @@ -/**************************************************************************** -** -** 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 <qcoreapplication.h> -#include <qmetatype.h> -#include <QtTest/QtTest> - -#include <QtDBus/QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QCoreApplication> +#include <QMetaType> +#include <QDBusArgument> +#include <QDBusMetaType> +#include <QDBusError> +#include <QDBusUnixFileDescriptor> + #include <private/qdbusmetaobject_p.h> class tst_QDBusMetaObject: public QObject @@ -418,7 +397,7 @@ void tst_QDBusMetaObject::types() QCOMPARE(constructed.isUser(), expected.isUser()); QCOMPARE(constructed.isWritable(), expected.isWritable()); QCOMPARE(constructed.typeName(), expected.typeName()); - QCOMPARE(constructed.type(), expected.type()); + QCOMPARE(constructed.metaType(), expected.metaType()); QCOMPARE(constructed.userType(), expected.userType()); } } diff --git a/tests/auto/dbus/qdbusmetatype/CMakeLists.txt b/tests/auto/dbus/qdbusmetatype/CMakeLists.txt index d4878f681c..5a1ba189fc 100644 --- a/tests/auto/dbus/qdbusmetatype/CMakeLists.txt +++ b/tests/auto/dbus/qdbusmetatype/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbusmetatype.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusmetatype Test: ##################################################################### -qt_add_test(tst_qdbusmetatype +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusmetatype LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusmetatype SOURCES tst_qdbusmetatype.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusmetatype/qdbusmetatype.pro b/tests/auto/dbus/qdbusmetatype/qdbusmetatype.pro deleted file mode 100644 index ee6f7c305d..0000000000 --- a/tests/auto/dbus/qdbusmetatype/qdbusmetatype.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbusmetatype -QT = core dbus testlib -SOURCES += tst_qdbusmetatype.cpp diff --git a/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp b/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp index 4b926dcd05..be9a240fd5 100644 --- a/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp +++ b/tests/auto/dbus/qdbusmetatype/tst_qdbusmetatype.cpp @@ -1,35 +1,11 @@ -/**************************************************************************** -** -** 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 <qcoreapplication.h> -#include <qmetatype.h> -#include <QtTest/QtTest> - -#include <QtDBus/QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QCoreApplication> +#include <QMetaType> +#include <QDBusArgument> +#include <QDBusMetaType> class tst_QDBusMetaType: public QObject { @@ -108,8 +84,6 @@ typedef QMap<int, QString> IntStringMap; typedef QMap<QString, QString> StringStringMap; typedef QMap<QString, Struct1> StringStruct1Map; -Q_DECLARE_METATYPE(QVariant::Type) - QT_BEGIN_NAMESPACE QDBusArgument &operator<<(QDBusArgument &arg, const Struct1 &) { @@ -271,6 +245,15 @@ void tst_QDBusMetaType::initTestCase() qDBusRegisterMetaType<QList<Struct3> >(); qDBusRegisterMetaType<QList<Struct4> >(); +#ifdef Q_CC_GNU_ONLY + // GCC has a defect/extension (depending on your point of view) that allows + // a template class with defaulted template parameters to match a Template + // Template Parameter (TTP) with fewer template arguments. The call below + // tries to use the template<template <typename> class Container, ...> + // template functions qdbusargument.h + qDBusRegisterMetaType<std::vector<Struct1> >(); +#endif + qDBusRegisterMetaType<Invalid0>(); qDBusRegisterMetaType<Invalid1>(); qDBusRegisterMetaType<Invalid2>(); @@ -282,79 +265,82 @@ void tst_QDBusMetaType::initTestCase() qDBusRegisterMetaType<QList<Invalid0> >(); - intStringMap = qDBusRegisterMetaType<QMap<int, QString> >(); - stringStringMap = qDBusRegisterMetaType<QMap<QString, QString> >(); - stringStruct1Map = qDBusRegisterMetaType<QMap<QString, Struct1> >(); + intStringMap = qDBusRegisterMetaType<QMap<int, QString> >().id(); + stringStringMap = qDBusRegisterMetaType<QMap<QString, QString> >().id(); + stringStruct1Map = qDBusRegisterMetaType<QMap<QString, Struct1> >().id(); } void tst_QDBusMetaType::staticTypes_data() { - QTest::addColumn<QVariant::Type>("typeId"); + QTest::addColumn<int>("typeId"); QTest::addColumn<QString>("signature"); - QTest::newRow("uchar") << QVariant::Type(QMetaType::UChar) << "y"; - QTest::newRow("bool") << QVariant::Bool << "b"; - QTest::newRow("short") << QVariant::Type(QMetaType::Short) << "n"; - QTest::newRow("ushort") << QVariant::Type(QMetaType::UShort) << "q"; - QTest::newRow("int") << QVariant::Int << "i"; - QTest::newRow("uint") << QVariant::UInt << "u"; - QTest::newRow("qlonglong") << QVariant::LongLong << "x"; - QTest::newRow("qulonglong") << QVariant::ULongLong << "t"; - QTest::newRow("double") << QVariant::Double << "d"; - QTest::newRow("QString") << QVariant::String << "s"; - QTest::newRow("QDBusObjectPath") << QVariant::Type(qMetaTypeId<QDBusObjectPath>()) << "o"; - QTest::newRow("QDBusSignature") << QVariant::Type(qMetaTypeId<QDBusSignature>()) << "g"; - QTest::newRow("QDBusVariant") << QVariant::Type(qMetaTypeId<QDBusVariant>()) << "v"; - - QTest::newRow("QByteArray") << QVariant::ByteArray << "ay"; - QTest::newRow("QStringList") << QVariant::StringList << "as"; + QTest::newRow("uchar") << int(QMetaType::UChar) << "y"; + QTest::newRow("bool") << int(QMetaType::Bool) << "b"; + QTest::newRow("short") << int(QMetaType::Short) << "n"; + QTest::newRow("ushort") << int(QMetaType::UShort) << "q"; + QTest::newRow("int") << int(QMetaType::Int) << "i"; + QTest::newRow("uint") << int(QMetaType::UInt) << "u"; + QTest::newRow("qlonglong") << int(QMetaType::LongLong) << "x"; + QTest::newRow("qulonglong") << int(QMetaType::ULongLong) << "t"; + QTest::newRow("double") << int(QMetaType::Double) << "d"; + QTest::newRow("QString") << int(QMetaType::QString) << "s"; + QTest::newRow("QDBusObjectPath") << qMetaTypeId<QDBusObjectPath>() << "o"; + QTest::newRow("QDBusSignature") << qMetaTypeId<QDBusSignature>() << "g"; + QTest::newRow("QDBusVariant") << qMetaTypeId<QDBusVariant>() << "v"; + + QTest::newRow("QByteArray") << int(QMetaType::QByteArray) << "ay"; + QTest::newRow("QStringList") << int(QMetaType::QStringList) << "as"; } void tst_QDBusMetaType::dynamicTypes_data() { - QTest::addColumn<QVariant::Type>("typeId"); + QTest::addColumn<int>("typeId"); QTest::addColumn<QString>("signature"); - QTest::newRow("QVariantList") << QVariant::List << "av"; - QTest::newRow("QVariantMap") << QVariant::Map << "a{sv}"; - QTest::newRow("QDate") << QVariant::Date << "(iii)"; - QTest::newRow("QTime") << QVariant::Time << "(iiii)"; - QTest::newRow("QDateTime") << QVariant::DateTime << "((iii)(iiii)i)"; - QTest::newRow("QRect") << QVariant::Rect << "(iiii)"; - QTest::newRow("QRectF") << QVariant::RectF << "(dddd)"; - QTest::newRow("QSize") << QVariant::Size << "(ii)"; - QTest::newRow("QSizeF") << QVariant::SizeF << "(dd)"; - QTest::newRow("QPoint") << QVariant::Point << "(ii)"; - QTest::newRow("QPointF") << QVariant::PointF << "(dd)"; - QTest::newRow("QLine") << QVariant::Line << "((ii)(ii))"; - QTest::newRow("QLineF") << QVariant::LineF << "((dd)(dd))"; - - QTest::newRow("Struct1") << QVariant::Type(qMetaTypeId<Struct1>()) << "(s)"; - QTest::newRow("QList<Struct1>") << QVariant::Type(qMetaTypeId<QList<Struct1> >()) << "a(s)"; - - QTest::newRow("Struct2") << QVariant::Type(qMetaTypeId<Struct2>()) << "(sos)"; - QTest::newRow("QList<Struct2>") << QVariant::Type(qMetaTypeId<QList<Struct2> >()) << "a(sos)"; - - QTest::newRow("QList<Struct3>") << QVariant::Type(qMetaTypeId<QList<Struct3> >()) << "a(sas)"; - QTest::newRow("Struct3") << QVariant::Type(qMetaTypeId<Struct3>()) << "(sas)"; - - QTest::newRow("Struct4") << QVariant::Type(qMetaTypeId<Struct4>()) << "(ssa(ss)sayasx)"; - QTest::newRow("QList<Struct4>") << QVariant::Type(qMetaTypeId<QList<Struct4> >()) << "a(ssa(ss)sayasx)"; - - QTest::newRow("Struct5") << QVariant::Type(qMetaTypeId<Struct5>()) << "a{sa{sv}}"; - - QTest::newRow("Struct6") << QVariant::Type(qMetaTypeId<Struct6>()) << "av"; - - QTest::newRow("QMap<int,QString>") << QVariant::Type(intStringMap) << "a{is}"; - QTest::newRow("QMap<QString,QString>") << QVariant::Type(stringStringMap) << "a{ss}"; - QTest::newRow("QMap<QString,Struct1>") << QVariant::Type(stringStruct1Map) << "a{s(s)}"; + QTest::newRow("QVariantList") << int(QMetaType::QVariantList) << "av"; + QTest::newRow("QVariantMap") << int(QMetaType::QVariantMap) << "a{sv}"; + QTest::newRow("QDate") << int(QMetaType::QDate) << "(iii)"; + QTest::newRow("QTime") << int(QMetaType::QTime) << "(iiii)"; + QTest::newRow("QDateTime") << int(QMetaType::QDateTime) << "((iii)(iiii)i)"; + QTest::newRow("QRect") << int(QMetaType::QRect) << "(iiii)"; + QTest::newRow("QRectF") << int(QMetaType::QRectF) << "(dddd)"; + QTest::newRow("QSize") << int(QMetaType::QSize) << "(ii)"; + QTest::newRow("QSizeF") << int(QMetaType::QSizeF) << "(dd)"; + QTest::newRow("QPoint") << int(QMetaType::QPoint) << "(ii)"; + QTest::newRow("QPointF") << int(QMetaType::QPointF) << "(dd)"; + QTest::newRow("QLine") << int(QMetaType::QLine) << "((ii)(ii))"; + QTest::newRow("QLineF") << int(QMetaType::QLineF) << "((dd)(dd))"; + + QTest::newRow("Struct1") << qMetaTypeId<Struct1>() << "(s)"; + QTest::newRow("QList<Struct1>") << qMetaTypeId<QList<Struct1> >() << "a(s)"; +#ifdef Q_CC_GNU_ONLY + QTest::newRow("std::vector<Struct1>") << qMetaTypeId<std::vector<Struct1> >() << "a(s)"; +#endif + + QTest::newRow("Struct2") << qMetaTypeId<Struct2>() << "(sos)"; + QTest::newRow("QList<Struct2>") << qMetaTypeId<QList<Struct2>>() << "a(sos)"; + + QTest::newRow("QList<Struct3>") << qMetaTypeId<QList<Struct3>>() << "a(sas)"; + QTest::newRow("Struct3") << qMetaTypeId<Struct3>() << "(sas)"; + + QTest::newRow("Struct4") << qMetaTypeId<Struct4>() << "(ssa(ss)sayasx)"; + QTest::newRow("QList<Struct4>") << qMetaTypeId<QList<Struct4>>() << "a(ssa(ss)sayasx)"; + + QTest::newRow("Struct5") << qMetaTypeId<Struct5>() << "a{sa{sv}}"; + + QTest::newRow("Struct6") << qMetaTypeId<Struct6>() << "av"; + + QTest::newRow("QMap<int,QString>") << intStringMap << "a{is}"; + QTest::newRow("QMap<QString,QString>") << stringStringMap << "a{ss}"; + QTest::newRow("QMap<QString,Struct1>") << stringStruct1Map << "a{s(s)}"; } void tst_QDBusMetaType::staticTypes() { - QFETCH(QVariant::Type, typeId); + QFETCH(int, typeId); - QString result = QDBusMetaType::typeToSignature(typeId); + QString result = QDBusMetaType::typeToSignature(QMetaType(typeId)); QTEST(result, "signature"); } @@ -366,43 +352,43 @@ void tst_QDBusMetaType::dynamicTypes() void tst_QDBusMetaType::invalidTypes_data() { - QTest::addColumn<QVariant::Type>("typeId"); + QTest::addColumn<int>("typeId"); QTest::addColumn<QString>("signature"); - QTest::newRow("Invalid0") << QVariant::Type(qMetaTypeId<Invalid0>()) << ""; - QTest::newRow("Invalid1") << QVariant::Type(qMetaTypeId<Invalid1>()) << ""; - QTest::newRow("Invalid2") << QVariant::Type(qMetaTypeId<Invalid2>()) << ""; - QTest::newRow("Invalid3") << QVariant::Type(qMetaTypeId<Invalid3>()) << ""; - QTest::newRow("Invalid4") << QVariant::Type(qMetaTypeId<Invalid4>()) << ""; - QTest::newRow("Invalid5") << QVariant::Type(qMetaTypeId<Invalid5>()) << ""; - QTest::newRow("Invalid6") << QVariant::Type(qMetaTypeId<Invalid6>()) << ""; - QTest::newRow("Invalid7") << QVariant::Type(qMetaTypeId<Invalid7>()) << ""; + QTest::newRow("Invalid0") << qMetaTypeId<Invalid0>() << ""; + QTest::newRow("Invalid1") << qMetaTypeId<Invalid1>() << ""; + QTest::newRow("Invalid2") << qMetaTypeId<Invalid2>() << ""; + QTest::newRow("Invalid3") << qMetaTypeId<Invalid3>() << ""; + QTest::newRow("Invalid4") << qMetaTypeId<Invalid4>() << ""; + QTest::newRow("Invalid5") << qMetaTypeId<Invalid5>() << ""; + QTest::newRow("Invalid6") << qMetaTypeId<Invalid6>() << ""; + QTest::newRow("Invalid7") << qMetaTypeId<Invalid7>() << ""; - QTest::newRow("QList<Invalid0>") << QVariant::Type(qMetaTypeId<QList<Invalid0> >()) << ""; + QTest::newRow("QList<Invalid0>") << qMetaTypeId<QList<Invalid0>>() << ""; - QTest::newRow("long") << QVariant::Type(QMetaType::Long) << ""; - QTest::newRow("void*") << QVariant::Type(QMetaType::VoidStar) << ""; + QTest::newRow("long") << int(QMetaType::Long) << ""; + QTest::newRow("void*") << int(QMetaType::VoidStar) << ""; } void tst_QDBusMetaType::invalidTypes() { // same test if (qstrcmp(QTest::currentDataTag(), "Invalid0") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid0' produces invalid D-BUS signature `<empty>' (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid0' produces invalid D-Bus signature '<empty>' (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "Invalid1") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid1' attempts to redefine basic D-BUS type 's' (QString) (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid1' attempts to redefine basic D-Bus type 's' (QString) (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "Invalid2") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid2' attempts to redefine basic D-BUS type 'o' (QDBusObjectPath) (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid2' attempts to redefine basic D-Bus type 'o' (QDBusObjectPath) (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "Invalid3") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid3' attempts to redefine basic D-BUS type 'as' (QStringList) (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid3' attempts to redefine basic D-Bus type 'as' (QStringList) (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "Invalid4") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid4' attempts to redefine basic D-BUS type 'ay' (QByteArray) (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid4' attempts to redefine basic D-Bus type 'ay' (QByteArray) (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "Invalid5") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid5' produces invalid D-BUS signature `ii' (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid5' produces invalid D-Bus signature 'ii' (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "Invalid7") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `Invalid7' produces invalid D-BUS signature `()' (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'Invalid7' produces invalid D-Bus signature '()' (Did you forget to call beginStructure() ?)"); else if (qstrcmp(QTest::currentDataTag(), "QList<Invalid0>") == 0) - QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type `QList<Invalid0>' produces invalid D-BUS signature `a' (Did you forget to call beginStructure() ?)"); + QTest::ignoreMessage(QtWarningMsg, "QDBusMarshaller: type 'QList<Invalid0>' produces invalid D-Bus signature 'a' (Did you forget to call beginStructure() ?)"); staticTypes(); staticTypes(); // run twice: the error messages should be printed once only diff --git a/tests/auto/dbus/qdbuspendingcall/CMakeLists.txt b/tests/auto/dbus/qdbuspendingcall/CMakeLists.txt index 47c4261313..4493d2364f 100644 --- a/tests/auto/dbus/qdbuspendingcall/CMakeLists.txt +++ b/tests/auto/dbus/qdbuspendingcall/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbuspendingcall.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbuspendingcall Test: ##################################################################### -qt_add_test(tst_qdbuspendingcall +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbuspendingcall LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbuspendingcall SOURCES tst_qdbuspendingcall.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbuspendingcall/qdbuspendingcall.pro b/tests/auto/dbus/qdbuspendingcall/qdbuspendingcall.pro deleted file mode 100644 index ddfe3008a5..0000000000 --- a/tests/auto/dbus/qdbuspendingcall/qdbuspendingcall.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbuspendingcall -QT = core dbus testlib -SOURCES += tst_qdbuspendingcall.cpp diff --git a/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp b/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp index 78c3fb223b..f901c7a536 100644 --- a/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp +++ b/tests/auto/dbus/qdbuspendingcall/tst_qdbuspendingcall.cpp @@ -1,37 +1,18 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include <QtCore/QObject> -#include <QtCore/QVariant> -#include <QtCore/QList> -#include <QtCore/QThread> -#include <QtTest/QtTest> -#include <QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QTestEventLoop> +#include <QObject> +#include <QVariant> +#include <QList> +#include <QThread> +#include <QDBusAbstractAdaptor> +#include <QDBusMessage> +#include <QDBusConnection> +#include <QDBusPendingCallWatcher> +#include <QDBusInterface> #define TEST_INTERFACE_NAME "org.qtproject.QtDBus.MyObject" @@ -176,10 +157,10 @@ void tst_QDBusPendingCall::waitForFinished() QCOMPARE(reply.signature(), QString("as")); const QVariantList args = ac.reply().arguments(); - QCOMPARE(args.count(), 1); + QCOMPARE(args.size(), 1); const QVariant &arg = args.at(0); - QCOMPARE(arg.type(), QVariant::StringList); + QCOMPARE(arg.userType(), QMetaType::QStringList); QVERIFY(arg.toStringList().contains(conn.baseService())); } @@ -323,7 +304,7 @@ void tst_QDBusPendingCall::watcher_waitForFinished_threaded() public: tst_QDBusPendingCall *tst; WorkerThread(tst_QDBusPendingCall *tst) : tst(tst) {} - void run() + void run() override { QDBusPendingCall ac = tst->sendMessage(); // QVERIFY(!ac.isFinished()); diff --git a/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt b/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt index 2ece3ac4bf..52e11b3dbd 100644 --- a/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt +++ b/tests/auto/dbus/qdbuspendingreply/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbuspendingreply.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbuspendingreply Test: ##################################################################### -qt_add_test(tst_qdbuspendingreply +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbuspendingreply LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbuspendingreply SOURCES tst_qdbuspendingreply.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbuspendingreply/qdbuspendingreply.pro b/tests/auto/dbus/qdbuspendingreply/qdbuspendingreply.pro deleted file mode 100644 index 814e40decc..0000000000 --- a/tests/auto/dbus/qdbuspendingreply/qdbuspendingreply.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbuspendingreply -QT = core dbus testlib -SOURCES += tst_qdbuspendingreply.cpp diff --git a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp index 2648b22f1f..da25f768d0 100644 --- a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp +++ b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp @@ -1,35 +1,15 @@ -/**************************************************************************** -** -** 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/QObject> -#include <QtCore/QVariant> -#include <QtCore/QList> -#include <QtTest/QtTest> -#include <QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QObject> +#include <QVariant> +#include <QList> +#include <QDBusArgument> +#include <QDBusInterface> +#include <QDBusMetaType> +#include <QDBusAbstractAdaptor> +#include <QDBusPendingReply> typedef QMap<int,QString> IntStringMap; Q_DECLARE_METATYPE(IntStringMap) diff --git a/tests/auto/dbus/qdbusreply/CMakeLists.txt b/tests/auto/dbus/qdbusreply/CMakeLists.txt index 5f75e52d4f..6427d92d7c 100644 --- a/tests/auto/dbus/qdbusreply/CMakeLists.txt +++ b/tests/auto/dbus/qdbusreply/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbusreply.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusreply Test: ##################################################################### -qt_add_test(tst_qdbusreply +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusreply LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusreply SOURCES tst_qdbusreply.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusreply/qdbusreply.pro b/tests/auto/dbus/qdbusreply/qdbusreply.pro deleted file mode 100644 index 42e9e6dddc..0000000000 --- a/tests/auto/dbus/qdbusreply/qdbusreply.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusreply -QT = core dbus testlib -SOURCES += tst_qdbusreply.cpp diff --git a/tests/auto/dbus/qdbusreply/tst_qdbusreply.cpp b/tests/auto/dbus/qdbusreply/tst_qdbusreply.cpp index 362cbab902..e05da43019 100644 --- a/tests/auto/dbus/qdbusreply/tst_qdbusreply.cpp +++ b/tests/auto/dbus/qdbusreply/tst_qdbusreply.cpp @@ -1,37 +1,15 @@ -/**************************************************************************** -** -** 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 <qcoreapplication.h> -#include <qdebug.h> -#include <qvariant.h> - -#include <QtTest/QtTest> - -#include <QtDBus> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QDebug> +#include <QCoreApplication> +#include <QVariant> +#include <QDBusArgument> +#include <QDBusInterface> +#include <QDBusMetaType> +#include <QDBusAbstractAdaptor> +#include <QDBusReply> typedef QMap<int,QString> IntStringMap; Q_DECLARE_METATYPE(IntStringMap) diff --git a/tests/auto/dbus/qdbusservicewatcher/CMakeLists.txt b/tests/auto/dbus/qdbusservicewatcher/CMakeLists.txt index d4b16feebd..48144cd353 100644 --- a/tests/auto/dbus/qdbusservicewatcher/CMakeLists.txt +++ b/tests/auto/dbus/qdbusservicewatcher/CMakeLists.txt @@ -1,12 +1,20 @@ -# Generated from qdbusservicewatcher.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusservicewatcher Test: ##################################################################### -qt_add_test(tst_qdbusservicewatcher +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusservicewatcher LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusservicewatcher SOURCES tst_qdbusservicewatcher.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus + Qt::TestPrivate ) diff --git a/tests/auto/dbus/qdbusservicewatcher/qdbusservicewatcher.pro b/tests/auto/dbus/qdbusservicewatcher/qdbusservicewatcher.pro deleted file mode 100644 index e689a5cfa3..0000000000 --- a/tests/auto/dbus/qdbusservicewatcher/qdbusservicewatcher.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusservicewatcher -QT = core dbus testlib -SOURCES += tst_qdbusservicewatcher.cpp diff --git a/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp b/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp index 1ba7ee51b1..741c50217f 100644 --- a/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp +++ b/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp @@ -1,35 +1,13 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include <QtDBus/QDBusServiceWatcher> -#include <QtDBus> -#include <QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QtTest/private/qpropertytesthelper_p.h> +#include <QSignalSpy> +#include <QTestEventLoop> +#include <QDBusConnection> +#include <QDBusServiceWatcher> class tst_QDBusServiceWatcher: public QObject { @@ -52,6 +30,8 @@ private slots: void disconnectedConnection(); void setConnection_data(); void setConnection(); + void bindings(); + void bindingsAutomated(); private: QString generateServiceName(); @@ -119,12 +99,12 @@ void tst_QDBusServiceWatcher::watchForCreation() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.size(), 1); QCOMPARE(spyR.at(0).at(0).toString(), registeredName); - QCOMPARE(spyU.count(), 0); + QCOMPARE(spyU.size(), 0); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QVERIFY(spyO.at(0).at(1).toString().isEmpty()); QCOMPARE(spyO.at(0).at(2).toString(), con.baseService()); @@ -142,12 +122,12 @@ void tst_QDBusServiceWatcher::watchForCreation() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.size(), 1); QCOMPARE(spyR.at(0).at(0).toString(), registeredName); - QCOMPARE(spyU.count(), 0); + QCOMPARE(spyU.size(), 0); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QVERIFY(spyO.at(0).at(1).toString().isEmpty()); QCOMPARE(spyO.at(0).at(2).toString(), con.baseService()); @@ -183,12 +163,12 @@ void tst_QDBusServiceWatcher::watchForDisappearance() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 0); + QCOMPARE(spyR.size(), 0); - QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.size(), 1); QCOMPARE(spyU.at(0).at(0).toString(), registeredName); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QCOMPARE(spyO.at(0).at(1).toString(), con.baseService()); QVERIFY(spyO.at(0).at(2).toString().isEmpty()); @@ -217,12 +197,12 @@ void tst_QDBusServiceWatcher::watchForDisappearanceUniqueConnection() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 0); + QCOMPARE(spyR.size(), 0); - QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.size(), 1); QCOMPARE(spyU.at(0).at(0).toString(), watchedName); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), watchedName); QCOMPARE(spyO.at(0).at(1).toString(), watchedName); QVERIFY(spyO.at(0).at(2).toString().isEmpty()); @@ -254,12 +234,12 @@ void tst_QDBusServiceWatcher::watchForOwnerChange() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.size(), 1); QCOMPARE(spyR.at(0).at(0).toString(), registeredName); - QCOMPARE(spyU.count(), 0); + QCOMPARE(spyU.size(), 0); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QVERIFY(spyO.at(0).at(1).toString().isEmpty()); QCOMPARE(spyO.at(0).at(2).toString(), con.baseService()); @@ -277,13 +257,13 @@ void tst_QDBusServiceWatcher::watchForOwnerChange() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.size(), 1); QCOMPARE(spyR.at(0).at(0).toString(), registeredName); - QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.size(), 1); QCOMPARE(spyU.at(0).at(0).toString(), registeredName); - QCOMPARE(spyO.count(), 2); + QCOMPARE(spyO.size(), 2); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QCOMPARE(spyO.at(0).at(1).toString(), con.baseService()); QVERIFY(spyO.at(0).at(2).toString().isEmpty()); @@ -318,12 +298,12 @@ void tst_QDBusServiceWatcher::modeChange() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.size(), 1); QCOMPARE(spyR.at(0).at(0).toString(), registeredName); - QCOMPARE(spyU.count(), 0); + QCOMPARE(spyU.size(), 0); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QVERIFY(spyO.at(0).at(1).toString().isEmpty()); QCOMPARE(spyO.at(0).at(2).toString(), con.baseService()); @@ -341,12 +321,12 @@ void tst_QDBusServiceWatcher::modeChange() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 0); + QCOMPARE(spyR.size(), 0); - QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.size(), 1); QCOMPARE(spyU.at(0).at(0).toString(), registeredName); - QCOMPARE(spyO.count(), 1); + QCOMPARE(spyO.size(), 1); QCOMPARE(spyO.at(0).at(0).toString(), registeredName); QCOMPARE(spyO.at(0).at(1).toString(), con.baseService()); QVERIFY(spyO.at(0).at(2).toString().isEmpty()); @@ -397,9 +377,9 @@ void tst_QDBusServiceWatcher::setConnection() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 1); + QCOMPARE(spyR.size(), 1); QCOMPARE(spyR.at(0).at(0).toString(), serviceName); - QCOMPARE(spyU.count(), 0); + QCOMPARE(spyU.size(), 0); // is the system bus available? if (!QDBusConnection::systemBus().isConnected()) @@ -420,11 +400,79 @@ void tst_QDBusServiceWatcher::setConnection() QTestEventLoop::instance().enterLoop(1); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(spyR.count(), 0); + QCOMPARE(spyR.size(), 0); - QCOMPARE(spyU.count(), 1); + QCOMPARE(spyU.size(), 1); QCOMPARE(spyU.at(0).at(0).toString(), watchedName); } +void tst_QDBusServiceWatcher::bindings() +{ + QString serviceName("normal"); + + QDBusConnection con(""); + QVERIFY(!con.isConnected()); + + QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration); + QProperty<QDBusServiceWatcher::WatchMode> follower; + int notificationCounter = 0; + auto connection = follower.subscribe([&]() { notificationCounter++; }); + QCOMPARE(notificationCounter, 1); + follower.setBinding([&]() { return watcher.watchMode(); }); + QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForRegistration); + QCOMPARE(notificationCounter, 2); + + watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForUnregistration); + QCOMPARE(notificationCounter, 3); + + QProperty<QDBusServiceWatcher::WatchMode> leader(QDBusServiceWatcher::WatchForRegistration); + watcher.bindableWatchMode().setBinding([&]() { return leader.value(); }); + QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForRegistration); + QCOMPARE(notificationCounter, 4); + + leader = QDBusServiceWatcher::WatchForUnregistration; + QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForUnregistration); + QCOMPARE(notificationCounter, 5); + + // check that setting a value breaks the binding + watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + QCOMPARE(notificationCounter, 5); + leader = QDBusServiceWatcher::WatchForRegistration; + QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForUnregistration); + + // check that setting the same value again does not trigger notification + watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); + QCOMPARE(notificationCounter, 5); +} + +void tst_QDBusServiceWatcher::bindingsAutomated() +{ + QString serviceName("normal"); + + QDBusConnection con(""); + QVERIFY(!con.isConnected()); + + QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration); + + QTestPrivate::testReadWritePropertyBasics<QDBusServiceWatcher, QStringList>( + watcher, + QStringList() << "foo" << "bar", + QStringList() << "bar" << "foo", + "watchedServices"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QDBusServiceWatcher::watchedServices"); + return; + } + + QTestPrivate::testReadWritePropertyBasics<QDBusServiceWatcher, + QFlags<QDBusServiceWatcher::WatchModeFlag>>( + watcher, QDBusServiceWatcher::WatchForUnregistration, + QDBusServiceWatcher::WatchForRegistration, "watchMode"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QDBusServiceWatcher::watchMode"); + return; + } +} QTEST_MAIN(tst_QDBusServiceWatcher) #include "tst_qdbusservicewatcher.moc" diff --git a/tests/auto/dbus/qdbusthreading/CMakeLists.txt b/tests/auto/dbus/qdbusthreading/CMakeLists.txt index f0a0bebb20..807e401a02 100644 --- a/tests/auto/dbus/qdbusthreading/CMakeLists.txt +++ b/tests/auto/dbus/qdbusthreading/CMakeLists.txt @@ -1,12 +1,19 @@ -# Generated from qdbusthreading.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusthreading Test: ##################################################################### -qt_add_test(tst_qdbusthreading +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusthreading LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusthreading SOURCES tst_qdbusthreading.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::DBus ) diff --git a/tests/auto/dbus/qdbusthreading/qdbusthreading.pro b/tests/auto/dbus/qdbusthreading/qdbusthreading.pro deleted file mode 100644 index 95358b2003..0000000000 --- a/tests/auto/dbus/qdbusthreading/qdbusthreading.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qdbusthreading -QT = core dbus testlib -SOURCES += tst_qdbusthreading.cpp diff --git a/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp b/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp index b4690268c8..cccf00fd6b 100644 --- a/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp +++ b/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp @@ -1,39 +1,20 @@ -/**************************************************************************** -** -** 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 <QtTest> -#include <QtDBus> -#include <QtCore/QVarLengthArray> -#include <QtCore/QThread> -#include <QtCore/QObject> -#include <QtCore/QSemaphore> -#include <QtCore/QMutex> -#include <QtCore/QWaitCondition> -#include <QtCore/QMap> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QTestEventLoop> +#include <QVarLengthArray> +#include <QThread> +#include <QObject> +#include <QSemaphore> +#include <QMutex> +#include <QWaitCondition> +#include <QMap> +#include <QDBusAbstractAdaptor> +#include <QDBusConnection> +#include <QDBusReply> +#include <QDBusConnectionInterface> +#include <QDBusInterface> class Thread : public QThread { @@ -41,7 +22,7 @@ class Thread : public QThread static int counter; public: Thread(bool automatic = true); - void run(); + void run() override; using QThread::exec; }; diff --git a/tests/auto/dbus/qdbustype/CMakeLists.txt b/tests/auto/dbus/qdbustype/CMakeLists.txt index a7d8104ec7..1a4e75f61a 100644 --- a/tests/auto/dbus/qdbustype/CMakeLists.txt +++ b/tests/auto/dbus/qdbustype/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qdbustype.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbustype Test: ##################################################################### -qt_add_test(tst_qdbustype +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbustype LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbustype SOURCES tst_qdbustype.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::DBusPrivate ) @@ -15,14 +22,14 @@ qt_add_test(tst_qdbustype ## Scopes: ##################################################################### -qt_extend_target(tst_qdbustype CONDITION QT_FEATURE_dbus_linked +qt_internal_extend_target(tst_qdbustype CONDITION QT_FEATURE_dbus_linked DEFINES QT_LINKED_LIBDBUS - PUBLIC_LIBRARIES + LIBRARIES dbus-1 ) -qt_extend_target(tst_qdbustype CONDITION NOT QT_FEATURE_dbus_linked +qt_internal_extend_target(tst_qdbustype CONDITION NOT QT_FEATURE_dbus_linked SOURCES ../../../../src/dbus/qdbus_symbols.cpp ) diff --git a/tests/auto/dbus/qdbustype/qdbustype.pro b/tests/auto/dbus/qdbustype/qdbustype.pro deleted file mode 100644 index 75a9980732..0000000000 --- a/tests/auto/dbus/qdbustype/qdbustype.pro +++ /dev/null @@ -1,10 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbustype -QT = core-private dbus-private testlib -SOURCES += tst_qdbustype.cpp -qtConfig(dbus-linked) { - DEFINES += QT_LINKED_LIBDBUS - QMAKE_USE += dbus -} else { - SOURCES += ../../../../src/dbus/qdbus_symbols.cpp -} diff --git a/tests/auto/dbus/qdbustype/tst_qdbustype.cpp b/tests/auto/dbus/qdbustype/tst_qdbustype.cpp index f475e87a2b..63cb7d4a65 100644 --- a/tests/auto/dbus/qdbustype/tst_qdbustype.cpp +++ b/tests/auto/dbus/qdbustype/tst_qdbustype.cpp @@ -1,33 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the FOO module 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 <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> #include <QtCore/QCoreApplication> #include <QtDBus/private/qdbusutil_p.h> @@ -105,7 +80,7 @@ static void addFixedTypes() static void addInvalidSingleLetterTypes() { - QChar nulString[] = { 0 }; + QChar nulString[] = { '\0' }; QTest::newRow("nul") << QString(nulString, 1) << false << false; QTest::newRow("tilde") << "~" << false << false; QTest::newRow("struct-begin") << "(" << false << false; @@ -187,7 +162,6 @@ static void addNakedDictEntry() void tst_QDBusType::isValidFixedType_data() { addColumns(); - addFixedTypes(); addBasicTypes(Invalid); addVariant(Invalid); addInvalidSingleLetterTypes(); @@ -198,7 +172,7 @@ void tst_QDBusType::isValidFixedType() QFETCH(QString, data); QFETCH(bool, result); QFETCH(bool, isValid); - QVERIFY2(data.length() == 1, "Test is malformed, this function must test only one-letter types"); + QVERIFY2(data.size() == 1, "Test is malformed, this function must test only one-letter types"); QVERIFY(isValid || (!isValid && !result)); int type = data.at(0).unicode(); @@ -220,7 +194,7 @@ void tst_QDBusType::isValidBasicType() QFETCH(QString, data); QFETCH(bool, result); QFETCH(bool, isValid); - QVERIFY2(data.length() == 1, "Test is malformed, this function must test only one-letter types"); + QVERIFY2(data.size() == 1, "Test is malformed, this function must test only one-letter types"); QVERIFY(isValid || (!isValid && !result)); int type = data.at(0).unicode(); @@ -232,6 +206,7 @@ void tst_QDBusType::isValidBasicType() void tst_QDBusType::isValidSingleSignature_data() { addColumns(); + QTest::newRow("empty") << "" << false; addSingleSignatures(); addNakedDictEntry(); } @@ -248,6 +223,7 @@ void tst_QDBusType::isValidSingleSignature() void tst_QDBusType::isValidArray_data() { addColumns(); + QTest::newRow("empty") << "" << false; addSingleSignatures(); } @@ -267,7 +243,10 @@ void tst_QDBusType::isValidArray() void tst_QDBusType::isValidSignature_data() { - isValidSingleSignature_data(); + addColumns(); + QTest::newRow("empty") << "" << true; + addSingleSignatures(); + addNakedDictEntry(); } void tst_QDBusType::isValidSignature() @@ -276,8 +255,10 @@ void tst_QDBusType::isValidSignature() QFETCH(bool, result); data.append(data); - if (data.at(0).unicode()) - QCOMPARE(bool(q_dbus_signature_validate(data.toLatin1(), 0)), result); + if (!data.isEmpty() && data.at(0).unicode()) { + // libdbus-1 API can't deal with string containing NULs + QCOMPARE(bool(q_dbus_signature_validate(data.toLatin1(), nullptr)), result); + } QCOMPARE(QDBusUtil::isValidSignature(data), result); } diff --git a/tests/auto/dbus/qdbusxmlparser/CMakeLists.txt b/tests/auto/dbus/qdbusxmlparser/CMakeLists.txt index 7390c25cb4..6d92443213 100644 --- a/tests/auto/dbus/qdbusxmlparser/CMakeLists.txt +++ b/tests/auto/dbus/qdbusxmlparser/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qdbusxmlparser.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbusxmlparser Test: ##################################################################### -qt_add_test(tst_qdbusxmlparser +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbusxmlparser LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qdbusxmlparser SOURCES tst_qdbusxmlparser.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::DBusPrivate Qt::Xml diff --git a/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro b/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro deleted file mode 100644 index d695cc998f..0000000000 --- a/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase parallel_test -TARGET = tst_qdbusxmlparser -QT = core-private dbus-private xml testlib -SOURCES += tst_qdbusxmlparser.cpp diff --git a/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp b/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp index 264dbe127f..7f1c4e933c 100644 --- a/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp +++ b/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp @@ -1,37 +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$ -** -****************************************************************************/ -/* -*- C++ -*- - */ -#include <qcoreapplication.h> -#include <qmetatype.h> -#include <QtTest/QtTest> -#include <QtDBus/QtDBus> -#include <QtXml/QDomDocument> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QCoreApplication> +#include <QDomDocument> +#include <QMetaType> +#include <QTest> #define USE_PRIVATE_CODE #include "../qdbusmarshall/common.h" @@ -59,10 +32,18 @@ private slots: void properties(); }; +static void addAnnotation(QDBusIntrospection::Annotations &annotations, const QString &name, + const QString &value) +{ + annotations.insert( + name, + QDBusIntrospection::Annotation{ QDBusIntrospection::SourceLocation{}, name, value }); +} + void tst_QDBusXmlParser::initTestCase() { - // Always initialize the hash seed to 0 to get reliable test results - qSetGlobalQHashSeed(0); + // Always initialize the hash seed with a known value to get reliable test results + QHashSeed::setDeterministicGlobalSeed(); } void tst_QDBusXmlParser::parsing_data() @@ -127,21 +108,21 @@ void tst_QDBusXmlParser::parsing_data() void tst_QDBusXmlParser::parsing_common(const QString &xmlData) { - QDBusIntrospection::Object obj = + const QDBusIntrospection::Object obj = QDBusIntrospection::parseObject(xmlData, "local.testing", "/"); QFETCH(int, interfaceCount); QFETCH(int, objectCount); QFETCH(int, annotationCount); QFETCH(QStringList, introspection); - QCOMPARE(obj.interfaces.count(), interfaceCount); - QCOMPARE(obj.childObjects.count(), objectCount); - QCOMPARE(QDBusIntrospection::parseInterface(xmlData).annotations.count(), annotationCount); + QCOMPARE(obj.interfaces.size(), interfaceCount); + QCOMPARE(obj.childObjects.size(), objectCount); + QCOMPARE(QDBusIntrospection::parseInterface(xmlData).annotations.size(), annotationCount); QDBusIntrospection::Interfaces ifaces = QDBusIntrospection::parseInterfaces(xmlData); // also verify the naming int i = 0; - foreach (QString name, obj.interfaces) { + for (const QString &name : obj.interfaces) { const QString expectedName = QString("iface.iface%1").arg(i+1); QCOMPARE(name, expectedName); @@ -151,7 +132,7 @@ void tst_QDBusXmlParser::parsing_common(const QString &xmlData) } i = 0; - foreach (QString name, obj.childObjects) + for (const QString &name : obj.childObjects) QCOMPARE(name, QString("obj%1").arg(++i)); } @@ -218,7 +199,7 @@ void tst_QDBusXmlParser::methods_data() // add a third, with annotations method.name = "Baz"; - method.annotations.insert("foo.testing", "nothing to see here"); + addAnnotation(method.annotations, "foo.testing", "nothing to see here"); map << method; QTest::newRow("method-with-annotation") << "<method name=\"Foo\"/>" @@ -317,7 +298,7 @@ void tst_QDBusXmlParser::methods_data() method = QDBusIntrospection::Method(); method.inputArgs << arg("a{sv}", "variantMap") << arg("u", "index"); method.outputArgs << arg("s", "key") << arg("v", "value"); - method.annotations.insert("foo.equivalent", "QVariantMap"); + addAnnotation(method.annotations, "foo.equivalent", "QVariantMap"); method.name = "Method2"; map << method; @@ -354,7 +335,7 @@ void tst_QDBusXmlParser::methods() QFETCH(MethodMap, methodMap); MethodMap parsedMap = iface.methods; - QCOMPARE(parsedMap.count(), methodMap.count()); + QCOMPARE(parsedMap.size(), methodMap.size()); QCOMPARE(parsedMap, methodMap); } @@ -386,7 +367,7 @@ void tst_QDBusXmlParser::signals__data() // add a third, with annotations signal.name = "Baz"; - signal.annotations.insert("foo.testing", "nothing to see here"); + addAnnotation(signal.annotations, "foo.testing", "nothing to see here"); map << signal; QTest::newRow("signal-with-annotation") << "<signal name=\"Foo\"/>" @@ -435,7 +416,7 @@ void tst_QDBusXmlParser::signals__data() // with annotation "foo.equivalent":"QVariantMap" signal = QDBusIntrospection::Signal(); signal.outputArgs << arg("s", "key") << arg("v", "value"); - signal.annotations.insert("foo.equivalent", "QVariantMap"); + addAnnotation(signal.annotations, "foo.equivalent", "QVariantMap"); signal.name = "Signal2"; map << signal; @@ -468,7 +449,7 @@ void tst_QDBusXmlParser::signals_() QFETCH(SignalMap, signalMap); SignalMap parsedMap = iface.signals_; - QCOMPARE(signalMap.count(), parsedMap.count()); + QCOMPARE(signalMap.size(), parsedMap.size()); QCOMPARE(signalMap, parsedMap); } @@ -519,8 +500,8 @@ void tst_QDBusXmlParser::properties_data() prop.name = "baz"; prop.type = "as"; prop.access = QDBusIntrospection::Property::Write; - prop.annotations.insert("foo.annotation", "Hello, World"); - prop.annotations.insert("foo.annotation2", "Goodbye, World"); + addAnnotation(prop.annotations, "foo.annotation", "Hello, World"); + addAnnotation(prop.annotations, "foo.annotation2", "Goodbye, World"); map << prop; QTest::newRow("complex") << "<property access=\"read\" type=\"i\" name=\"bar\"/>" @@ -558,7 +539,7 @@ void tst_QDBusXmlParser::properties() QFETCH(PropertyMap, propertyMap); PropertyMap parsedMap = iface.properties; - QCOMPARE(propertyMap.count(), parsedMap.count()); + QCOMPARE(propertyMap.size(), parsedMap.size()); QCOMPARE(propertyMap, parsedMap); } |