aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-08-09 15:01:13 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-09 11:50:58 +0200
commitd25f11bb15cad8b24e4d0aaa041e998d0f86d3f7 (patch)
treead85ce30e3614dff4a9321450c271a6c6e81e235 /tests
parent0e0f46c01cf6a183996d36c31987ca4a46b50bd9 (diff)
Add unit test for concatenated property name access
Task-number: QTBUG-23126 Change-Id: I706d5f4ba49a554c3816146f15a87e001cde9a3f Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/concatenatedStringPropertyAccess.qml127
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp10
2 files changed, 137 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/concatenatedStringPropertyAccess.qml b/tests/auto/qml/qqmlecmascript/data/concatenatedStringPropertyAccess.qml
new file mode 100644
index 0000000000..573ad431e1
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/concatenatedStringPropertyAccess.qml
@@ -0,0 +1,127 @@
+import QtQuick 2.0
+
+// this used to trigger crash: see QTBUG-23126
+Item {
+ id: root
+ property bool success: false
+
+ // each of these property names have partial strings
+ // which are prehashed by v8 (random, cos, sin, ...)
+ property int randomProperty: 4
+ property real cosProperty: 1
+ property real cossin: 1
+ property real propertycos: 1
+ property real cos: 1
+
+ // these property names are entirely "new".
+ property string kqwpald: "hello"
+ property bool poiuyt: false
+
+ Component.onCompleted: {
+ success = true;
+
+ // 1: ensure that we can access the properties by name
+
+ if (root["random" + "Property"] != 4) {
+ success = false;
+ return;
+ }
+
+ if (root["cos" + "Property"] != 1) {
+ success = false;
+ return;
+ }
+
+ if (root["cos" + "sin"] != 1) {
+ success = false;
+ return;
+ }
+
+ if (root["property" + "cos"] != 1) {
+ success = false;
+ return;
+ }
+
+ if (root["" + "cos"] != 1) {
+ success = false;
+ return;
+ }
+
+ if (root["cos" + ""] != 1) {
+ success = false;
+ return;
+ }
+
+ if (root["kq" + "wpald"] != "hello") {
+ success = false;
+ return;
+ }
+
+ if (root["poiu" + "yt"] != false) {
+ success = false;
+ return;
+ }
+
+ // 2: ensure that similarly named properties don't cause crash
+
+ if (root["random" + "property"] == 4) {
+ success = false;
+ return;
+ }
+
+ if (root["cos" + "property"] == 1) {
+ success = false;
+ return;
+ }
+
+ if (root["cos" + "Sin"] == 1) {
+ success = false;
+ return;
+ }
+
+ if (root["property" + "Cos"] == 1) {
+ success = false;
+ return;
+ }
+
+ if (root["" + "Cos"] == 1) {
+ success = false;
+ return;
+ }
+
+ if (root["Cos" + ""] == 1) {
+ success = false;
+ return;
+ }
+
+ if (root["kq" + "Wpald"] == "hello") {
+ success = false;
+ return;
+ }
+
+ if (root["poiu" + "Yt"] == false) {
+ success = false;
+ return;
+ }
+
+ // 3: ensure that toString doesn't crash
+
+ root["random" + "Property"].toString();
+ root["cos" + "Property"].toString();
+ root["cos" + "Sin"] ? root["cos" + "Sin"].toString() : "";
+ root["property" + "Cos"] ? root["property" + "Cos"].toString() : "";
+ root["Cos" + ""] ? root["Cos" + ""].toString() : "";
+ root["" + "Cos"] ? root["" + "Cos"].toString() : "";
+ root["kq" + "Wpald"] ? root["kq" + "Wpald"].toString() : "";
+ root["poiu" + "Yt"] ? root["poiu" + "Yt"].toString() : "";
+
+ root["random" + "property"] ? root["random" + "property"].toString() : "";
+ root["cos" + "property"] ? root["cos" + "property"].toString() : "";
+ root["cos" + "sin"] ? root["cos" + "sin"].toString() : "";
+ root["property" + "cos"] ? root["property" + "cos"].toString() : "";
+ root["cos" + ""] ? root["cos" + ""].toString() : "";
+ root["" + "cos"] ? root["" + "cos"].toString() : "";
+ root["kq" + "wpald"] ? root["kq" + "wpald"].toString() : "";
+ root["poiu" + "yt"] ? root["poiu" + "yt"].toString() : "";
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 55b76f1d20..963bec91bf 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -281,6 +281,7 @@ private slots:
void overrideDataAssert();
void fallbackBindings_data();
void fallbackBindings();
+ void concatenatedStringPropertyAccess();
private:
static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -7280,6 +7281,15 @@ void tst_qqmlecmascript::sequenceSort()
delete object;
}
+void tst_qqmlecmascript::concatenatedStringPropertyAccess()
+{
+ QQmlComponent component(&engine, testFileUrl("concatenatedStringPropertyAccess.qml"));
+ QObject *object = component.create();
+ QVERIFY(object);
+ QVERIFY(object->property("success").toBool());
+ delete object;
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"