OSDN Git Service

ark: make use of JSON format support provided by Katie in tests
authorIvailo Monev <xakepa10@laimg.moc>
Tue, 4 Feb 2020 16:38:14 +0000 (16:38 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Tue, 4 Feb 2020 16:38:14 +0000 (16:38 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
ark/kerfuffle/tests/jobstest.cpp
ark/kerfuffle/tests/jsonarchiveinterface.cpp
ark/kerfuffle/tests/jsonparser.cpp

index 45fd77d..96dcb70 100644 (file)
@@ -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);
 
index bf0d088..eaf3350 100644 (file)
 #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)
 {
index 8c4c7e6..688ed1e 100644 (file)
 #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);
 }