From 3664d3b8426c05814cbf327ba010c5bec24853ef Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Wed, 18 Jan 2012 12:32:58 +1000 Subject: Changed xml unittests to work from installation directory - Changed to use QFINDTESTDATA and TESTDATA Change-Id: Ib738adfb6d0553e4c995ccaa51e34335f00f50f0 Reviewed-by: Kurt Korbatits Reviewed-by: Rohan McGovern Reviewed-by: Jason McDonald --- tests/auto/xml/dom/qdom/qdom.pro | 9 +--- tests/auto/xml/dom/qdom/tst_qdom.cpp | 62 +++++++++++++--------- tests/auto/xml/sax/qxml/qxml.pro | 6 +-- tests/auto/xml/sax/qxml/tst_qxml.cpp | 5 +- .../xml/sax/qxmlsimplereader/qxmlsimplereader.pro | 6 +-- .../sax/qxmlsimplereader/tst_qxmlsimplereader.cpp | 11 +++- 6 files changed, 53 insertions(+), 46 deletions(-) diff --git a/tests/auto/xml/dom/qdom/qdom.pro b/tests/auto/xml/dom/qdom/qdom.pro index 11f5f66152..db19a8ba89 100644 --- a/tests/auto/xml/dom/qdom/qdom.pro +++ b/tests/auto/xml/dom/qdom/qdom.pro @@ -6,15 +6,8 @@ QT = core xml testlib QT -= gui wince* { - addFiles.files = testdata doubleNamespaces.xml umlaut.xml - addFiles.path = . - DEPLOYMENT += addFiles - wince*|qt_not_deployed { DEPLOYMENT_PLUGIN += qcncodecs qjpcodecs qkrcodecs qtwcodecs } - DEFINES += SRCDIR=\\\"\\\" -} -else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" } +TESTDATA += testdata/* doubleNamespaces.xml umlaut.xml diff --git a/tests/auto/xml/dom/qdom/tst_qdom.cpp b/tests/auto/xml/dom/qdom/tst_qdom.cpp index b5dc2e6081..a2f6d36264 100644 --- a/tests/auto/xml/dom/qdom/tst_qdom.cpp +++ b/tests/auto/xml/dom/qdom/tst_qdom.cpp @@ -290,18 +290,20 @@ void tst_QDom::setContent() void tst_QDom::toString_01_data() { QTest::addColumn("fileName"); + const QString prefix = QFINDTESTDATA("testdata/toString_01"); + if (prefix.isEmpty()) + QFAIL("Cannot find testdata directory!"); + QTest::newRow( "01" ) << QString(prefix + "/doc01.xml"); + QTest::newRow( "02" ) << QString(prefix + "/doc02.xml"); + QTest::newRow( "03" ) << QString(prefix + "/doc03.xml"); + QTest::newRow( "04" ) << QString(prefix + "/doc04.xml"); + QTest::newRow( "05" ) << QString(prefix + "/doc05.xml"); - QTest::newRow( "01" ) << QString(SRCDIR "testdata/toString_01/doc01.xml"); - QTest::newRow( "02" ) << QString(SRCDIR "testdata/toString_01/doc02.xml"); - QTest::newRow( "03" ) << QString(SRCDIR "testdata/toString_01/doc03.xml"); - QTest::newRow( "04" ) << QString(SRCDIR "testdata/toString_01/doc04.xml"); - QTest::newRow( "05" ) << QString(SRCDIR "testdata/toString_01/doc05.xml"); - - QTest::newRow( "euc-jp" ) << QString(SRCDIR "testdata/toString_01/doc_euc-jp.xml"); - QTest::newRow( "iso-2022-jp" ) << QString(SRCDIR "testdata/toString_01/doc_iso-2022-jp.xml"); - QTest::newRow( "little-endian" ) << QString(SRCDIR "testdata/toString_01/doc_little-endian.xml"); - QTest::newRow( "utf-16" ) << QString(SRCDIR "testdata/toString_01/doc_utf-16.xml"); - QTest::newRow( "utf-8" ) << QString(SRCDIR "testdata/toString_01/doc_utf-8.xml"); + QTest::newRow( "euc-jp" ) << QString(prefix + "/doc_euc-jp.xml"); + QTest::newRow( "iso-2022-jp" ) << QString(prefix + "/doc_iso-2022-jp.xml"); + QTest::newRow( "little-endian" ) << QString(prefix + "/doc_little-endian.xml"); + QTest::newRow( "utf-16" ) << QString(prefix + "/doc_utf-16.xml"); + QTest::newRow( "utf-8" ) << QString(prefix + "/doc_utf-8.xml"); } @@ -471,7 +473,10 @@ void tst_QDom::save() void tst_QDom::initTestCase() { - QFile file(SRCDIR "testdata/excludedCodecs.txt"); + QString testFile = QFINDTESTDATA("testdata/excludedCodecs.txt"); + if (testFile.isEmpty()) + QFAIL("Cannot find testdata/excludedCodecs.txt"); + QFile file(testFile); QVERIFY(file.open(QIODevice::ReadOnly|QIODevice::Text)); QByteArray codecName; @@ -546,19 +551,21 @@ void tst_QDom::saveWithSerialization() const void tst_QDom::saveWithSerialization_data() const { QTest::addColumn("fileName"); - - QTest::newRow("doc01.xml") << QString(SRCDIR "testdata/toString_01/doc01.xml"); - QTest::newRow("doc01.xml") << QString(SRCDIR "testdata/toString_01/doc01.xml"); - QTest::newRow("doc02.xml") << QString(SRCDIR "testdata/toString_01/doc02.xml"); - QTest::newRow("doc03.xml") << QString(SRCDIR "testdata/toString_01/doc03.xml"); - QTest::newRow("doc04.xml") << QString(SRCDIR "testdata/toString_01/doc04.xml"); - QTest::newRow("doc05.xml") << QString(SRCDIR "testdata/toString_01/doc05.xml"); - - QTest::newRow("doc_euc-jp.xml") << QString(SRCDIR "testdata/toString_01/doc_euc-jp.xml"); - QTest::newRow("doc_iso-2022-jp.xml") << QString(SRCDIR "testdata/toString_01/doc_iso-2022-jp.xml"); - QTest::newRow("doc_little-endian.xml") << QString(SRCDIR "testdata/toString_01/doc_little-endian.xml"); - QTest::newRow("doc_utf-16.xml") << QString(SRCDIR "testdata/toString_01/doc_utf-16.xml"); - QTest::newRow("doc_utf-8.xml") << QString(SRCDIR "testdata/toString_01/doc_utf-8.xml"); + const QString prefix = QFINDTESTDATA("testdata/toString_01"); + if (prefix.isEmpty()) + QFAIL("Cannot find testdata!"); + QTest::newRow("doc01.xml") << QString(prefix + "/doc01.xml"); + QTest::newRow("doc01.xml") << QString(prefix + "/doc01.xml"); + QTest::newRow("doc02.xml") << QString(prefix + "/doc02.xml"); + QTest::newRow("doc03.xml") << QString(prefix + "/doc03.xml"); + QTest::newRow("doc04.xml") << QString(prefix + "/doc04.xml"); + QTest::newRow("doc05.xml") << QString(prefix + "/doc05.xml"); + + QTest::newRow("doc_euc-jp.xml") << QString(prefix + "/doc_euc-jp.xml"); + QTest::newRow("doc_iso-2022-jp.xml") << QString(prefix + "/doc_iso-2022-jp.xml"); + QTest::newRow("doc_little-endian.xml") << QString(prefix + "/doc_little-endian.xml"); + QTest::newRow("doc_utf-16.xml") << QString(prefix + "/doc_utf-16.xml"); + QTest::newRow("doc_utf-8.xml") << QString(prefix + "/doc_utf-8.xml"); } void tst_QDom::cloneNode_data() @@ -1775,7 +1782,10 @@ void tst_QDom::doubleNamespaceDeclarations() const { QDomDocument doc; - QFile file(SRCDIR "doubleNamespaces.xml" ); + QString testFile = QFINDTESTDATA("doubleNamespaces.xml"); + if (testFile.isEmpty()) + QFAIL("Cannot find test file doubleNamespaces.xml!"); + QFile file(testFile); QVERIFY(file.open(QIODevice::ReadOnly)); QXmlSimpleReader reader; diff --git a/tests/auto/xml/sax/qxml/qxml.pro b/tests/auto/xml/sax/qxml/qxml.pro index 4f2e427d14..e0b48ad9f5 100644 --- a/tests/auto/xml/sax/qxml/qxml.pro +++ b/tests/auto/xml/sax/qxml/qxml.pro @@ -4,8 +4,4 @@ TARGET = tst_qxml SOURCES += tst_qxml.cpp QT = core xml testlib -wince* { - addFiles.files = 0x010D.xml - addFiles.path = . - DEPLOYMENT += addFiles -} +TESTDATA += 0x010D.xml diff --git a/tests/auto/xml/sax/qxml/tst_qxml.cpp b/tests/auto/xml/sax/qxml/tst_qxml.cpp index afe219c635..14f4e554aa 100644 --- a/tests/auto/xml/sax/qxml/tst_qxml.cpp +++ b/tests/auto/xml/sax/qxml/tst_qxml.cpp @@ -196,7 +196,10 @@ void tst_QXml::interpretedAs0D() const QChar(0x010D) + QLatin1String("reated-by=\"an attr value\"/>")); - QFile f("0x010D.xml"); + QString testFile = QFINDTESTDATA("0x010D.xml"); + if (testFile.isEmpty()) + QFAIL("Cannot find test file 0x010D.xml!"); + QFile f(testFile); QVERIFY(f.open(QIODevice::ReadOnly)); QXmlInputSource data(&f); diff --git a/tests/auto/xml/sax/qxmlsimplereader/qxmlsimplereader.pro b/tests/auto/xml/sax/qxmlsimplereader/qxmlsimplereader.pro index ae924ca35f..cec33ded18 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/qxmlsimplereader.pro +++ b/tests/auto/xml/sax/qxmlsimplereader/qxmlsimplereader.pro @@ -12,8 +12,4 @@ CONFIG += no_batch QT += network xml testlib QT -= gui -wince* { - addFiles.files = encodings parser xmldocs - addFiles.path = . - DEPLOYMENT += addFiles -} +TESTDATA += encodings/* xmldocs/* diff --git a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp index 1478ae7e23..8001c199e4 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp @@ -141,7 +141,7 @@ class tst_QXmlSimpleReader : public QObject ~tst_QXmlSimpleReader(); private slots: - + void initTestCase(); void testGoodXmlFile(); void testGoodXmlFile_data(); void testBadXmlFile(); @@ -164,6 +164,7 @@ class tst_QXmlSimpleReader : public QObject private: static QDomDocument fromByteArray(const QString &title, const QByteArray &ba, bool *ok); XmlServer *server; + QString prefix; }; tst_QXmlSimpleReader::tst_QXmlSimpleReader() @@ -210,6 +211,14 @@ public: }; +void tst_QXmlSimpleReader::initTestCase() +{ + prefix = QFileInfo(QFINDTESTDATA("xmldocs")).absolutePath(); + if (prefix.isEmpty()) + QFAIL("Cannot find xmldocs testdata!"); + QDir::setCurrent(prefix); +} + void tst_QXmlSimpleReader::idsInParseException1() { MyErrorHandler handler; -- cgit v1.2.3