diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2012-11-30 11:51:05 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-11 07:41:49 +0100 |
commit | 5b3e7c8dfa4856b04013ace24d19bbd104dc3bd0 (patch) | |
tree | dbaf1fa3c3ecf623b99807bc18c90e57de535991 /tests/auto/dbus | |
parent | fac02ddc39145963646ad0f36b9e41573e49e6c5 (diff) |
Generate the introspection string during parsing
Commit 0696071316b3dacb8d1ca15a269e4f4215642b9d moved away from QDom but
also lost the ability to fill the introspection field of the created
QDBusIntrospection::Interface instances. This commit now generate the
string again as we proceed with the QXmlStreamReader based parsing.
Task-number: QTBUG-26668
Change-Id: I8f406e1f4e9d3e667a8557db69da36cac369ba4f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/dbus')
-rw-r--r-- | tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro | 2 | ||||
-rw-r--r-- | tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp | 99 |
2 files changed, 72 insertions, 29 deletions
diff --git a/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro b/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro index 4b3415612a..a7186c341b 100644 --- a/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro +++ b/tests/auto/dbus/qdbusxmlparser/qdbusxmlparser.pro @@ -1,5 +1,5 @@ CONFIG += testcase TARGET = tst_qdbusxmlparser -QT = core-private dbus-private testlib +QT = core-private dbus-private xml testlib SOURCES += tst_qdbusxmlparser.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp b/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp index 5f03600b89..35cf989753 100644 --- a/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp +++ b/tests/auto/dbus/qdbusxmlparser/tst_qdbusxmlparser.cpp @@ -44,6 +44,7 @@ #include <qmetatype.h> #include <QtTest/QtTest> #include <QtDBus/QtDBus> +#include <QtXml/QDomDocument> #define USE_PRIVATE_CODE #include "../qdbusmarshall/common.h" @@ -54,6 +55,7 @@ class tst_QDBusXmlParser: public QObject private: void parsing_common(const QString&); + QString clean_xml(const QString&); private slots: void parsing_data(); @@ -75,36 +77,58 @@ void tst_QDBusXmlParser::parsing_data() QTest::addColumn<int>("interfaceCount"); QTest::addColumn<int>("objectCount"); QTest::addColumn<int>("annotationCount"); + QTest::addColumn<QStringList>("introspection"); - QTest::newRow("null") << QString() << 0 << 0 << 0; - QTest::newRow("empty") << QString("") << 0 << 0 << 0; + QStringList introspection; + + QTest::newRow("null") << QString() << 0 << 0 << 0 << introspection; + QTest::newRow("empty") << QString("") << 0 << 0 << 0 << introspection; - QTest::newRow("junk") << "<junk/>" << 0 << 0 << 0; + QTest::newRow("junk") << "<junk/>" << 0 << 0 << 0 << introspection; QTest::newRow("interface-inside-junk") << "<junk><interface name=\"iface.iface1\" /></junk>" - << 0 << 0 << 0; + << 0 << 0 << 0 << introspection; QTest::newRow("object-inside-junk") << "<junk><node name=\"obj1\" /></junk>" - << 0 << 0 << 0; + << 0 << 0 << 0 << introspection; - QTest::newRow("zero-interfaces") << "<node/>" << 0 << 0 << 0; - QTest::newRow("one-interface") << "<node><interface name=\"iface.iface1\" /></node>" << 1 << 0 << 0; + QTest::newRow("zero-interfaces") << "<node/>" << 0 << 0 << 0 << introspection; - + introspection << "<interface name=\"iface.iface1\"/>"; + QTest::newRow("one-interface") << "<node><interface name=\"iface.iface1\" /></node>" + << 1 << 0 << 0 << introspection; + introspection.clear(); + + introspection << "<interface name=\"iface.iface1\"/>" + << "<interface name=\"iface.iface2\"/>"; QTest::newRow("two-interfaces") << "<node><interface name=\"iface.iface1\" />" "<interface name=\"iface.iface2\" /></node>" - << 2 << 0 << 0; + << 2 << 0 << 0 << introspection; + introspection.clear(); - QTest::newRow("one-object") << "<node><node name=\"obj1\"/></node>" << 0 << 1 << 0; - QTest::newRow("two-objects") << "<node><node name=\"obj1\"/><node name=\"obj2\"/></node>" << 0 << 2 << 0; + QTest::newRow("one-object") << "<node><node name=\"obj1\"/></node>" + << 0 << 1 << 0 << introspection; + QTest::newRow("two-objects") << "<node><node name=\"obj1\"/><node name=\"obj2\"/></node>" + << 0 << 2 << 0 << introspection; - QTest::newRow("i1o1") << "<node><interface name=\"iface.iface1\"/><node name=\"obj1\"/></node>" << 1 << 1 << 0; + introspection << "<interface name=\"iface.iface1\"/>"; + QTest::newRow("i1o1") << "<node><interface name=\"iface.iface1\"/><node name=\"obj1\"/></node>" + << 1 << 1 << 0 << introspection; + introspection.clear(); + introspection << "<interface name=\"iface.iface1\">" + " <annotation name=\"foo.testing\" value=\"nothing to see here\"/>" + "</interface>"; QTest::newRow("one-interface-annotated") << "<node><interface name=\"iface.iface1\">" "<annotation name=\"foo.testing\" value=\"nothing to see here\" />" - "</interface></node>" << 1 << 0 << 1; + "</interface></node>" << 1 << 0 << 1 << introspection; + introspection.clear(); + + + introspection << "<interface name=\"iface.iface1\"/>"; QTest::newRow("one-interface-docnamespace") << "<?xml version=\"1.0\" xmlns:doc=\"foo\" ?><node>" "<interface name=\"iface.iface1\"><doc:something />" - "</interface></node>" << 1 << 0 << 0; + "</interface></node>" << 1 << 0 << 0 << introspection; + introspection.clear(); } void tst_QDBusXmlParser::parsing_common(const QString &xmlData) @@ -114,20 +138,36 @@ void tst_QDBusXmlParser::parsing_common(const QString &xmlData) QFETCH(int, interfaceCount); QFETCH(int, objectCount); QFETCH(int, annotationCount); + QFETCH(QStringList, introspection); QCOMPARE(obj.interfaces.count(), interfaceCount); QCOMPARE(obj.childObjects.count(), objectCount); QCOMPARE(QDBusIntrospection::parseInterface(xmlData).annotations.count(), annotationCount); + QDBusIntrospection::Interfaces ifaces = QDBusIntrospection::parseInterfaces(xmlData); + // also verify the naming int i = 0; - foreach (QString name, obj.interfaces) - QCOMPARE(name, QString("iface.iface%1").arg(++i)); + foreach (QString name, obj.interfaces) { + const QString expectedName = QString("iface.iface%1").arg(i+1); + QCOMPARE(name, expectedName); + + const QString expectedIntrospection = clean_xml(introspection.at(i++)); + const QString resultIntrospection = clean_xml(ifaces.value(expectedName)->introspection); + QCOMPARE(resultIntrospection, expectedIntrospection); + } i = 0; foreach (QString name, obj.childObjects) QCOMPARE(name, QString("obj%1").arg(++i)); } +QString tst_QDBusXmlParser::clean_xml(const QString &xmlData) +{ + QDomDocument dom; + dom.setContent(xmlData); + return dom.toString(); +} + void tst_QDBusXmlParser::parsing() { QFETCH(QString, xmlData); @@ -304,10 +344,10 @@ void tst_QDBusXmlParser::methods_data() void tst_QDBusXmlParser::methods() { - QString xmlHeader = "<node>" - "<interface name=\"iface.iface1\">", - xmlFooter = "</interface>" - "</node>"; + QString intHeader = "<interface name=\"iface.iface1\">", + intFooter = "</interface>", + xmlHeader = "<node>" + intHeader, + xmlFooter = intFooter + "</node>"; QFETCH(QString, xmlDataFragment); @@ -315,6 +355,7 @@ void tst_QDBusXmlParser::methods() QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); QCOMPARE(iface.name, QString("iface.iface1")); + QCOMPARE(clean_xml(iface.introspection), clean_xml(intHeader + xmlDataFragment + intFooter)); QFETCH(MethodMap, methodMap); MethodMap parsedMap = iface.methods; @@ -417,10 +458,10 @@ void tst_QDBusXmlParser::signals__data() void tst_QDBusXmlParser::signals_() { - QString xmlHeader = "<node>" - "<interface name=\"iface.iface1\">", - xmlFooter = "</interface>" - "</node>"; + QString intHeader = "<interface name=\"iface.iface1\">", + intFooter = "</interface>", + xmlHeader = "<node>" + intHeader, + xmlFooter = intFooter + "</node>"; QFETCH(QString, xmlDataFragment); @@ -428,6 +469,7 @@ void tst_QDBusXmlParser::signals_() QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); QCOMPARE(iface.name, QString("iface.iface1")); + QCOMPARE(clean_xml(iface.introspection), clean_xml(intHeader + xmlDataFragment + intFooter)); QFETCH(SignalMap, signalMap); SignalMap parsedMap = iface.signals_; @@ -506,10 +548,10 @@ void tst_QDBusXmlParser::properties_data() void tst_QDBusXmlParser::properties() { - QString xmlHeader = "<node>" - "<interface name=\"iface.iface1\">", - xmlFooter = "</interface>" - "</node>"; + QString intHeader = "<interface name=\"iface.iface1\">", + intFooter = "</interface>", + xmlHeader = "<node>" + intHeader, + xmlFooter = intFooter + "</node>"; QFETCH(QString, xmlDataFragment); @@ -517,6 +559,7 @@ void tst_QDBusXmlParser::properties() QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); QCOMPARE(iface.name, QString("iface.iface1")); + QCOMPARE(clean_xml(iface.introspection), clean_xml(intHeader + xmlDataFragment + intFooter)); QFETCH(PropertyMap, propertyMap); PropertyMap parsedMap = iface.properties; |