From 72367b1679f8176c8f8a2a424a1c9325433dd8cd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 8 Mar 2012 23:43:28 +0100 Subject: Bootstrap qdbuscpp2xml. This involves invoking the Moc classes directly and using the data structures it provides instead of invoking the moc exectutable and parsing the generated code. Change-Id: Ia5c654e8ef58d52d0d3376252c13e13885f80da3 Reviewed-by: Thiago Macieira --- tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro | 11 ++ tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc | 5 + tests/auto/tools/qdbuscpp2xml/test1.h | 128 +++++++++++++++ tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp | 181 +++++++++++++++++++++ tests/auto/tools/tools.pro | 1 + 5 files changed, 326 insertions(+) create mode 100644 tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro create mode 100644 tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc create mode 100644 tests/auto/tools/qdbuscpp2xml/test1.h create mode 100644 tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp (limited to 'tests/auto') diff --git a/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro new file mode 100644 index 0000000000..4217d5e73c --- /dev/null +++ b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +QT = core testlib dbus +TARGET = tst_qdbuscpp2xml + +QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS + +SOURCES += tst_qdbuscpp2xml.cpp \ + +RESOURCES += qdbuscpp2xml.qrc + +HEADERS += test1.h \ No newline at end of file diff --git a/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc new file mode 100644 index 0000000000..b4cffb842e --- /dev/null +++ b/tests/auto/tools/qdbuscpp2xml/qdbuscpp2xml.qrc @@ -0,0 +1,5 @@ + + + test1.h + + diff --git a/tests/auto/tools/qdbuscpp2xml/test1.h b/tests/auto/tools/qdbuscpp2xml/test1.h new file mode 100644 index 0000000000..35dee2cc38 --- /dev/null +++ b/tests/auto/tools/qdbuscpp2xml/test1.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDBUSCPP2XML_TEST1_H +#define QDBUSCPP2XML_TEST1_H + +#include + +class QDBusObjectPath; +class QDBusUnixFileDescriptor; +class QDBusSignature; + +class Test1 : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.qtProject.qdbuscpp2xmlTests.Test1") + Q_PROPERTY(int numProperty1 READ numProperty1 CONSTANT) + Q_PROPERTY(int numProperty2 READ numProperty2 WRITE setNumProperty2) +public: + Test1(QObject *parent = 0) : QObject(parent) {} + + int numProperty1() { return 42; } + + int numProperty2() { return 42; } + void setNumProperty2(int) {} + +signals: + void signalVoidType(); + int signalIntType(); + void signal_primitive_args(int a1, bool a2, short a3, ushort a4, uint a5, qlonglong a6, double a7, qlonglong a8 = 0); + void signal_string_args(const QByteArray &ba, const QString &a2); + void signal_Qt_args1(const QDate &a1, const QTime &a2, const QDateTime &a3, + const QRect &a4, const QRectF &a5, const QSize &a6, const QSizeF &a7); + void signal_Qt_args2(const QPoint &a1, const QPointF &a2, const QLine &a3, const QLineF &a4, + const QVariantList &a5, const QVariantMap &a6, const QVariantHash &a7); + + void signal_QDBus_args(const QDBusObjectPath &a1, const QDBusSignature &a2, const QDBusUnixFileDescriptor &a3); + + void signal_container_args1(const QList &a1, const QList &a2, const QList &a3, const QList &a4, const QList &a5); + void signal_container_args2(const QList &a1, const QList &a2, const QList &a3, const QList &a4, const QList &a5, const QList &a6); + + Q_SCRIPTABLE void signalVoidType_scriptable(); + Q_SCRIPTABLE int signalIntType_scriptable(); + Q_SCRIPTABLE void signal_primitive_args_scriptable(int a1, bool a2, short a3, ushort a4, uint a5, qlonglong a6, double a7, qlonglong a8 = 0); + Q_SCRIPTABLE void signal_string_args_scriptable(const QByteArray &ba, const QString &a2); + Q_SCRIPTABLE void signal_Qt_args1_scriptable(const QDate &a1, const QTime &a2, const QDateTime &a3, + const QRect &a4, const QRectF &a5, const QSize &a6, const QSizeF &a7); + Q_SCRIPTABLE void signal_Qt_args2_scriptable(const QPoint &a1, const QPointF &a2, const QLine &a3, const QLineF &a4, + const QVariantList &a5, const QVariantMap &a6, const QVariantHash &a7); + + Q_SCRIPTABLE void signal_QDBus_args_scriptable(const QDBusObjectPath &a1, const QDBusSignature &a2, const QDBusUnixFileDescriptor &a3); + + Q_SCRIPTABLE void signal_container_args1_scriptable(const QList &a1, const QList &a2, const QList &a3, const QList &a4, const QList &a5); + Q_SCRIPTABLE void signal_container_args2_scriptable(const QList &a1, const QList &a2, const QList &a3, const QList &a4, const QList &a5, const QList &a6); + +public slots: + void slotVoidType() {} + int slotIntType() { return 42; } + + Q_SCRIPTABLE void slotVoidType_scriptable() {} + Q_SCRIPTABLE int slotIntType_scriptable() { return 42; } + +protected slots: + void neverExported1() {} + int neverExported2() { return 42; } + + Q_SCRIPTABLE void neverExported3() {} + Q_SCRIPTABLE int neverExported4() { return 42; } + +private slots: + void neverExported5() {} + int neverExported6() { return 42; } + + Q_SCRIPTABLE void neverExported7() {} + Q_SCRIPTABLE int neverExported8() { return 42; } + +public: + Q_SCRIPTABLE void methodVoidType() {} + Q_SCRIPTABLE int methodIntType() { return 42; } + +protected: + Q_SCRIPTABLE void neverExported9() {} + Q_SCRIPTABLE int neverExported10() { return 42; } + +private: + Q_SCRIPTABLE void neverExported11() {} + Q_SCRIPTABLE int neverExported12() { return 42; } +}; + +#endif diff --git a/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp new file mode 100644 index 0000000000..5510c656e1 --- /dev/null +++ b/tests/auto/tools/qdbuscpp2xml/tst_qdbuscpp2xml.cpp @@ -0,0 +1,181 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include "test1.h" + +#include + +// in qdbusxmlgenerator.cpp +QT_BEGIN_NAMESPACE +extern Q_DBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface, + const QMetaObject *mo, + const QMetaObject *base, + int flags); +QT_END_NAMESPACE + +static QString addXmlHeader(const QString &input) +{ + return + "\n" + + (input.isEmpty() ? QString() : QString("\n " + input.trimmed())) + + "\n\n"; +} + +class tst_qdbuscpp2xml : public QObject +{ + Q_OBJECT + +private slots: + void qdbuscpp2xml_data(); + void qdbuscpp2xml(); + + void initTestCase(); + void cleanupTestCase(); + +private: + QHash m_tests; +}; + +void tst_qdbuscpp2xml::initTestCase() +{ + m_tests.insert("test1", new Test1); +} + +void tst_qdbuscpp2xml::cleanupTestCase() +{ + qDeleteAll(m_tests); +} + +void tst_qdbuscpp2xml::qdbuscpp2xml_data() +{ + QTest::addColumn("inputfile"); + QTest::addColumn("flags"); + + QBitArray doneFlags(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); + } + } +} + +void tst_qdbuscpp2xml::qdbuscpp2xml() +{ + QFETCH(QString, inputfile); + QFETCH(int, flags); + + // qdbuscpp2xml considers these equivalent + if (flags & QDBusConnection::ExportScriptableSlots) + flags |= QDBusConnection::ExportScriptableInvokables; + if (flags & QDBusConnection::ExportNonScriptableSlots) + flags |= QDBusConnection::ExportNonScriptableInvokables; + + if (flags & QDBusConnection::ExportScriptableInvokables) + flags |= QDBusConnection::ExportScriptableSlots; + if (flags & QDBusConnection::ExportNonScriptableInvokables) + flags |= QDBusConnection::ExportNonScriptableSlots; + + QStringList options; + if (flags & QDBusConnection::ExportScriptableProperties) { + if (flags & QDBusConnection::ExportNonScriptableProperties) + options << "-P"; + else + options << "-p"; + } + if (flags & QDBusConnection::ExportScriptableSignals) { + if (flags & QDBusConnection::ExportNonScriptableSignals) + options << "-S"; + else + options << "-s"; + } + if (flags & QDBusConnection::ExportScriptableSlots) { + if (flags & QDBusConnection::ExportNonScriptableSlots) + options << "-M"; + else + options << "-m"; + } + + // Launch + const QString command = QLatin1String("qdbuscpp2xml"); + QProcess process; + process.start(command, QStringList() << options << (QFINDTESTDATA(inputfile + QStringLiteral(".h")))); + if (!process.waitForFinished()) { + 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)); + } + const QChar cr = QLatin1Char('\r'); + const QString err = QString::fromLocal8Bit(process.readAllStandardError()).remove(cr); + const QString out = QString::fromAscii(process.readAllStandardOutput()).remove(cr); + + if (!err.isEmpty()) { + qDebug() << "UNEXPECTED STDERR CONTENTS: " << err; + QFAIL("UNEXPECTED STDERR CONTENTS"); + } + + const QChar nl = QLatin1Char('\n'); + const QStringList actualLines = out.split(nl); + + QObject *testObject = m_tests.value(inputfile); + + if (flags == 0) + flags = QDBusConnection::ExportScriptableContents + | QDBusConnection::ExportNonScriptableContents; + + QString expected = qDBusGenerateMetaObjectXml(QString(), testObject->metaObject(), &QObject::staticMetaObject, flags); + + expected = addXmlHeader(expected); + + QCOMPARE(out, expected); +} + +QTEST_APPLESS_MAIN(tst_qdbuscpp2xml) + +#include "tst_qdbuscpp2xml.moc" diff --git a/tests/auto/tools/tools.pro b/tests/auto/tools/tools.pro index 6bf6ddf64f..0a2821773f 100644 --- a/tests/auto/tools/tools.pro +++ b/tests/auto/tools/tools.pro @@ -5,3 +5,4 @@ SUBDIRS=\ moc \ rcc \ +contains(QT_CONFIG, dbus):SUBDIRS += qdbuscpp2xml -- cgit v1.2.3