summaryrefslogtreecommitdiffstats
path: root/tests/auto/dbus/qdbusinterface
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/dbus/qdbusinterface')
-rw-r--r--tests/auto/dbus/qdbusinterface/CMakeLists.txt21
-rw-r--r--tests/auto/dbus/qdbusinterface/myobject.h29
-rw-r--r--tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt7
-rw-r--r--tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp31
-rw-r--r--tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp148
5 files changed, 116 insertions, 120 deletions
diff --git a/tests/auto/dbus/qdbusinterface/CMakeLists.txt b/tests/auto/dbus/qdbusinterface/CMakeLists.txt
index f47d8be56b..56439f9ef6 100644
--- a/tests/auto/dbus/qdbusinterface/CMakeLists.txt
+++ b/tests/auto/dbus/qdbusinterface/CMakeLists.txt
@@ -1,7 +1,13 @@
-# 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:
@@ -14,22 +20,18 @@ qt_internal_add_test(tst_qdbusinterface
LIBRARIES
Qt::CorePrivate
Qt::DBusPrivate
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Core
Qt::DBus
)
-#### Keys ignored in scope 1:.:.:qdbusinterface.pro:<TRUE>:
-# CONFIG = "testcase"
-# DESTDIR = "./"
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qdbusinterface CONDITION QT_FEATURE_dbus_linked
DEFINES
QT_LINKED_LIBDBUS
- PUBLIC_LIBRARIES
+ LIBRARIES
dbus-1
)
@@ -38,4 +40,5 @@ qt_internal_extend_target(tst_qdbusinterface CONDITION NOT QT_FEATURE_dbus_linke
../../../../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 e6f6d4a505..355d4d3752 100644
--- a/tests/auto/dbus/qdbusinterface/myobject.h
+++ b/tests/auto/dbus/qdbusinterface/myobject.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef MYOBJECT_H
#define MYOBJECT_H
diff --git a/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt b/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt
index 5ee288169d..55eb2c39cc 100644
--- a/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt
+++ b/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmyserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qmyserver_qdbusinterface Binary:
@@ -6,10 +7,10 @@
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 f7a935b1ba..5d8692d9a6 100644
--- a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp
+++ b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** 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 <QCoreApplication>
#include <QDBusServer>
diff --git a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp
index c02c6c82b0..803ae4fa0f 100644
--- a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp
+++ b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.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 <QTest>
#include <QDebug>
@@ -45,6 +20,8 @@
#include "../qdbusmarshall/common.h"
#include "myobject.h"
+using namespace Qt::StringLiterals;
+
#define TEST_INTERFACE_NAME "org.qtproject.QtDBus.MyObject"
#define TEST_SIGNAL_NAME "somethingHappened"
@@ -223,6 +200,10 @@ private slots:
void complexPropertyWritePeer();
void interactiveAuthorizationRequired();
+
+ void interfaceNameFallback_data();
+ void interfaceNameFallback();
+
private:
QProcess proc;
};
@@ -331,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()
@@ -486,14 +474,14 @@ 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().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().userType(), QMetaType::QString);
@@ -505,14 +493,14 @@ 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().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().userType(), QMetaType::QString);
@@ -533,7 +521,7 @@ 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().userType(), QMetaType::QString);
@@ -545,7 +533,7 @@ 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().userType(), QMetaType::QString);
@@ -567,7 +555,7 @@ 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().userType(), QMetaType::QString);
@@ -582,7 +570,7 @@ 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().userType(), QMetaType::QString);
@@ -611,7 +599,7 @@ 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().userType(), QMetaType::QString);
@@ -636,7 +624,7 @@ 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().userType(), QMetaType::QString);
@@ -667,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);
@@ -681,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);
@@ -721,14 +709,14 @@ 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().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().userType(), QMetaType::QString);
@@ -741,14 +729,14 @@ 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().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().userType(), QMetaType::QString);
@@ -770,7 +758,7 @@ 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().userType(), QMetaType::QString);
@@ -783,7 +771,7 @@ 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().userType(), QMetaType::QString);
@@ -806,7 +794,7 @@ 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().userType(), QMetaType::QString);
@@ -822,7 +810,7 @@ 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().userType(), QMetaType::QString);
@@ -852,7 +840,7 @@ 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().userType(), QMetaType::QString);
@@ -878,7 +866,7 @@ 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().userType(), QMetaType::QString);
@@ -910,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);
@@ -925,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);
@@ -1027,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);
}
@@ -1090,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);
}
@@ -1165,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"