testStelJsonParser.cpp   testStelJsonParser.cpp 
skipping to change at line 30 skipping to change at line 30
#include "tests/testStelJsonParser.hpp" #include "tests/testStelJsonParser.hpp"
#include <QObject> #include <QObject>
#include <QDebug> #include <QDebug>
#include <QTest> #include <QTest>
#include <QBuffer> #include <QBuffer>
#include <stdexcept> #include <stdexcept>
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
QTEST_MAIN(TestStelJsonParser); QTEST_GUILESS_MAIN(TestStelJsonParser);
void TestStelJsonParser::initTestCase() void TestStelJsonParser::initTestCase()
{ {
largeJsonBuff = "{\"test1\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5 ],[0.5,-0.5],[-0.5,-0.5]], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ largeJsonBuff = "{\"test1\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5 ],[0.5,-0.5],[-0.5,-0.5]], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
\"test2\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ \"test2\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
\"test3\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ \"test3\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
\"test4\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ \"test4\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
\"test5\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ \"test5\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
\"test6\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ \"test6\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
\"test7\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \ \"test7\": {\"worldCoords\": [[[-0.5,0.5],[0.5,0.5],[0.5,-0.5],[-0.5,-0.5] ], [[-0.2,-0.2],[0.2,-0.2],[0.2,0.2],[-0.2,0.2]]]}, \
skipping to change at line 88 skipping to change at line 88
QVERIFY(result.toMap().value("val").toInt(&ok)==-12356); QVERIFY(result.toMap().value("val").toInt(&ok)==-12356);
QVERIFY(ok==true); QVERIFY(ok==true);
// Test windows line ending // Test windows line ending
result = StelJsonParser::parse("{\"val\": -12356\r\n}"); result = StelJsonParser::parse("{\"val\": -12356\r\n}");
QVERIFY(result.toMap().value("val").canConvert<int>()); QVERIFY(result.toMap().value("val").canConvert<int>());
QVERIFY(result.toMap().value("val").toInt(&ok)==-12356); QVERIFY(result.toMap().value("val").toInt(&ok)==-12356);
QVERIFY(ok==true); QVERIFY(ok==true);
} }
void TestStelJsonParser::testIterator()
{
QBuffer buf;
buf.setData(listJsonBuff);
buf.open(QIODevice::ReadOnly);
try
{
int tot = 0;
JsonListIterator iter = StelJsonParser::initListIterator(&bu
f);
while (iter.hasNext())
{
QVariant v = iter.next();
QVERIFY(v.canConvert<QVariantMap>());
++tot;
}
QVERIFY(tot==3);
}
catch (std::runtime_error& e)
{
QString msg("Exception while loading JSON: ");
msg+=e.what();
QFAIL(qPrintable(msg));
}
buf.close();
}
void TestStelJsonParser::testErrors() void TestStelJsonParser::testErrors()
{ {
bool wasCatched = false; bool wasCatched = false;
QVariant result; QVariant result;
QString erMsg; QString erMsg;
try try
{ {
result = StelJsonParser::parse("{val: -12356}"); result = StelJsonParser::parse("{val: -12356}");
} }
catch (std::runtime_error& e) catch (std::runtime_error& e)
skipping to change at line 141 skipping to change at line 114
QVERIFY(result.isNull()); QVERIFY(result.isNull());
} }
void TestStelJsonParser::benchmarkParse() void TestStelJsonParser::benchmarkParse()
{ {
QBuffer buf; QBuffer buf;
buf.setData(largeJsonBuff); buf.setData(largeJsonBuff);
buf.open(QIODevice::ReadOnly); buf.open(QIODevice::ReadOnly);
QVariant result; QVariant result;
QBENCHMARK { QBENCHMARK {
buf.seek(0);
result = StelJsonParser::parse(&buf); result = StelJsonParser::parse(&buf);
} }
} }
 End of changes. 3 change blocks. 
29 lines changed or deleted 2 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/