diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2010-10-29 13:25:24 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2010-11-01 07:58:45 (GMT) |
commit | 9ffc5678c59f3aaf35130f931ad28d98e2013d2a (patch) | |
tree | eb50ac46a6a123f3903a79c220bf8cf3c5506fd8 /tests/auto/qscriptvalue | |
parent | 2b8c26f9f3fbba75463a818797b6d83cd409c74f (diff) | |
download | Qt-9ffc5678c59f3aaf35130f931ad28d98e2013d2a.zip Qt-9ffc5678c59f3aaf35130f931ad28d98e2013d2a.tar.gz Qt-9ffc5678c59f3aaf35130f931ad28d98e2013d2a.tar.bz2 |
Refactor tst_QScriptValue::getSetData
The test should use _data function. The test was divided into two
separate cases, it should reduce maintenance costs.
Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto/qscriptvalue')
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 96 | ||||
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.h | 5 |
2 files changed, 68 insertions, 33 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 0dd219b..fdfb2a6 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -2295,39 +2295,71 @@ void tst_QScriptValue::getSetScope() QVERIFY(!object2.scope().isValid()); } -void tst_QScriptValue::getSetData() +void tst_QScriptValue::getSetData_objects_data() { - QScriptEngine eng; - { - QScriptValue object = eng.newObject(); - QVERIFY(!object.data().isValid()); - QScriptValue v1(true); - object.setData(v1); - QVERIFY(object.data().strictlyEquals(v1)); - QScriptValue v2(123); - object.setData(v2); - QVERIFY(object.data().strictlyEquals(v2)); - QScriptValue v3 = eng.newObject(); - object.setData(v3); - QVERIFY(object.data().strictlyEquals(v3)); - object.setData(QScriptValue()); - QVERIFY(!object.data().isValid()); - } - { - QScriptValue value = eng.undefinedValue(); - QVERIFY(!value.data().isValid()); - QScriptValue v1(true); - value.setData(v1); - QVERIFY(!value.data().isValid()); - QScriptValue v2(123); - value.setData(v2); - QVERIFY(!value.data().isValid()); - QScriptValue v3 = eng.newObject(); - value.setData(v3); - QVERIFY(!value.data().isValid()); - value.setData(QScriptValue()); - QVERIFY(!value.data().isValid()); - } + newEngine(); + + QTest::addColumn<QScriptValue>("object"); + + QTest::newRow("object from evaluate") << engine->evaluate("new Object()"); + QTest::newRow("object from engine") << engine->newObject(); + QTest::newRow("Array") << engine->newArray(); + QTest::newRow("Date") << engine->newDate(12324); + QTest::newRow("QObject") << engine->newQObject(this); + QTest::newRow("RegExp") << engine->newRegExp(QRegExp()); +} + +void tst_QScriptValue::getSetData_objects() +{ + QFETCH(QScriptValue, object); + + QVERIFY(!object.data().isValid()); + QScriptValue v1(true); + object.setData(v1); + QVERIFY(object.data().strictlyEquals(v1)); + QScriptValue v2(123); + object.setData(v2); + QVERIFY(object.data().strictlyEquals(v2)); + QScriptValue v3 = engine->newObject(); + object.setData(v3); + QVERIFY(object.data().strictlyEquals(v3)); + object.setData(QScriptValue()); + QVERIFY(!object.data().isValid()); +} + +void tst_QScriptValue::getSetData_nonObjects_data() +{ + newEngine(); + + QTest::addColumn<QScriptValue>("value"); + + QTest::newRow("undefined (bound)") << engine->undefinedValue(); + QTest::newRow("null (bound)") << engine->nullValue(); + QTest::newRow("string (bound)") << QScriptValue(engine, "Pong"); + QTest::newRow("bool (bound)") << QScriptValue(engine, false); + + QTest::newRow("undefined") << QScriptValue(QScriptValue::UndefinedValue); + QTest::newRow("null") << QScriptValue(QScriptValue::NullValue); + QTest::newRow("string") << QScriptValue("Pong"); + QTest::newRow("bool") << QScriptValue(true); +} + +void tst_QScriptValue::getSetData_nonObjects() +{ + QFETCH(QScriptValue, value); + + QVERIFY(!value.data().isValid()); + QScriptValue v1(true); + value.setData(v1); + QVERIFY(!value.data().isValid()); + QScriptValue v2(123); + value.setData(v2); + QVERIFY(!value.data().isValid()); + QScriptValue v3 = engine->newObject(); + value.setData(v3); + QVERIFY(!value.data().isValid()); + value.setData(QScriptValue()); + QVERIFY(!value.data().isValid()); } class TestScriptClass : public QScriptClass diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h index b6274f4..a431f0b 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.h +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h @@ -113,7 +113,10 @@ private slots: void getSetScope(); void getSetProperty(); void arrayElementGetterSetter(); - void getSetData(); + void getSetData_objects_data(); + void getSetData_objects(); + void getSetData_nonObjects_data(); + void getSetData_nonObjects(); void getSetScriptClass_emptyClass_data(); void getSetScriptClass_emptyClass(); void getSetScriptClass_JSObjectFromCpp(); |