From 8d35bba74305fcbb73230b718611957abc771f5a Mon Sep 17 00:00:00 2001 From: Jedrzej Nowacki Date: Thu, 18 Nov 2010 10:04:00 +0200 Subject: Split newQObject tests into smaller chunks. Reviewed-by: Kent Hansen --- tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 90 +++++++++++----------------- 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(...) -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(undefined), (QObject *)0); + newEngine(); + QTest::addColumn("value"); - QScriptValue null = eng.nullValue(); - QCOMPARE(null.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(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(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(sant), (QObject *)0); - QScriptValue number = QScriptValue(&eng, 123.0); - QCOMPARE(number.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(number), (QObject *)0); +void tst_QScriptValue::toQObject_nonQObject() +{ + QFETCH(QScriptValue, value); + QCOMPARE(value.toQObject(), (QObject *)0); + QCOMPARE(qscriptvalue_cast(value), (QObject *)0); +} - QScriptValue str = QScriptValue(&eng, QString("ciao")); - QCOMPARE(str.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(str), (QObject *)0); - } +// unfortunately, this is necessary in order to do qscriptvalue_cast(...) +Q_DECLARE_METATYPE(QPushButton*); - QScriptValue object = eng.newObject(); - QCOMPARE(object.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(object), (QObject *)0); +void tst_QScriptValue::toQObject() +{ + QScriptEngine eng; QScriptValue qobject = eng.newQObject(this); QCOMPARE(qobject.toQObject(), (QObject *)this); QCOMPARE(qscriptvalue_cast(qobject), (QObject *)this); QCOMPARE(qscriptvalue_cast(qobject), (QWidget *)0); - QScriptValue qobject2 = eng.newQObject(0); - QCOMPARE(qobject2.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(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(qbutton), (QWidget *)&button); QCOMPARE(qscriptvalue_cast(qbutton), &button); - // V2 constructors - { - QScriptValue falskt = QScriptValue(false); - QCOMPARE(falskt.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(falskt), (QObject *)0); - - QScriptValue sant = QScriptValue(true); - QCOMPARE(sant.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(sant), (QObject *)0); - - QScriptValue number = QScriptValue(123.0); - QCOMPARE(number.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(number), (QObject *)0); - - QScriptValue str = QScriptValue(QString("ciao")); - QCOMPARE(str.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(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(variant3), (QObject*)0); QCOMPARE(qscriptvalue_cast(variant3), (QWidget*)0); QCOMPARE(qscriptvalue_cast(variant3), &button); - - QScriptValue inv; - QCOMPARE(inv.toQObject(), (QObject *)0); - QCOMPARE(qscriptvalue_cast(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(); -- cgit v0.12