From ed91e29b23a07879a748c199902e3bf3fe6cd73f Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 19 Apr 2010 13:03:51 +0200 Subject: Improve QScript{Engine,Value}::toObject() test coverage Test that calling toObject() doesn't change the type of the original value. --- tests/auto/qscriptengine/tst_qscriptengine.cpp | 30 ++++++++++++++++++++++++++ tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 12 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index 5713f8e..60b9112 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -3833,6 +3833,7 @@ void tst_QScriptEngine::toObject() QVERIFY(tmp.isObject()); QCOMPARE(tmp.toNumber(), falskt.toNumber()); } + QVERIFY(falskt.isBool()); QScriptValue sant(true); { @@ -3840,6 +3841,7 @@ void tst_QScriptEngine::toObject() QVERIFY(tmp.isObject()); QCOMPARE(tmp.toNumber(), sant.toNumber()); } + QVERIFY(sant.isBool()); QScriptValue number(123.0); { @@ -3847,6 +3849,7 @@ void tst_QScriptEngine::toObject() QVERIFY(tmp.isObject()); QCOMPARE(tmp.toNumber(), number.toNumber()); } + QVERIFY(number.isNumber()); QScriptValue str = QScriptValue(&eng, QString("ciao")); { @@ -3854,6 +3857,7 @@ void tst_QScriptEngine::toObject() QVERIFY(tmp.isObject()); QCOMPARE(tmp.toString(), str.toString()); } + QVERIFY(str.isString()); QScriptValue object = eng.newObject(); { @@ -3866,6 +3870,32 @@ void tst_QScriptEngine::toObject() QVERIFY(eng.toObject(qobject).strictlyEquals(qobject)); QVERIFY(!eng.toObject(QScriptValue()).isValid()); + + // v1 constructors + + QScriptValue boolValue(&eng, true); + { + QScriptValue ret = eng.toObject(boolValue); + QVERIFY(ret.isObject()); + QCOMPARE(ret.toBool(), boolValue.toBool()); + } + QVERIFY(boolValue.isBool()); + + QScriptValue numberValue(&eng, 123.0); + { + QScriptValue ret = eng.toObject(numberValue); + QVERIFY(ret.isObject()); + QCOMPARE(ret.toNumber(), numberValue.toNumber()); + } + QVERIFY(numberValue.isNumber()); + + QScriptValue stringValue(&eng, QString::fromLatin1("foo")); + { + QScriptValue ret = eng.toObject(stringValue); + QVERIFY(ret.isObject()); + QCOMPARE(ret.toString(), stringValue.toString()); + } + QVERIFY(stringValue.isString()); } void tst_QScriptEngine::reservedWords_data() diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index b2f6caf..815747d 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -1446,9 +1446,11 @@ void tst_QScriptValue::toObject() QScriptValue undefined = eng.undefinedValue(); QCOMPARE(undefined.toObject().isValid(), false); + QVERIFY(undefined.isUndefined()); QScriptValue null = eng.nullValue(); QCOMPARE(null.toObject().isValid(), false); + QVERIFY(null.isNull()); { QScriptValue falskt = QScriptValue(&eng, false); @@ -1457,6 +1459,7 @@ void tst_QScriptValue::toObject() QCOMPARE(tmp.isObject(), true); QCOMPARE(tmp.toNumber(), falskt.toNumber()); } + QVERIFY(falskt.isBool()); QScriptValue sant = QScriptValue(&eng, true); { @@ -1464,6 +1467,7 @@ void tst_QScriptValue::toObject() QCOMPARE(tmp.isObject(), true); QCOMPARE(tmp.toNumber(), sant.toNumber()); } + QVERIFY(sant.isBool()); QScriptValue number = QScriptValue(&eng, 123.0); { @@ -1471,6 +1475,7 @@ void tst_QScriptValue::toObject() QCOMPARE(tmp.isObject(), true); QCOMPARE(tmp.toNumber(), number.toNumber()); } + QVERIFY(number.isNumber()); QScriptValue str = QScriptValue(&eng, QString("ciao")); { @@ -1478,6 +1483,7 @@ void tst_QScriptValue::toObject() QCOMPARE(tmp.isObject(), true); QCOMPARE(tmp.toString(), str.toString()); } + QVERIFY(str.isString()); } QScriptValue object = eng.newObject(); @@ -1497,10 +1503,12 @@ void tst_QScriptValue::toObject() QScriptValue undefined = QScriptValue(QScriptValue::UndefinedValue); QVERIFY(!undefined.toObject().isValid()); QVERIFY(!eng.toObject(undefined).isValid()); + QVERIFY(undefined.isUndefined()); QScriptValue null = QScriptValue(QScriptValue::NullValue); QVERIFY(!null.toObject().isValid()); QVERIFY(!eng.toObject(null).isValid()); + QVERIFY(null.isNull()); QScriptValue falskt = QScriptValue(false); QVERIFY(!falskt.toObject().isValid()); @@ -1509,6 +1517,7 @@ void tst_QScriptValue::toObject() QVERIFY(tmp.isObject()); QVERIFY(tmp.toBool()); } + QVERIFY(falskt.isBool()); QScriptValue sant = QScriptValue(true); QVERIFY(!sant.toObject().isValid()); @@ -1517,6 +1526,7 @@ void tst_QScriptValue::toObject() QVERIFY(tmp.isObject()); QVERIFY(tmp.toBool()); } + QVERIFY(sant.isBool()); QScriptValue number = QScriptValue(123.0); QVERIFY(!number.toObject().isValid()); @@ -1525,6 +1535,7 @@ void tst_QScriptValue::toObject() QVERIFY(tmp.isObject()); QCOMPARE(tmp.toInt32(), number.toInt32()); } + QVERIFY(number.isNumber()); QScriptValue str = QScriptValue(QString::fromLatin1("ciao")); QVERIFY(!str.toObject().isValid()); @@ -1533,6 +1544,7 @@ void tst_QScriptValue::toObject() QVERIFY(tmp.isObject()); QCOMPARE(tmp.toString(), QString::fromLatin1("ciao")); } + QVERIFY(str.isString()); } } -- cgit v0.12