summaryrefslogtreecommitdiffstats
path: root/tests/auto/qxmlstream/tst_qxmlstream.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-08-17 14:55:58 (GMT)
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-08-18 17:10:56 (GMT)
commit393f5d5b2705c0ed7e6e1a3a69cc9cdf16cf334d (patch)
tree3b20e5280bf629e6360eaa35b23019e77b66a4c4 /tests/auto/qxmlstream/tst_qxmlstream.cpp
parente08ca6bcaf5fc746fdf8f3e379c17bf0a9daa771 (diff)
downloadQt-393f5d5b2705c0ed7e6e1a3a69cc9cdf16cf334d.zip
Qt-393f5d5b2705c0ed7e6e1a3a69cc9cdf16cf334d.tar.gz
Qt-393f5d5b2705c0ed7e6e1a3a69cc9cdf16cf334d.tar.bz2
Added two convenience functions to QXmlStreamReader
QXmlStreamReader::readNextStartElement reads until the next start element within the current element, or returns false when no such element is encountered before the end element is reached. It simplifies the common case of iterating over the elements in an XML document. QXmlStreamReader::skipCurrentElement reads until the end element of the current element, skipping any child elements. This functionality was requested in two tasks, and a similar function 'readUnknownElement' was present in Qt's stream reader example. Autotest is included, example and documentation have been updated. Task-number: 238793 Reviewed-by: mae
Diffstat (limited to 'tests/auto/qxmlstream/tst_qxmlstream.cpp')
-rw-r--r--tests/auto/qxmlstream/tst_qxmlstream.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp
index 375528c..f496dcf 100644
--- a/tests/auto/qxmlstream/tst_qxmlstream.cpp
+++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp
@@ -550,6 +550,7 @@ private slots:
void setEntityResolver();
void readFromQBuffer() const;
void readFromQBufferInvalid() const;
+ void readNextStartElement() const;
void crashInUTF16Codec() const;
void hasAttributeSignature() const;
void hasAttribute() const;
@@ -1107,6 +1108,24 @@ void tst_QXmlStream::readFromQBufferInvalid() const
QVERIFY(reader.hasError());
}
+void tst_QXmlStream::readNextStartElement() const
+{
+ QLatin1String in("<?xml version=\"1.0\"?><A><!-- blah --><B><C/></B><B attr=\"value\"/>text</A>");
+ QXmlStreamReader reader(in);
+
+ QVERIFY(reader.readNextStartElement());
+ QVERIFY(reader.isStartElement() && reader.name() == "A");
+
+ int amountOfB = 0;
+ while (reader.readNextStartElement()) {
+ QVERIFY(reader.isStartElement() && reader.name() == "B");
+ ++amountOfB;
+ reader.skipCurrentElement();
+ }
+
+ QCOMPARE(amountOfB, 2);
+}
+
void tst_QXmlStream::crashInUTF16Codec() const
{
QEventLoop eventLoop;