diff options
Diffstat (limited to 'tests/auto/tools/qdbuscpp2xml')
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/CMakeLists.txt | 15 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc | 5 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/test1.h | 33 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/test2.h | 24 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp | 130 |
5 files changed, 132 insertions, 75 deletions
diff --git a/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt b/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt index ad2d289eb4..9dea3f3c4d 100644 --- a/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt +++ b/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt @@ -1,20 +1,29 @@ -# Generated from qdbuscpp2xml.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qdbuscpp2xml Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qdbuscpp2xml LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qdbuscpp2xml SOURCES test1.h + test2.h tst_qdbuscpp2xml.cpp - PUBLIC_LIBRARIES - Qt::DBus + LIBRARIES + Qt::DBusPrivate ) # Resources: set(qdbuscpp2xml_resource_files "test1.h" + "test2.h" ) qt_internal_add_resource(tst_qdbuscpp2xml "qdbuscpp2xml" diff --git a/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc deleted file mode 100644 index b4cffb842e..0000000000 --- a/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/tst_qdbuscpp2xml/"> - <file>test1.h</file> -</qresource> -</RCC> diff --git a/tests/auto/tools/qdbuscpp2xml/test1.h b/tests/auto/tools/qdbuscpp2xml/test1.h index 69f3a2cadc..24cd939657 100644 --- a/tests/auto/tools/qdbuscpp2xml/test1.h +++ b/tests/auto/tools/qdbuscpp2xml/test1.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -** 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) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QDBUSCPP2XML_TEST1_H #define QDBUSCPP2XML_TEST1_H @@ -42,6 +17,7 @@ class Test1 : public QObject Q_CLASSINFO("D-Bus Interface", "org.qtProject.qdbuscpp2xmlTests.Test1") Q_PROPERTY(int numProperty1 READ numProperty1 CONSTANT) Q_PROPERTY(int numProperty2 READ numProperty2 WRITE setNumProperty2) + Q_PROPERTY(int numProperty3 MEMBER m_numProperty3) Q_ENUMS(Salaries) public: // C++1y allows use of single quote as a digit separator, useful for large @@ -122,6 +98,9 @@ protected: private: Q_SCRIPTABLE void neverExported11() {} Q_SCRIPTABLE int neverExported12() { return 42; } + +private: + int m_numProperty3; }; #endif diff --git a/tests/auto/tools/qdbuscpp2xml/test2.h b/tests/auto/tools/qdbuscpp2xml/test2.h new file mode 100644 index 0000000000..b90820ad38 --- /dev/null +++ b/tests/auto/tools/qdbuscpp2xml/test2.h @@ -0,0 +1,24 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#ifndef TEST2_H +#define TEST2_H + +#include <QObject> +#include <QtDBus/QtDBus> + +// Regression test for QTBUG-34550 +class Test2 : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "net.company.object") + Q_PROPERTY(QDBusObjectPath objectProperty READ objectProperty) + Q_PROPERTY(QList<QDBusObjectPath> objectPropertyList READ objectPropertyList) +public: + Test2(QObject *parent = nullptr) : QObject(parent) { } + + QDBusObjectPath objectProperty() { return {}; } + + QList<QDBusObjectPath> objectPropertyList() { return {}; } +}; + +#endif // TEST2_H diff --git a/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp index 90d91b9848..535aa6c5a8 100644 --- a/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp +++ b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp @@ -1,38 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -** 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) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QLibraryInfo> #include <QProcess> -#include "test1.h" - #include <QtDBus/QDBusConnection> +#include <QtDBus/private/dbus_minimal_p.h> + +#include "test1.h" +#include "test2.h" // in qdbusxmlgenerator.cpp QT_BEGIN_NAMESPACE @@ -57,6 +34,8 @@ class tst_qdbuscpp2xml : public QObject private slots: void qdbuscpp2xml_data(); void qdbuscpp2xml(); + void qtdbusTypes_data(); + void qtdbusTypes(); void initTestCase(); void cleanupTestCase(); @@ -68,6 +47,7 @@ private: void tst_qdbuscpp2xml::initTestCase() { m_tests.insert("test1", new Test1); + m_tests.insert("test2", new Test2); } void tst_qdbuscpp2xml::cleanupTestCase() @@ -82,14 +62,16 @@ void tst_qdbuscpp2xml::qdbuscpp2xml_data() QBitArray doneFlags(int(QDBusConnection::ExportAllContents) + 1); for (int flag = 0x10; flag < QDBusConnection::ExportScriptableContents; flag += 0x10) { - QTest::newRow("xmlgenerator-" + QByteArray::number(flag)) << "test1" << flag; - doneFlags.setBit(flag); - for (int mask = QDBusConnection::ExportAllSlots; mask <= QDBusConnection::ExportAllContents; mask += 0x110) { - int flags = flag | mask; - if (doneFlags.testBit(flags)) - continue; - QTest::newRow("xmlgenerator-" + QByteArray::number(flags)) << "test1" << flags; - doneFlags.setBit(flags); + for (const auto &testFile : m_tests.keys()) { + QTest::newRow("xmlgenerator-" + QByteArray::number(flag) + "-" + qUtf8Printable(testFile)) << testFile << flag; + doneFlags.setBit(flag); + for (int mask = QDBusConnection::ExportAllSlots; mask <= QDBusConnection::ExportAllContents; mask += 0x110) { + int flags = flag | mask; + if (doneFlags.testBit(flags)) + continue; + QTest::newRow("xmlgenerator-" + QByteArray::number(flags) + "-" + qUtf8Printable(testFile)) << testFile << flags; + doneFlags.setBit(flags); + } } } } @@ -150,9 +132,6 @@ void tst_qdbuscpp2xml::qdbuscpp2xml() QFAIL("UNEXPECTED STDERR CONTENTS"); } - const QChar nl = QLatin1Char('\n'); - const QStringList actualLines = out.split(nl); - QObject *testObject = m_tests.value(inputfile); if (flags == 0) @@ -166,6 +145,77 @@ void tst_qdbuscpp2xml::qdbuscpp2xml() QCOMPARE(out, expected); } +void tst_qdbuscpp2xml::qtdbusTypes_data() +{ + QTest::addColumn<QByteArray>("type"); + QTest::addColumn<QByteArray>("expectedSignature"); + auto addRow = [](QByteArray type, QByteArray signature) { + QTest::addRow("%s", type.constData()) << type << signature; + + // lists and vectors + QTest::addRow("QList-%s", type.constData()) + << "QList<" + type + '>' << DBUS_TYPE_ARRAY + signature; + QTest::addRow("QVector-%s", type.constData()) + << "QVector<" + type + '>' << DBUS_TYPE_ARRAY + signature; + }; + addRow("QDBusVariant", DBUS_TYPE_VARIANT_AS_STRING); + addRow("QDBusObjectPath", DBUS_TYPE_OBJECT_PATH_AS_STRING); + addRow("QDBusSignature", DBUS_TYPE_SIGNATURE_AS_STRING); + addRow("QDBusUnixFileDescriptor", DBUS_TYPE_UNIX_FD_AS_STRING); + + // QDBusMessage is not a type, but must be recognized + QTest::newRow("QDBusMessage") << QByteArray("QDBusMessage") << QByteArray(); +} + +void tst_qdbuscpp2xml::qtdbusTypes() +{ + static const char cppSkeleton[] = R"( +class QDBusVariantBugRepro : public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.qtproject.test") +public Q_SLOTS: + void method(const @TYPE@ &); +};)"; + static const char methodXml[] = R"(<method name="method")"; + static const char expectedSkeleton[] = R"(<arg type="@S@" direction="in"/>)"; + + QFETCH(QByteArray, type); + QFETCH(QByteArray, expectedSignature); + + const QString binpath = QLibraryInfo::path(QLibraryInfo::BinariesPath); + const QString command = binpath + QLatin1String("/qdbuscpp2xml"); + QProcess process; + process.start(command); + + process.write(QByteArray(cppSkeleton).replace("@TYPE@", type)); + process.closeWriteChannel(); + + if (!process.waitForStarted()) { + const QString path = QString::fromLocal8Bit(qgetenv("PATH")); + QString message = QString::fromLatin1("'%1' could not be found when run from '%2'. Path: '%3' "). + arg(command, QDir::currentPath(), path); + QFAIL(qPrintable(message)); + } + QVERIFY2(process.waitForFinished(), qPrintable(process.errorString())); + + // verify nothing was printed on stderr + QCOMPARE(process.readAllStandardError(), QString()); + + // we don't do a full XML parsing here... + QByteArray output = process.readAll().simplified(); + QVERIFY2(output.contains("<node>") && output.contains("</node>"), "Output was: " + output); + output = output.mid(output.indexOf("<node>") + strlen("<node>")); + output = output.left(output.indexOf("</node>")); + + QVERIFY2(output.contains(methodXml), "Output was: " + output); + + if (!expectedSignature.isEmpty()) { + QByteArray expected = QByteArray(expectedSkeleton).replace("@S@", expectedSignature); + QVERIFY2(output.contains(expected), "Expected: '" + expected + "'; got: '" + output + '\''); + } +} + QTEST_APPLESS_MAIN(tst_qdbuscpp2xml) #include "tst_qdbuscpp2xml.moc" |