aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-01-29 12:18:53 +0100
committerLiang Qi <liang.qi@qt.io>2019-01-29 12:37:04 +0100
commit8ec2403603f82e7a0d43b4de04c97ef1c7f1ad35 (patch)
treed7099d5a7cf813f378064ef0348647f4e68b2692 /tests/auto/qml
parent15525d2a309a6028d548797bc777e38905f36c46 (diff)
parent454676a8745a7334539449562a5fda47db2fc2ca (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts: src/3rdparty/masm/yarr/YarrJIT.cpp src/qml/compiler/qv4instr_moth.cpp src/quick/handlers/qquicksinglepointhandler_p.h src/quick/handlers/qquicktaphandler.cpp src/quick/items/context2d/qquickcontext2d.cpp Done-With: Ulf Hermann <ulf.hermann@qt.io> Change-Id: I109453131f9f0a05316ae37c7d6ed1edc8c0f9d4
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp59
-rw-r--r--tests/auto/qml/qml.pro1
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp3
-rw-r--r--tests/auto/qml/qqmlnotifier/data/objectRenamer.qml9
-rw-r--r--tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp32
-rw-r--r--tests/auto/qml/qv4mm/data/createdestroy.qml60
-rw-r--r--tests/auto/qml/qv4mm/qv4mm.pro6
-rw-r--r--tests/auto/qml/qv4mm/tst_qv4mm.cpp24
-rw-r--r--tests/auto/qml/qv4regexp/qv4regexp.pro8
-rw-r--r--tests/auto/qml/qv4regexp/tst_qv4regexp.cpp53
10 files changed, 252 insertions, 3 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 94494df4c0..76328bb405 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -220,6 +220,8 @@ private slots:
void functionToString_data();
void functionToString();
+ void stringReplace();
+
void protoChanges_QTBUG68369();
void multilineStrings();
@@ -4367,6 +4369,63 @@ void tst_QJSEngine::functionToString()
QCOMPARE(evaluationResult.toString(), expectedString);
}
+void tst_QJSEngine::stringReplace()
+{
+ QJSEngine engine;
+
+ QJSValue val = engine.evaluate("'x'.replace('x', '$1')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$1"));
+
+ val = engine.evaluate("'x'.replace('x', '$10')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$10"));
+
+ val = engine.evaluate("'x'.replace('x', '$01')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$01"));
+
+ val = engine.evaluate("'x'.replace('x', '$0')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$0"));
+
+ val = engine.evaluate("'x'.replace('x', '$00')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$00"));
+
+ val = engine.evaluate("'x'.replace(/(x)/, '$1')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("x"));
+
+ val = engine.evaluate("'x'.replace(/(x)/, '$01')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("x"));
+
+ val = engine.evaluate("'x'.replace(/(x)/, '$2')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$2"));
+
+ val = engine.evaluate("'x'.replace(/(x)/, '$02')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$02"));
+
+ val = engine.evaluate("'x'.replace(/(x)/, '$0')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$0"));
+
+ val = engine.evaluate("'x'.replace(/(x)/, '$00')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("$00"));
+
+ val = engine.evaluate("'x'.replace(/()()()()()()()()()(x)/, '$11')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("1"));
+
+ val = engine.evaluate("'x'.replace(/()()()()()()()()()(x)/, '$10')");
+ QVERIFY(val.isString());
+ QCOMPARE(val.toString(), QString("x"));
+}
+
void tst_QJSEngine::protoChanges_QTBUG68369()
{
QJSEngine engine;
diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro
index 0127260101..5448088ee5 100644
--- a/tests/auto/qml/qml.pro
+++ b/tests/auto/qml/qml.pro
@@ -73,6 +73,7 @@ PRIVATETESTS += \
qv4assembler \
qv4mm \
qv4identifiertable \
+ qv4regexp \
ecmascripttests \
bindingdependencyapi \
v4misc
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index e247ed4eff..958bf847ce 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -7557,7 +7557,8 @@ public:
private slots:
void reviveFirstWeakReference() {
- *resultPtr = weakRef->valueRef() && weakRef->isNullOrUndefined();
+ // weakRef is not required to be undefined here. The gc can clear it later.
+ *resultPtr = weakRef->valueRef();
if (!*resultPtr)
return;
QV4::ExecutionEngine *v4 = qmlEngine(this)->handle();
diff --git a/tests/auto/qml/qqmlnotifier/data/objectRenamer.qml b/tests/auto/qml/qqmlnotifier/data/objectRenamer.qml
new file mode 100644
index 0000000000..65d2206880
--- /dev/null
+++ b/tests/auto/qml/qqmlnotifier/data/objectRenamer.qml
@@ -0,0 +1,9 @@
+import QtQml 2.2
+
+QtObject {
+ property Timer timer: Timer {
+ running: true
+ interval: 0
+ onTriggered: parent.objectName = "havoc"
+ }
+}
diff --git a/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp b/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp
index 8811f779bb..6e831eacc1 100644
--- a/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp
+++ b/tests/auto/qml/qqmlnotifier/tst_qqmlnotifier.cpp
@@ -32,6 +32,9 @@
#include <QQmlContext>
#include <qqml.h>
#include <QMetaMethod>
+#if QT_CONFIG(process)
+#include <QProcess>
+#endif
#include "../../shared/util.h"
@@ -156,6 +159,8 @@ private slots:
void disconnectOnDestroy();
void lotsOfBindings();
+ void deleteFromHandler();
+
private:
void createObjects();
@@ -335,6 +340,33 @@ void tst_qqmlnotifier::lotsOfBindings()
delete e;
}
+void tst_qqmlnotifier::deleteFromHandler()
+{
+#if !QT_CONFIG(process)
+ QSKIP("Need QProcess support to test qFatal.");
+#else
+ if (qEnvironmentVariableIsSet("TST_QQMLNOTIFIER_DO_CRASH")) {
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("objectRenamer.qml"));
+ QPointer<QObject> mess = component.create();
+ QObject::connect(mess, &QObject::objectNameChanged, [&]() { delete mess; });
+ QTRY_VERIFY(mess.isNull()); // BANG!
+ } else {
+ QProcess process;
+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+ env.insert("TST_QQMLNOTIFIER_DO_CRASH", "bang");
+ process.setProcessEnvironment(env);
+ process.setProgram(QCoreApplication::applicationFilePath());
+ process.setArguments({"deleteFromHandler"});
+ process.start();
+ QTRY_COMPARE(process.exitStatus(), QProcess::CrashExit);
+ const QByteArray output = process.readAllStandardOutput();
+ QVERIFY(output.contains("QFATAL"));
+ QVERIFY(output.contains("destroyed while one of its QML signal handlers is in progress"));
+ }
+#endif
+}
+
QTEST_MAIN(tst_qqmlnotifier)
#include "tst_qqmlnotifier.moc"
diff --git a/tests/auto/qml/qv4mm/data/createdestroy.qml b/tests/auto/qml/qv4mm/data/createdestroy.qml
new file mode 100644
index 0000000000..5a4dd0f520
--- /dev/null
+++ b/tests/auto/qml/qv4mm/data/createdestroy.qml
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml 2.2
+
+QtObject {
+ property int creations: 0
+ property int destructions: 0
+ property int iterations: 0
+
+ property Component itemComponent: Component {
+ QtObject {
+ property var parent;
+ Component.onCompleted: ++parent.creations
+ Component.onDestruction: ++parent.destructions
+ }
+ }
+
+ property QtObject item: null;
+ property Timer timer: Timer {
+ running: true
+ repeat: true
+ interval: 1
+ onTriggered: {
+ if (parent.iterations === 100) {
+ item = null;
+ running = false;
+ } else {
+ ++parent.iterations;
+ item = itemComponent.createObject(null, { parent : parent });
+ }
+ gc();
+ }
+ }
+}
diff --git a/tests/auto/qml/qv4mm/qv4mm.pro b/tests/auto/qml/qv4mm/qv4mm.pro
index d9b749af4a..375c5cea75 100644
--- a/tests/auto/qml/qv4mm/qv4mm.pro
+++ b/tests/auto/qml/qv4mm/qv4mm.pro
@@ -1,6 +1,10 @@
CONFIG += testcase
TARGET = tst_qv4mm
-osx:CONFIG -= app_bundle
+include (../../shared/util.pri)
+
+macos:CONFIG -= app_bundle
+
+TESTDATA = data/*
SOURCES += tst_qv4mm.cpp
diff --git a/tests/auto/qml/qv4mm/tst_qv4mm.cpp b/tests/auto/qml/qv4mm/tst_qv4mm.cpp
index d8f4ed12e8..578a47d5fa 100644
--- a/tests/auto/qml/qv4mm/tst_qv4mm.cpp
+++ b/tests/auto/qml/qv4mm/tst_qv4mm.cpp
@@ -29,16 +29,23 @@
#include <qtest.h>
#include <QQmlEngine>
#include <QLoggingCategory>
+#include <QQmlComponent>
+
#include <private/qv4mm_p.h>
#include <private/qv4qobjectwrapper_p.h>
-class tst_qv4mm : public QObject
+#include "../../shared/util.h"
+
+#include <memory>
+
+class tst_qv4mm : public QQmlDataTest
{
Q_OBJECT
private slots:
void gcStats();
void multiWrappedQObjects();
+ void accessParentOnDestruction();
};
void tst_qv4mm::gcStats()
@@ -86,6 +93,21 @@ void tst_qv4mm::multiWrappedQObjects()
QCOMPARE(engine2.memoryManager->m_pendingFreedObjectWrapperValue.size(), 0);
}
+void tst_qv4mm::accessParentOnDestruction()
+{
+ QLoggingCategory::setFilterRules("qt.qml.gc.*=false");
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("createdestroy.qml"));
+ std::unique_ptr<QObject> obj(component.create());
+ QVERIFY(obj);
+ QPointer<QObject> timer = qvariant_cast<QObject *>(obj->property("timer"));
+ QVERIFY(timer);
+ QTRY_VERIFY(!timer->property("running").toBool());
+ QCOMPARE(obj->property("iterations").toInt(), 100);
+ QCOMPARE(obj->property("creations").toInt(), 100);
+ QCOMPARE(obj->property("destructions").toInt(), 100);
+}
+
QTEST_MAIN(tst_qv4mm)
#include "tst_qv4mm.moc"
diff --git a/tests/auto/qml/qv4regexp/qv4regexp.pro b/tests/auto/qml/qv4regexp/qv4regexp.pro
new file mode 100644
index 0000000000..f4ab6941f5
--- /dev/null
+++ b/tests/auto/qml/qv4regexp/qv4regexp.pro
@@ -0,0 +1,8 @@
+CONFIG += testcase
+TARGET = tst_qv4regexp
+macos:CONFIG -= app_bundle
+
+SOURCES += tst_qv4regexp.cpp
+
+QT += qml qml-private testlib
+
diff --git a/tests/auto/qml/qv4regexp/tst_qv4regexp.cpp b/tests/auto/qml/qv4regexp/tst_qv4regexp.cpp
new file mode 100644
index 0000000000..cbf9c3e47d
--- /dev/null
+++ b/tests/auto/qml/qv4regexp/tst_qv4regexp.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtQml/qjsengine.h>
+
+class tst_qv4regexp : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void catchJitFail();
+};
+
+void tst_qv4regexp::catchJitFail()
+{
+ QJSEngine engine;
+ QJSValue result = engine.evaluate(QLatin1String(
+ "var prevString = \" ok\";"
+ "var r = /^(\\s*)(([\\)\\]}]?\\s*)*([\\)\\]]\\s*))?;/.exec(prevString);"
+ "r === null;"), QLatin1String("regexptest.js"));
+ QVERIFY(result.isBool());
+ QVERIFY(result.toBool());
+}
+
+QTEST_MAIN(tst_qv4regexp)
+
+#include "tst_qv4regexp.moc"