diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-11-02 09:43:40 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-11-08 14:44:44 (GMT) |
commit | 8e96ec267e388ca290b5287f3b2272e74c4bafce (patch) | |
tree | bb35df19f0131c6f2a63e41f8957e31033220551 /tests/auto/qscriptextqobject | |
parent | 213cdbb1d635daf8a9f9214fbc628a23cab2dc63 (diff) | |
download | Qt-8e96ec267e388ca290b5287f3b2272e74c4bafce.zip Qt-8e96ec267e388ca290b5287f3b2272e74c4bafce.tar.gz Qt-8e96ec267e388ca290b5287f3b2272e74c4bafce.tar.bz2 |
Split monolithic QtScript autotest into smaller tests
Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/auto/qscriptextqobject')
-rw-r--r-- | tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp index 1562118..29934d5 100644 --- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp +++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp @@ -528,6 +528,20 @@ protected slots: private slots: void registeredTypes(); void getSetStaticProperty(); + void getSetStaticProperty_propertyFlags(); + void getSetStaticProperty_changeInCpp(); + void getSetStaticProperty_changeInJS(); + void getSetStaticProperty_compatibleVariantTypes(); + void getSetStaticProperty_conversion(); + void getSetStaticProperty_delete(); + void getSetStaticProperty_nonScriptable(); + void getSetStaticProperty_writeOnly(); + void getSetStaticProperty_readOnly(); + void getSetStaticProperty_enum(); + void getSetStaticProperty_qflags(); + void getSetStaticProperty_pointerDeref(); + void getSetStaticProperty_customGetterSetter(); + void getSetStaticProperty_methodPersistence(); void getSetDynamicProperty(); void getSetChildren(); void callQtInvokable(); @@ -655,7 +669,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() QCOMPARE(m_engine->evaluate("myObject.stringListProperty[1]").isString(), true); QCOMPARE(m_engine->evaluate("myObject.stringListProperty[1]").toString(), QLatin1String("zag")); +} +void tst_QScriptExtQObject::getSetStaticProperty_propertyFlags() +{ // default flags for "normal" properties { QScriptValue mobj = m_engine->globalObject().property("myObject"); @@ -677,7 +694,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() QVERIFY(!(mobj.propertyFlags("mySlot()") & QScriptValue::SkipInEnumeration)); QVERIFY(mobj.propertyFlags("mySlot()") & QScriptValue::QObjectMember); } +} +void tst_QScriptExtQObject::getSetStaticProperty_changeInCpp() +{ // property change in C++ should be reflected in script m_myObject->setIntProperty(456); QCOMPARE(m_engine->evaluate("myObject.intProperty") @@ -701,7 +721,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() m_myObject->setStringProperty(QLatin1String("zab")); QCOMPARE(m_engine->evaluate("myObject.stringProperty") .equals(QScriptValue(m_engine, QLatin1String("zab"))), true); +} +void tst_QScriptExtQObject::getSetStaticProperty_changeInJS() +{ // property change in script should be reflected in C++ QCOMPARE(m_engine->evaluate("myObject.intProperty = 123") .strictlyEquals(QScriptValue(m_engine, 123)), true); @@ -784,7 +807,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() << QLatin1String("two") << QLatin1String("true")); } +} +void tst_QScriptExtQObject::getSetStaticProperty_compatibleVariantTypes() +{ // test setting properties where we can't convert the type natively but where the // types happen to be compatible variant types already { @@ -803,7 +829,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() mobj.setProperty("propWithCustomType", m_engine->newVariant(qVariantFromValue(t))); QVERIFY(m_myObject->propWithCustomType().string == t.string); } +} +void tst_QScriptExtQObject::getSetStaticProperty_conversion() +{ // test that we do value conversion if necessary when setting properties { QScriptValue br = m_engine->evaluate("myObject.brushProperty"); @@ -823,28 +852,41 @@ void tst_QScriptExtQObject::getSetStaticProperty() m_engine->globalObject().setProperty("myColor", QScriptValue()); } +} +void tst_QScriptExtQObject::getSetStaticProperty_delete() +{ // try to delete QCOMPARE(m_engine->evaluate("delete myObject.intProperty").toBoolean(), false); QCOMPARE(m_engine->evaluate("myObject.intProperty").toNumber(), 123.0); + m_myObject->setVariantProperty(42); QCOMPARE(m_engine->evaluate("delete myObject.variantProperty").toBoolean(), false); QCOMPARE(m_engine->evaluate("myObject.variantProperty").toNumber(), 42.0); +} +void tst_QScriptExtQObject::getSetStaticProperty_nonScriptable() +{ // non-scriptable property QCOMPARE(m_myObject->hiddenProperty(), 456.0); QCOMPARE(m_engine->evaluate("myObject.hiddenProperty").isUndefined(), true); QCOMPARE(m_engine->evaluate("myObject.hiddenProperty = 123;" "myObject.hiddenProperty").toInt32(), 123); QCOMPARE(m_myObject->hiddenProperty(), 456.0); +} +void tst_QScriptExtQObject::getSetStaticProperty_writeOnly() +{ // write-only property QCOMPARE(m_myObject->writeOnlyProperty(), 789); QCOMPARE(m_engine->evaluate("myObject.writeOnlyProperty").isUndefined(), true); QCOMPARE(m_engine->evaluate("myObject.writeOnlyProperty = 123;" "myObject.writeOnlyProperty").isUndefined(), true); QCOMPARE(m_myObject->writeOnlyProperty(), 123); +} +void tst_QScriptExtQObject::getSetStaticProperty_readOnly() +{ // read-only property QCOMPARE(m_myObject->readOnlyProperty(), 987); QCOMPARE(m_engine->evaluate("myObject.readOnlyProperty").toInt32(), 987); @@ -856,7 +898,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() QCOMPARE(mobj.propertyFlags("readOnlyProperty") & QScriptValue::ReadOnly, QScriptValue::ReadOnly); } +} +void tst_QScriptExtQObject::getSetStaticProperty_enum() +{ // enum property QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy); { @@ -881,7 +926,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() QCOMPARE(m_myObject->enumProperty(), MyQObject::BazPolicy); m_engine->evaluate("myObject.enumProperty = 'nada'"); QCOMPARE(m_myObject->enumProperty(), (MyQObject::Policy)-1); +} +void tst_QScriptExtQObject::getSetStaticProperty_qflags() +{ // flags property QCOMPARE(m_myObject->flagsProperty(), MyQObject::FooAbility); { @@ -900,7 +948,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() m_engine->evaluate("myObject.flagsProperty = 'ScoobyDoo'"); // ### ouch! Shouldn't QMetaProperty::write() rather not change the value...? QCOMPARE(m_myObject->flagsProperty(), (MyQObject::Ability)-1); +} +void tst_QScriptExtQObject::getSetStaticProperty_pointerDeref() +{ // auto-dereferencing of pointers { QBrush b = QColor(0xCA, 0xFE, 0xBA, 0xBE); @@ -920,7 +971,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() } m_engine->globalObject().setProperty("brushPointer", QScriptValue()); } +} +void tst_QScriptExtQObject::getSetStaticProperty_customGetterSetter() +{ // install custom property getter+setter { QScriptValue mobj = m_engine->globalObject().property("myObject"); @@ -930,7 +984,10 @@ void tst_QScriptExtQObject::getSetStaticProperty() mobj.setProperty("intProperty", 321); QCOMPARE(mobj.property("intProperty").toInt32(), 321); } +} +void tst_QScriptExtQObject::getSetStaticProperty_methodPersistence() +{ // method properties are persistent { QScriptValue slot = m_engine->evaluate("myObject.mySlot"); |