summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-10-13 13:06:27 +0200
committerAleix Pol <[email protected]>2016-10-21 00:49:42 +0200
commitf85d8a5d80c16610bce0ec74ccf9b7a860a90389 (patch)
treec0d23d56ff40e2b3119f809f231a48df01d31906
parentd35167eb455ec33bb7f2aec2fdc285ec0d6c7724 (diff)
Improve testing
-rw-r--r--libdiscover/backends/SnapBackend/tests/SnapTest.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/libdiscover/backends/SnapBackend/tests/SnapTest.cpp b/libdiscover/backends/SnapBackend/tests/SnapTest.cpp
index 133a4b9..32540ac 100644
--- a/libdiscover/backends/SnapBackend/tests/SnapTest.cpp
+++ b/libdiscover/backends/SnapBackend/tests/SnapTest.cpp
@@ -33,6 +33,28 @@
#include <QtTest>
#include <QAction>
+namespace QTest {
+ template<>
+ char *toString(const QJsonValue &value)
+ {
+ QByteArray ret;
+ if (value.isObject())
+ ret = QJsonDocument(value.toObject()).toJson();
+ else if (value.isArray())
+ ret = QJsonDocument(value.toArray()).toJson();
+ else
+ ret = value.toString().toLatin1();
+ return qstrdup(ret.data());
+ }
+
+ template<>
+ char *toString(const QJsonObject &object)
+ {
+ QByteArray ret = QJsonDocument(object).toJson();
+ return qstrdup(ret.data());
+ }
+}
+
class SnapTest : public QObject
{
Q_OBJECT
@@ -53,11 +75,24 @@ private Q_SLOTS:
const auto snaps = socket.snaps();
for(const auto &snapValue : snaps) {
QVERIFY(snapValue.isObject());
- const auto snap = snapValue.toObject();
+ auto snap = snapValue.toObject();
QVERIFY(snap.contains(QLatin1String("name") ));
QVERIFY(snap.contains(QLatin1String("developer")));
- const auto requestedSnap = socket.snapByName(snap.value(QLatin1String("name")).toString().toUtf8());
+ auto requestedSnap = socket.snapByName(snap.value(QLatin1String("name")).toString().toUtf8());
+
+ //should treat these separately becauase they're randomly delivered in different order
+ //just make sure they're the same number, for now
+ const auto apps = snap.take(QLatin1String("apps")).toArray(), reqApps = requestedSnap.take(QLatin1String("apps")).toArray();
+ QCOMPARE(apps.count(), reqApps.count());
+
+ if (requestedSnap != snap) {
+ const auto keys = snap.keys();
+ QCOMPARE(requestedSnap.keys(), keys);
+ foreach(const auto &key, keys) {
+ QCOMPARE(requestedSnap.value(key), snap.value(key));
+ }
+ }
QCOMPARE(requestedSnap, snap);
}
}