summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptvalue
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-09-21 10:56:11 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-09-21 14:29:16 (GMT)
commit65b4ce3c51283adb76dcb73cc654b06359b1ae00 (patch)
treec71e10c6da5f986cc83ab520efce3a5952114efe /tests/auto/qscriptvalue
parent1b34feacef7a2d3ac005449a7cfbcb08a6bbf947 (diff)
downloadQt-65b4ce3c51283adb76dcb73cc654b06359b1ae00.zip
Qt-65b4ce3c51283adb76dcb73cc654b06359b1ae00.tar.gz
Qt-65b4ce3c51283adb76dcb73cc654b06359b1ae00.tar.bz2
QtScript: Fix comparing QVariant and QObject.
This add a hook inside JSC to be able to implement our own comparison function when comparing objects. Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto/qscriptvalue')
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp42
1 files changed, 40 insertions, 2 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index 92b7c90..742f765 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -2875,15 +2875,27 @@ void tst_QScriptValue::equals()
QScriptValue qobj1 = eng.newQObject(this);
QScriptValue qobj2 = eng.newQObject(this);
+ QScriptValue qobj3 = eng.newQObject(0);
+ QScriptValue qobj4 = eng.newQObject(new QObject());
QVERIFY(qobj1.equals(qobj2)); // compares the QObject pointers
+ QVERIFY(!qobj2.equals(qobj4)); // compares the QObject pointers
+ QVERIFY(!qobj2.equals(obj2)); // compares the QObject pointers
QScriptValue compareFun = eng.evaluate("(function(a, b) { return a == b; })");
QVERIFY(compareFun.isFunction());
{
QScriptValue ret = compareFun.call(QScriptValue(), QScriptValueList() << qobj1 << qobj2);
QVERIFY(ret.isBool());
- QEXPECT_FAIL("", "In JSC back-end, == on QObject wrappers doesn't work", Continue);
QVERIFY(ret.toBool());
+ ret = compareFun.call(QScriptValue(), QScriptValueList() << qobj1 << qobj3);
+ QVERIFY(ret.isBool());
+ QVERIFY(!ret.toBool());
+ ret = compareFun.call(QScriptValue(), QScriptValueList() << qobj1 << qobj4);
+ QVERIFY(ret.isBool());
+ QVERIFY(!ret.toBool());
+ ret = compareFun.call(QScriptValue(), QScriptValueList() << qobj1 << obj1);
+ QVERIFY(ret.isBool());
+ QVERIFY(!ret.toBool());
}
{
@@ -2893,7 +2905,6 @@ void tst_QScriptValue::equals()
{
QScriptValue ret = compareFun.call(QScriptValue(), QScriptValueList() << var1 << var2);
QVERIFY(ret.isBool());
- QEXPECT_FAIL("", "In JSC back-end, == on QVariant wrappers doesn't work", Continue);
QVERIFY(ret.toBool());
}
}
@@ -2929,6 +2940,33 @@ void tst_QScriptValue::equals()
// QVariant::operator==() performs type conversion
QVERIFY(var1.equals(var2));
}
+ {
+ QScriptValue var1 = eng.newVariant(QVariant(QString::fromLatin1("123")));
+ QScriptValue var2 = eng.newVariant(QVariant(double(123)));
+ QScriptValue var3(QString::fromLatin1("123"));
+ QScriptValue var4(123);
+ QScriptValue var4(123.0);
+
+ QVERIFY(var1.equals(var1));
+ QVERIFY(var1.equals(var2));
+ QVERIFY(var1.equals(var3));
+ QVERIFY(var1.equals(var4));
+
+ QVERIFY(var2.equals(var1));
+ QVERIFY(var2.equals(var2));
+ QVERIFY(var2.equals(var3));
+ QVERIFY(var2.equals(var4));
+
+ QVERIFY(var3.equals(var1));
+ QVERIFY(var3.equals(var2));
+ QVERIFY(var3.equals(var3));
+ QVERIFY(var3.equals(var4));
+
+ QVERIFY(var4.equals(var1));
+ QVERIFY(var4.equals(var2));
+ QVERIFY(var4.equals(var3));
+ QVERIFY(var4.equals(var4));
+ }
QScriptEngine otherEngine;
QTest::ignoreMessage(QtWarningMsg, "QScriptValue::equals: "