aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-05-25 16:59:42 +0200
committerUlf Hermann <ulf.hermann@qt.io>2018-05-25 15:21:32 +0000
commit9a44e3b6ca81f0e84d774a95e45b449b5d4cb583 (patch)
treee57fe07bfbfc8e64fd2f9214e9ddd5d47b3d9136 /tests
parent71688bab1b7abf64ae840dff887aa501e83d5acc (diff)
QML Debugger: Don't crash when encoding JSON data
Apparently QVariant::save cannot deal with QJsonObject and friends. Transform them into QVariants before sending them over the wire. Task-number: QTBUG-68474 Change-Id: I8fc9fade4915c2b40f8d16aea51ea6ff65247dc1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp
index 89217e7556..417b75e760 100644
--- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp
+++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp
@@ -53,6 +53,9 @@
#include <QtCore/qdebug.h>
#include <QtCore/qthread.h>
#include <QtCore/qabstractitemmodel.h>
+#include <QtCore/qjsonobject.h>
+#include <QtCore/qjsonarray.h>
+#include <QtCore/qjsondocument.h>
#define QVERIFYOBJECT(statement) \
do {\
@@ -82,6 +85,40 @@ public:
QModelIndex modelIndex() { return QModelIndex(); }
};
+class JsonTest : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QJsonObject data READ data WRITE setData NOTIFY dataChanged)
+
+public:
+ JsonTest(QObject *parent = 0) : QObject(parent)
+ {
+ m_data["foo"] = QJsonValue(12);
+ m_data["ttt"] = QJsonArray({4, 5, 4, 3, 2});
+ m_data["a"] = QJsonValue(QJsonValue::Null);
+ m_data["b"] = QJsonValue(QJsonValue::Undefined);
+ m_data["c"] = QJsonValue("fffff");
+ }
+
+ QJsonObject data() const { return m_data; }
+
+signals:
+ void dataChanged(const QJsonObject &data);
+
+public slots:
+ void setData(const QJsonObject &data)
+ {
+ if (data != m_data) {
+ m_data = data;
+ emit dataChanged(data);
+ }
+ }
+
+private:
+ QJsonObject m_data;
+};
+
+
class tst_QQmlEngineDebugService : public QObject
{
Q_OBJECT
@@ -139,6 +176,7 @@ private slots:
void regression_QTCREATORBUG_7451();
void queryObjectWithNonStreamableTypes();
+ void jsonData();
void asynchronousCreate();
void invalidContexts();
void createObjectOnDestruction();
@@ -363,6 +401,11 @@ void tst_QQmlEngineDebugService::initTestCase()
"CustomTypes {}"
;
+ qmlRegisterType<JsonTest>("JsonTest", 1, 0, "JsonTest");
+ qml << "import JsonTest 1.0\n"
+ "JsonTest {}"
+ ;
+
for (int i=0; i<qml.count(); i++) {
QQmlComponent component(m_engine);
component.setData(qml[i], QUrl::fromLocalFile(""));
@@ -676,7 +719,7 @@ void tst_QQmlEngineDebugService::queryRootContexts()
// root context query sends only root object data - it doesn't fill in
// the children or property info
QCOMPARE(context.objects.count(), 0);
- QCOMPARE(context.contexts.count(), 6);
+ QCOMPARE(context.contexts.count(), 7);
QVERIFY(context.contexts[0].debugId >= 0);
QCOMPARE(context.contexts[0].name, QString("tst_QQmlDebug_childContext"));
}
@@ -915,6 +958,24 @@ void tst_QQmlEngineDebugService::queryObjectWithNonStreamableTypes()
QVariant(QLatin1String("QModelIndex()")));
}
+void tst_QQmlEngineDebugService::jsonData()
+{
+ bool success;
+
+ QmlDebugObjectReference rootObject = findRootObject(5, true);
+ QVERIFY(!rootObject.className.isEmpty());
+
+ m_dbg->queryObject(rootObject, &success);
+ QVERIFY(success);
+ QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result())));
+
+ QmlDebugObjectReference obj = m_dbg->object();
+ QVERIFY(!obj.className.isEmpty());
+
+ QCOMPARE(findProperty(obj.properties, "data").value,
+ QJsonDocument::fromJson("{\"a\":null,\"c\":\"fffff\",\"foo\":12,\"ttt\":[4,5,4,3,2]}")
+ .toVariant());
+}
void tst_QQmlEngineDebugService::queryExpressionResult()
{