summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-08-18 15:01:19 (GMT)
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2009-08-18 17:10:56 (GMT)
commitfdf8956419fc784b458ef1d42c98fde526f9f5d5 (patch)
tree9d95bd2275be9378b66a3570af299031c189b664 /tests
parent393f5d5b2705c0ed7e6e1a3a69cc9cdf16cf334d (diff)
downloadQt-fdf8956419fc784b458ef1d42c98fde526f9f5d5.zip
Qt-fdf8956419fc784b458ef1d42c98fde526f9f5d5.tar.gz
Qt-fdf8956419fc784b458ef1d42c98fde526f9f5d5.tar.bz2
Added a behaviour parameter to QXmlStreamReader::readElementText
This makes the function a bit more useful, since previously it was only safe to use if you were sure that it would not encounter an unexpected child element, or if you would be alright with canceling the parser on such an occurrence. Now it is also possible to have it ignore any unexpected child elements, or to have it include the text found in any child elements. Task-number: 231938 Reviewed-by: mae
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qxmlstream/tst_qxmlstream.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp
index f496dcf..04f990f 100644
--- a/tests/auto/qxmlstream/tst_qxmlstream.cpp
+++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp
@@ -55,6 +55,8 @@
//TESTED_CLASS=QXmlStreamReader QXmlStreamWriter
//TESTED_FILES=corelib/xml/stream/qxmlutils.cpp corelib/xml/stream/qxmlstream.cpp corelib/xml/stream/qxmlstream_p.h
+Q_DECLARE_METATYPE(QXmlStreamReader::ReadElementTextBehaviour)
+
static const char *const catalogFile = "XML-Test-Suite/xmlconf/finalCatalog.xml";
static const int expectedRunCount = 1646;
static const int expectedSkipCount = 532;
@@ -551,6 +553,8 @@ private slots:
void readFromQBuffer() const;
void readFromQBufferInvalid() const;
void readNextStartElement() const;
+ void readElementText() const;
+ void readElementText_data() const;
void crashInUTF16Codec() const;
void hasAttributeSignature() const;
void hasAttribute() const;
@@ -1126,6 +1130,53 @@ void tst_QXmlStream::readNextStartElement() const
QCOMPARE(amountOfB, 2);
}
+void tst_QXmlStream::readElementText() const
+{
+ QFETCH(QXmlStreamReader::ReadElementTextBehaviour, behaviour);
+ QFETCH(QString, input);
+ QFETCH(QString, expected);
+
+ QXmlStreamReader reader(input);
+
+ QVERIFY(reader.readNextStartElement());
+ QCOMPARE(reader.readElementText(behaviour), expected);
+}
+
+void tst_QXmlStream::readElementText_data() const
+{
+ QTest::addColumn<QXmlStreamReader::ReadElementTextBehaviour>("behaviour");
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("expected");
+
+ QString validInput("<p>He was <em>never</em> going to admit<!-- TODO: rephrase --> his mistake.</p>");
+ QString invalidInput("<p>invalid...<p>");
+ QString invalidOutput("invalid...");
+
+ QTest::newRow("ErrorOnUnexpectedElement")
+ << QXmlStreamReader::ErrorOnUnexpectedElement
+ << validInput << QString("He was ");
+
+ QTest::newRow("IncludeChildElements")
+ << QXmlStreamReader::IncludeChildElements
+ << validInput << QString("He was never going to admit his mistake.");
+
+ QTest::newRow("SkipChildElements")
+ << QXmlStreamReader::SkipChildElements
+ << validInput << QString("He was going to admit his mistake.");
+
+ QTest::newRow("ErrorOnUnexpectedElement Invalid")
+ << QXmlStreamReader::ErrorOnUnexpectedElement
+ << invalidInput << invalidOutput;
+
+ QTest::newRow("IncludeChildElements Invalid")
+ << QXmlStreamReader::IncludeChildElements
+ << invalidInput << invalidOutput;
+
+ QTest::newRow("SkipChildElements Invalid")
+ << QXmlStreamReader::SkipChildElements
+ << invalidInput << invalidOutput;
+}
+
void tst_QXmlStream::crashInUTF16Codec() const
{
QEventLoop eventLoop;