diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2010-11-18 08:04:00 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2010-11-18 08:43:48 (GMT) |
commit | 8d35bba74305fcbb73230b718611957abc771f5a (patch) | |
tree | b65bc4cfe6f2d4431855b9c62589bbebbd765bd4 /tests/auto | |
parent | d372c9a34a61674a9a5bc42ef7957683b33fee63 (diff) | |
download | Qt-8d35bba74305fcbb73230b718611957abc771f5a.zip Qt-8d35bba74305fcbb73230b718611957abc771f5a.tar.gz Qt-8d35bba74305fcbb73230b718611957abc771f5a.tar.bz2 |
Split newQObject tests into smaller chunks.
Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 90 | ||||
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.h | 2 |
2 files changed, 36 insertions, 56 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index de753d2..1343356 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -1341,52 +1341,53 @@ void tst_QScriptValue::toVariant() } } -// unfortunately, this is necessary in order to do qscriptvalue_cast<QPushButton*>(...) -Q_DECLARE_METATYPE(QPushButton*) - -void tst_QScriptValue::toQObject() +void tst_QScriptValue::toQObject_nonQObject_data() { - QScriptEngine eng; - - QScriptValue undefined = eng.undefinedValue(); - QCOMPARE(undefined.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(undefined), (QObject *)0); + newEngine(); + QTest::addColumn<QScriptValue>("value"); - QScriptValue null = eng.nullValue(); - QCOMPARE(null.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(null), (QObject *)0); + QTest::newRow("invalid") << QScriptValue(); + QTest::newRow("bool(false)") << QScriptValue(false); + QTest::newRow("bool(true)") << QScriptValue(true); + QTest::newRow("int") << QScriptValue(123); + QTest::newRow("string") << QScriptValue(QString::fromLatin1("ciao")); + QTest::newRow("undefined") << QScriptValue(QScriptValue::UndefinedValue); + QTest::newRow("null") << QScriptValue(QScriptValue::NullValue); - { - QScriptValue falskt = QScriptValue(&eng, false); - QCOMPARE(falskt.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(falskt), (QObject *)0); + QTest::newRow("bool bound(false)") << QScriptValue(engine, false); + QTest::newRow("bool bound(true)") << QScriptValue(engine, true); + QTest::newRow("int bound") << QScriptValue(engine, 123); + QTest::newRow("string bound") << QScriptValue(engine, QString::fromLatin1("ciao")); + QTest::newRow("undefined bound") << engine->undefinedValue(); + QTest::newRow("null bound") << engine->nullValue(); + QTest::newRow("object") << engine->newObject(); + QTest::newRow("array") << engine->newArray(); + QTest::newRow("date") << engine->newDate(124); + QTest::newRow("variant(12345)") << engine->newVariant(12345); + QTest::newRow("variant((QObject*)0)") << engine->newVariant(qVariantFromValue((QObject*)0)); + QTest::newRow("newQObject(0)") << engine->newQObject(0); +} - QScriptValue sant = QScriptValue(&eng, true); - QCOMPARE(sant.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(sant), (QObject *)0); - QScriptValue number = QScriptValue(&eng, 123.0); - QCOMPARE(number.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(number), (QObject *)0); +void tst_QScriptValue::toQObject_nonQObject() +{ + QFETCH(QScriptValue, value); + QCOMPARE(value.toQObject(), (QObject *)0); + QCOMPARE(qscriptvalue_cast<QObject*>(value), (QObject *)0); +} - QScriptValue str = QScriptValue(&eng, QString("ciao")); - QCOMPARE(str.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(str), (QObject *)0); - } +// unfortunately, this is necessary in order to do qscriptvalue_cast<QPushButton*>(...) +Q_DECLARE_METATYPE(QPushButton*); - QScriptValue object = eng.newObject(); - QCOMPARE(object.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(object), (QObject *)0); +void tst_QScriptValue::toQObject() +{ + QScriptEngine eng; QScriptValue qobject = eng.newQObject(this); QCOMPARE(qobject.toQObject(), (QObject *)this); QCOMPARE(qscriptvalue_cast<QObject*>(qobject), (QObject *)this); QCOMPARE(qscriptvalue_cast<QWidget*>(qobject), (QWidget *)0); - QScriptValue qobject2 = eng.newQObject(0); - QCOMPARE(qobject2.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(qobject2), (QObject *)0); - QWidget widget; QScriptValue qwidget = eng.newQObject(&widget); QCOMPARE(qwidget.toQObject(), (QObject *)&widget); @@ -1400,25 +1401,6 @@ void tst_QScriptValue::toQObject() QCOMPARE(qscriptvalue_cast<QWidget*>(qbutton), (QWidget *)&button); QCOMPARE(qscriptvalue_cast<QPushButton*>(qbutton), &button); - // V2 constructors - { - QScriptValue falskt = QScriptValue(false); - QCOMPARE(falskt.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(falskt), (QObject *)0); - - QScriptValue sant = QScriptValue(true); - QCOMPARE(sant.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(sant), (QObject *)0); - - QScriptValue number = QScriptValue(123.0); - QCOMPARE(number.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(number), (QObject *)0); - - QScriptValue str = QScriptValue(QString("ciao")); - QCOMPARE(str.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(str), (QObject *)0); - } - // wrapping a QObject* as variant QScriptValue variant = eng.newVariant(qVariantFromValue((QObject*)&button)); QCOMPARE(variant.toQObject(), (QObject*)&button); @@ -1437,10 +1419,6 @@ void tst_QScriptValue::toQObject() QCOMPARE(qscriptvalue_cast<QObject*>(variant3), (QObject*)0); QCOMPARE(qscriptvalue_cast<QWidget*>(variant3), (QWidget*)0); QCOMPARE(qscriptvalue_cast<QPushButton*>(variant3), &button); - - QScriptValue inv; - QCOMPARE(inv.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast<QObject*>(inv), (QObject *)0); } void tst_QScriptValue::toObject() diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h index 7bf0b66..98d83e4 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.h +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h @@ -91,6 +91,8 @@ private slots: void toUInt32(); void toUInt16(); void toVariant(); + void toQObject_nonQObject_data(); + void toQObject_nonQObject(); void toQObject(); void toDateTime(); void toRegExp(); |