diff options
Diffstat (limited to 'tests/auto/tools/qdbuscpp2xml')
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/CMakeLists.txt | 13 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/test1.h | 6 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/test2.h | 24 | ||||
-rw-r--r-- | tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp | 103 |
4 files changed, 128 insertions, 18 deletions
diff --git a/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt b/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt index b2a53394b7..8ea0c609c0 100644 --- a/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt +++ b/tests/auto/tools/qdbuscpp2xml/CMakeLists.txt @@ -1,23 +1,29 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qdbuscpp2xml.pro. - ##################################################################### ## 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 LIBRARIES - Qt::DBus + Qt::DBusPrivate ) # Resources: set(qdbuscpp2xml_resource_files "test1.h" + "test2.h" ) qt_internal_add_resource(tst_qdbuscpp2xml "qdbuscpp2xml" @@ -27,3 +33,4 @@ qt_internal_add_resource(tst_qdbuscpp2xml "qdbuscpp2xml" ${qdbuscpp2xml_resource_files} ) +add_dependencies(tst_qdbuscpp2xml ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml) diff --git a/tests/auto/tools/qdbuscpp2xml/test1.h b/tests/auto/tools/qdbuscpp2xml/test1.h index abe1763d56..24cd939657 100644 --- a/tests/auto/tools/qdbuscpp2xml/test1.h +++ b/tests/auto/tools/qdbuscpp2xml/test1.h @@ -1,5 +1,5 @@ // 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 WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QDBUSCPP2XML_TEST1_H #define QDBUSCPP2XML_TEST1_H @@ -17,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 @@ -97,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 bb97a56651..535aa6c5a8 100644 --- a/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp +++ b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp @@ -1,13 +1,15 @@ // 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 WITH Qt-GPL-exception-1.0 +// 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 @@ -32,6 +34,8 @@ class tst_qdbuscpp2xml : public QObject private slots: void qdbuscpp2xml_data(); void qdbuscpp2xml(); + void qtdbusTypes_data(); + void qtdbusTypes(); void initTestCase(); void cleanupTestCase(); @@ -43,6 +47,7 @@ private: void tst_qdbuscpp2xml::initTestCase() { m_tests.insert("test1", new Test1); + m_tests.insert("test2", new Test2); } void tst_qdbuscpp2xml::cleanupTestCase() @@ -57,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); + } } } } @@ -125,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) @@ -141,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" |