mirror of
https://bitbucket.org/smil3y/kde-extraapps.git
synced 2025-02-23 18:32:53 +00:00
ark: make use of JSON format support provided by Katie in tests
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
8bd0653477
commit
cc8d37ea35
3 changed files with 32 additions and 7 deletions
|
@ -114,14 +114,13 @@ void JobsTest::startAndWaitForResult(KJob *job)
|
|||
|
||||
void JobsTest::testExtractedFilesSize()
|
||||
{
|
||||
Kerfuffle::ListJob *listJob;
|
||||
|
||||
JSONArchiveInterface *noSizeIface =
|
||||
createArchiveInterface(QLatin1String(KDESRCDIR "data/archive001.json"));
|
||||
JSONArchiveInterface *sizeIface =
|
||||
createArchiveInterface(QLatin1String(KDESRCDIR "data/archive002.json"));
|
||||
|
||||
listJob = new Kerfuffle::ListJob(noSizeIface, this);
|
||||
Kerfuffle::ListJob *listJob = new Kerfuffle::ListJob(noSizeIface, this);
|
||||
listJob->setAutoDelete(false);
|
||||
startAndWaitForResult(listJob);
|
||||
|
||||
|
|
|
@ -26,10 +26,13 @@
|
|||
#include "jsonarchiveinterface.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <qjson/parser.h>
|
||||
|
||||
#include <qfile.h>
|
||||
|
||||
#ifndef QT_KATIE
|
||||
# include <qjson/parser.h>
|
||||
#endif
|
||||
|
||||
|
||||
JSONArchiveInterface::JSONArchiveInterface(QObject *parent, const QVariantList& args)
|
||||
: Kerfuffle::ReadWriteArchiveInterface(parent, args)
|
||||
{
|
||||
|
|
|
@ -28,10 +28,13 @@
|
|||
#include "kerfuffle/archiveinterface.h"
|
||||
|
||||
#include <KDebug>
|
||||
#include <QString>
|
||||
|
||||
#include <QtCore/qstring.h>
|
||||
|
||||
#include <qjson/parser.h>
|
||||
#ifndef QT_KATIE
|
||||
# include <qjson/parser.h>
|
||||
#else
|
||||
# include <QJsonDocument>
|
||||
#endif
|
||||
|
||||
typedef QMap<QString, Kerfuffle::EntryMetaDataType> ArchiveProperties;
|
||||
|
||||
|
@ -73,6 +76,7 @@ JSONParser::~JSONParser()
|
|||
|
||||
JSONParser::JSONArchive JSONParser::parse(const QString &json)
|
||||
{
|
||||
#ifndef QT_KATIE
|
||||
bool ok;
|
||||
QJson::Parser parser;
|
||||
|
||||
|
@ -82,12 +86,22 @@ JSONParser::JSONArchive JSONParser::parse(const QString &json)
|
|||
kDebug() << "Line" << parser.errorLine() << ":" << parser.errorString();
|
||||
return JSONParser::JSONArchive();
|
||||
}
|
||||
#else
|
||||
QJsonParseError error;
|
||||
const QVariant result = QJsonDocument::fromJson(json.toUtf8(), &error).toVariant();
|
||||
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
kDebug() << "Line" << error.offset << ":" << error.errorString();
|
||||
return JSONParser::JSONArchive();
|
||||
}
|
||||
#endif
|
||||
|
||||
return createJSONArchive(result);
|
||||
}
|
||||
|
||||
JSONParser::JSONArchive JSONParser::parse(QIODevice *json)
|
||||
{
|
||||
#ifndef QT_KATIE
|
||||
bool ok;
|
||||
QJson::Parser parser;
|
||||
|
||||
|
@ -97,6 +111,15 @@ JSONParser::JSONArchive JSONParser::parse(QIODevice *json)
|
|||
kDebug() << "Line" << parser.errorLine() << ":" << parser.errorString();
|
||||
return JSONParser::JSONArchive();
|
||||
}
|
||||
#else
|
||||
QJsonParseError error;
|
||||
const QVariant result = QJsonDocument::fromJson(json->readAll(), &error).toVariant();
|
||||
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
kDebug() << "Line" << error.offset << ":" << error.errorString();
|
||||
return JSONParser::JSONArchive();
|
||||
}
|
||||
#endif
|
||||
|
||||
return createJSONArchive(result);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue