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>
This commit is contained in:
Kurt Korbatits 2012-02-15 14:22:48 +10:00 committed by Qt by Nokia
parent 922e0ab515
commit 32060c2115
2 changed files with 13 additions and 8 deletions

View File

@ -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

View File

@ -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());