diff options
Diffstat (limited to 'tests/auto/dbus/qdbusinterface')
5 files changed, 69 insertions, 13 deletions
diff --git a/tests/auto/dbus/qdbusinterface/CMakeLists.txt b/tests/auto/dbus/qdbusinterface/CMakeLists.txt index 206bea231a..56439f9ef6 100644 --- a/tests/auto/dbus/qdbusinterface/CMakeLists.txt +++ b/tests/auto/dbus/qdbusinterface/CMakeLists.txt @@ -1,10 +1,13 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qdbusinterface.pro. +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: @@ -22,10 +25,6 @@ qt_internal_add_test(tst_qdbusinterface Qt::DBus ) -#### Keys ignored in scope 1:.:.:qdbusinterface.pro:<TRUE>: -# CONFIG = "testcase" -# DESTDIR = "./" - ## Scopes: ##################################################################### @@ -43,4 +42,3 @@ qt_internal_extend_target(tst_qdbusinterface CONDITION NOT QT_FEATURE_dbus_linke add_dependencies(tst_qdbusinterface qmyserver_qdbusinterface) -# special case end diff --git a/tests/auto/dbus/qdbusinterface/myobject.h b/tests/auto/dbus/qdbusinterface/myobject.h index d1a74517b9..355d4d3752 100644 --- a/tests/auto/dbus/qdbusinterface/myobject.h +++ b/tests/auto/dbus/qdbusinterface/myobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// 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 1b51b1abfe..55eb2c39cc 100644 --- a/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt +++ b/tests/auto/dbus/qdbusinterface/qmyserver/CMakeLists.txt @@ -1,15 +1,13 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qmyserver.pro. - ##################################################################### ## qmyserver_qdbusinterface Binary: ##################################################################### qt_internal_add_executable(qmyserver_qdbusinterface OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - NO_INSTALL # special case + NO_INSTALL SOURCES ../myobject.h qmyserver.cpp diff --git a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp index 886f02d799..5d8692d9a6 100644 --- a/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp +++ b/tests/auto/dbus/qdbusinterface/qmyserver/qmyserver.cpp @@ -1,6 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 Intel Corporation. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// 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 d4b61d27dd..803ae4fa0f 100644 --- a/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp +++ b/tests/auto/dbus/qdbusinterface/tst_qdbusinterface.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QDebug> @@ -20,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" @@ -198,6 +200,10 @@ private slots: void complexPropertyWritePeer(); void interactiveAuthorizationRequired(); + + void interfaceNameFallback_data(); + void interfaceNameFallback(); + private: QProcess proc; }; @@ -1147,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" |