summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKurt Korbatits <kurt.korbatits@nokia.com>2012-02-15 14:22:48 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-16 04:23:20 +0100
commit32060c2115308e2e480a5b1787dbb2ebb1ed7936 (patch)
tree48a5f67a5b39acf939b0cdb3626de620acd4505a /tests/auto
parent922e0ab5154c72c78e0b8871d06ef5d0e4a0acc3 (diff)
Changed json unittest to work from installation directory
- Changed json unittest to use TESTDATA and QFINDTESTDATA Change-Id: Id29f8257565f409fa184ba465f25bc8454e2b7fb Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com> Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/json/json.pro2
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp19
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<QString>("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());