summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArno Rehn <a.rehn@menlosystems.com>2019-05-09 23:26:13 +0200
committerMilian Wolff <milian.wolff@kdab.com>2019-05-15 20:04:28 +0000
commit1466130070922a6cc55c2a5b724311780a394a13 (patch)
tree3eee73c565477ddd71f94483a6b152cf013c28cf /tests
parentfc891dad209725113f49f42cfd59a5ced6ff89d2 (diff)
downloadqtwebchannel-1466130070922a6cc55c2a5b724311780a394a13.tar.gz
Fix generic conversion of list-like values to JSON arrays
Previously, QVariant::toList() was used to convert a QVariant to a QVariantList. This only works for actual QVariantLists and QStringList, however. This patch uses QVariant::value<QVariantList>() which works in all cases. A better approach would be to extract a QSequentialIterable, but QTBUG-42016 currently prevents this. Change-Id: I732cc88a6db2ec5d990760364a9db98a52521f6b Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index 57aab53..27ef81c 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -797,6 +797,13 @@ void TestWebChannel::testWrapValues()
QVERIFY(value.isDouble());
QCOMPARE(value.toInt(), (int) flags);
}
+ {
+ QVector<int> vec{1, 2, 3};
+ QVariant variant = QVariant::fromValue(vec);
+ QJsonValue value = channel.d_func()->publisher->wrapResult(variant, m_dummyTransport);
+ QVERIFY(value.isArray());
+ QCOMPARE(value.toArray(), QJsonArray({1, 2, 3}));
+ }
}
void TestWebChannel::testWrapObjectWithMultipleTransports()