diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-04-19 11:03:51 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-04-19 11:06:01 (GMT) |
commit | ed91e29b23a07879a748c199902e3bf3fe6cd73f (patch) | |
tree | b6f1e0a45c625c9f8e04b4e842c4d02fa245b7de | |
parent | b0a500dfd0efc44e795d7348da38f162b50c8263 (diff) | |
download | Qt-ed91e29b23a07879a748c199902e3bf3fe6cd73f.zip Qt-ed91e29b23a07879a748c199902e3bf3fe6cd73f.tar.gz Qt-ed91e29b23a07879a748c199902e3bf3fe6cd73f.tar.bz2 |
Improve QScript{Engine,Value}::toObject() test coverage
Test that calling toObject() doesn't change the type of the
original value.
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 30 | ||||
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 12 |
2 files changed, 42 insertions, 0 deletions
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()); } } |