diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2011-10-12 14:27:57 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-09 13:08:36 +0100 |
commit | f6416183d36a260f3cbf6f89753f8a0ee27df7cc (patch) | |
tree | c0a8e60bfe2cf7dccba11f9518c7bac031b3796b /tests/auto/declarative/qdeclarativeecmascript | |
parent | 3cfee36b9910dafebd0846dd58115bf2f069ccba (diff) |
Get rid of QDeclarativeMetaType::{canCopy,copy}
Now that we have QMetaType::construct() that does placement new
construction, we can use that to copy the value.
We need to destruct the (default-constructed) existing value first,
but for primitive types that's a no-op, and for Qt's types it's
cheap since they use lazy initialization or "shared null".
Change-Id: Idadee04b1d5b590be7fec50fb0396fd277bee973
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
3 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/signalWithQJSValue.qml b/tests/auto/declarative/qdeclarativeecmascript/data/signalWithQJSValue.qml new file mode 100644 index 0000000000..36f481d533 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/signalWithQJSValue.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 + +MyQmlObject { + property string expression + property string compare + property bool pass: false + + onSignalWithQJSValue: + { + qjsvalueMethod(arg); + var expected = eval(expression); + pass = eval(compare)(arg, expected); + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index 06cc561c7f..b7f3f909ea 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -163,6 +163,7 @@ public: int value; }; QVariant variant() const { return m_variant; } + QJSValue qjsvalue() const { return m_qjsvalue; } int intProperty() const { return m_intProperty; } void setIntProperty(int i) { m_intProperty = i; emit intChanged(); } @@ -176,6 +177,7 @@ signals: void thirdBasicSignal(); void signalWithUnknownType(const MyQmlObject::MyType &arg); void signalWithVariant(const QVariant &arg); + void signalWithQJSValue(const QJSValue &arg); void intChanged(); public slots: @@ -185,6 +187,7 @@ public slots: void setString(const QString &s) { m_string = s; } void myinvokable(MyQmlObject *o) { myinvokableObject = o; } void variantMethod(const QVariant &v) { m_variant = v; } + void qjsvalueMethod(const QJSValue &v) { m_qjsvalue = v; } void v8function(QDeclarativeV8Function*); private: @@ -199,6 +202,7 @@ private: int m_resetProperty; QRegExp m_regExp; QVariant m_variant; + QJSValue m_qjsvalue; int m_intProperty; }; diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 31d4feb655..38d436448f 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -148,6 +148,8 @@ private slots: void signalWithJSValueInVariant(); void signalWithJSValueInVariant_twoEngines_data(); void signalWithJSValueInVariant_twoEngines(); + void signalWithQJSValue_data(); + void signalWithQJSValue(); void moduleApi_data(); void moduleApi(); void importScripts_data(); @@ -2945,6 +2947,32 @@ void tst_qdeclarativeecmascript::signalWithJSValueInVariant_twoEngines() QVERIFY(!object->property("pass").toBool()); } +void tst_qdeclarativeecmascript::signalWithQJSValue_data() +{ + signalWithJSValueInVariant_data(); +} + +void tst_qdeclarativeecmascript::signalWithQJSValue() +{ + QFETCH(QString, expression); + QFETCH(QString, compare); + + QDeclarativeComponent component(&engine, TEST_FILE("signalWithQJSValue.qml")); + QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject *>(component.create())); + QVERIFY(object != 0); + + QJSValue value = engine.evaluate(expression); + QVERIFY(!engine.hasUncaughtException()); + object->setProperty("expression", expression); + object->setProperty("compare", compare); + object->setProperty("pass", false); + + emit object->signalWithQJSValue(value); + + QVERIFY(object->property("pass").toBool()); + QVERIFY(object->qjsvalue().strictlyEquals(value)); +} + void tst_qdeclarativeecmascript::moduleApi_data() { QTest::addColumn<QUrl>("testfile"); |