aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp')
-rw-r--r--tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
index 71c186f3e4..59023391cd 100644
--- a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
+++ b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
@@ -1,11 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qtest.h>
-#include <QtQml/qqmlengine.h>
-#include <QtQml/qqmlfile.h>
#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlexpression.h>
+#include <QtQml/qqmlfile.h>
#include <QtQml/qqmlscriptstring.h>
#include <QtQuickTestUtils/private/qmlutils_p.h>
@@ -20,6 +21,7 @@ private slots:
void syntaxError();
void exception();
void expressionFromDataComponent();
+ void emptyScriptString();
};
class TestObject : public QObject
@@ -121,6 +123,36 @@ void tst_qqmlexpression::expressionFromDataComponent()
QCOMPARE(result.toString(), QStringLiteral("success"));
}
+void tst_qqmlexpression::emptyScriptString()
+{
+ QQmlEngine engine;
+ QQmlContext *context = engine.rootContext();
+ QVERIFY(context);
+ QVERIFY(context->isValid());
+
+ QQmlScriptString empty;
+ QVERIFY(empty.isEmpty());
+
+ QQmlExpression expression(empty, context, this);
+ QCOMPARE(expression.context(), context);
+ QCOMPARE(expression.scopeObject(), this);
+ QCOMPARE(expression.expression(), QString());
+
+ const QVariant result = expression.evaluate();
+ QVERIFY(!result.isValid());
+
+ QQmlComponent c(&engine, testFileUrl("scriptString.qml"));
+ std::unique_ptr<QObject> root { c.create() };
+ TestObject *testObj = qobject_cast<TestObject*>(root.get());
+ QVERIFY(testObj != nullptr);
+
+ QQmlScriptString script = testObj->scriptString();
+ QVERIFY(!script.isEmpty());
+
+ // verify that comparing against an empty script string does not crash
+ QVERIFY(script != empty);
+}
+
QTEST_MAIN(tst_qqmlexpression)
#include "tst_qqmlexpression.moc"