From 32060c2115308e2e480a5b1787dbb2ebb1ed7936 Mon Sep 17 00:00:00 2001 From: Kurt Korbatits Date: Wed, 15 Feb 2012 14:22:48 +1000 Subject: [PATCH] Changed json unittest to work from installation directory - Changed json unittest to use TESTDATA and QFINDTESTDATA Change-Id: Id29f8257565f409fa184ba465f25bc8454e2b7fb Reviewed-by: Rohan McGovern Reviewed-by: Jason McDonald --- tests/auto/corelib/json/json.pro | 2 +- tests/auto/corelib/json/tst_qtjson.cpp | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/auto/corelib/json/json.pro b/tests/auto/corelib/json/json.pro index 5158b7337a..7978a74278 100644 --- a/tests/auto/corelib/json/json.pro +++ b/tests/auto/corelib/json/json.pro @@ -3,6 +3,6 @@ QT = core testlib CONFIG -= app_bundle CONFIG += testcase -DEFINES += SRCDIR=\\\"$$PWD/\\\" +TESTDATA += test.json test.bjson test3.json test2.json SOURCES += tst_qtjson.cpp diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index e35f645ef6..323546b8ea 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -111,6 +111,8 @@ private Q_SLOTS: void testCompaction(); void testDebugStream(); void testCompactionError(); +private: + QString testDataDir; }; TestQtJson::TestQtJson(QObject *parent) : QObject(parent) @@ -119,6 +121,9 @@ TestQtJson::TestQtJson(QObject *parent) : QObject(parent) void TestQtJson::initTestCase() { + testDataDir = QFileInfo(QFINDTESTDATA("test.json")).absolutePath(); + if (testDataDir.isEmpty()) + testDataDir = QCoreApplication::applicationDirPath(); } void TestQtJson::cleanupTestCase() @@ -1077,7 +1082,7 @@ void TestQtJson::fromJson() void TestQtJson::fromBinary() { - QFile file(QLatin1String(SRCDIR "test.json")); + QFile file(testDataDir + "/test.json"); file.open(QFile::ReadOnly); QByteArray testJson = file.readAll(); @@ -1086,7 +1091,7 @@ void TestQtJson::fromBinary() QVERIFY(!outdoc.isNull()); QVERIFY(doc == outdoc); - QFile bfile(QLatin1String(SRCDIR "test.bjson")); + QFile bfile(testDataDir + "/test.bjson"); bfile.open(QFile::ReadOnly); QByteArray binary = bfile.readAll(); @@ -1099,8 +1104,8 @@ void TestQtJson::fromBinary() void TestQtJson::toAndFromBinary_data() { QTest::addColumn("filename"); - QTest::newRow("test.json") << QString::fromLatin1(SRCDIR "test.json"); - QTest::newRow("test2.json") << QString::fromLatin1(SRCDIR "test2.json"); + QTest::newRow("test.json") << (testDataDir + "/test.json"); + QTest::newRow("test2.json") << (testDataDir + "/test2.json"); } void TestQtJson::toAndFromBinary() @@ -1279,7 +1284,7 @@ void TestQtJson::parseDuplicateKeys() void TestQtJson::testParser() { - QFile file(QLatin1String(SRCDIR "test.json")); + QFile file(testDataDir + "/test.json"); file.open(QFile::ReadOnly); QByteArray testJson = file.readAll(); @@ -1364,7 +1369,7 @@ void TestQtJson::compactObject() void TestQtJson::validation() { // this basically tests that we don't crash on corrupt data - QFile file(QLatin1String(SRCDIR "test.json")); + QFile file(testDataDir + "/test.json"); QVERIFY(file.open(QFile::ReadOnly)); QByteArray testJson = file.readAll(); QVERIFY(!testJson.isEmpty()); @@ -1385,7 +1390,7 @@ void TestQtJson::validation() } - QFile file2(QLatin1String(SRCDIR "test3.json")); + QFile file2(testDataDir + "/test3.json"); file2.open(QFile::ReadOnly); testJson = file2.readAll(); QVERIFY(!testJson.isEmpty());