diff options
author | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2010-10-29 09:55:47 (GMT) |
---|---|---|
committer | Jedrzej Nowacki <jedrzej.nowacki@nokia.com> | 2010-11-01 07:56:54 (GMT) |
commit | 49c0770f875b81586bd1890e128534759e057705 (patch) | |
tree | 7cbf5e603f7dcd0a132dc76718451b63f329949e /tests/auto/qscriptvalue/tst_qscriptvalue.cpp | |
parent | 6e754afacba309797b1317b5eeab2b93536eb02b (diff) | |
download | Qt-49c0770f875b81586bd1890e128534759e057705.zip Qt-49c0770f875b81586bd1890e128534759e057705.tar.gz Qt-49c0770f875b81586bd1890e128534759e057705.tar.bz2 |
Split tst_QScriptValue::ctor autotest.
The test was too big. There should be no difference in coverage.
Reviewed-by: Kent Hansen
Diffstat (limited to 'tests/auto/qscriptvalue/tst_qscriptvalue.cpp')
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 230 |
1 files changed, 143 insertions, 87 deletions
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 5e42921a..3184d7a 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -113,7 +113,7 @@ void tst_QScriptValue::assignAndCopyConstruct_test(const char *, const QScriptVa DEFINE_TEST_FUNCTION(assignAndCopyConstruct) -void tst_QScriptValue::ctor() +void tst_QScriptValue::ctor_invalid() { QScriptEngine eng; { @@ -121,6 +121,11 @@ void tst_QScriptValue::ctor() QCOMPARE(v.isValid(), false); QCOMPARE(v.engine(), (QScriptEngine *)0); } +} + +void tst_QScriptValue::ctor_undefinedWithEngine() +{ + QScriptEngine eng; { QScriptValue v(&eng, QScriptValue::UndefinedValue); QCOMPARE(v.isValid(), true); @@ -128,6 +133,11 @@ void tst_QScriptValue::ctor() QCOMPARE(v.isObject(), false); QCOMPARE(v.engine(), &eng); } +} + +void tst_QScriptValue::ctor_nullWithEngine() +{ + QScriptEngine eng; { QScriptValue v(&eng, QScriptValue::NullValue); QCOMPARE(v.isValid(), true); @@ -135,6 +145,11 @@ void tst_QScriptValue::ctor() QCOMPARE(v.isObject(), false); QCOMPARE(v.engine(), &eng); } +} + +void tst_QScriptValue::ctor_boolWithEngine() +{ + QScriptEngine eng; { QScriptValue v(&eng, false); QCOMPARE(v.isValid(), true); @@ -144,6 +159,11 @@ void tst_QScriptValue::ctor() QCOMPARE(v.toBoolean(), false); QCOMPARE(v.engine(), &eng); } +} + +void tst_QScriptValue::ctor_intWithEngine() +{ + QScriptEngine eng; { QScriptValue v(&eng, int(1)); QCOMPARE(v.isValid(), true); @@ -152,132 +172,102 @@ void tst_QScriptValue::ctor() QCOMPARE(v.toNumber(), 1.0); QCOMPARE(v.engine(), &eng); } +} + +void tst_QScriptValue::ctor_int() +{ { QScriptValue v(int(0x43211234)); QVERIFY(v.isNumber()); QCOMPARE(v.toInt32(), 0x43211234); } { - QScriptValue v(&eng, uint(1)); + QScriptValue v(int(1)); QCOMPARE(v.isValid(), true); QCOMPARE(v.isNumber(), true); QCOMPARE(v.isObject(), false); QCOMPARE(v.toNumber(), 1.0); - QCOMPARE(v.engine(), &eng); - } - { - QScriptValue v(uint(0x43211234)); - QVERIFY(v.isNumber()); - QCOMPARE(v.toUInt32(), uint(0x43211234)); + QCOMPARE(v.engine(), (QScriptEngine *)0); } +} + +void tst_QScriptValue::ctor_uintWithEngine() +{ + QScriptEngine eng; { - QScriptValue v(&eng, 1.0); + QScriptValue v(&eng, uint(1)); QCOMPARE(v.isValid(), true); QCOMPARE(v.isNumber(), true); QCOMPARE(v.isObject(), false); QCOMPARE(v.toNumber(), 1.0); QCOMPARE(v.engine(), &eng); } +} + +void tst_QScriptValue::ctor_uint() +{ { - QScriptValue v(12345678910.5); + QScriptValue v(uint(0x43211234)); QVERIFY(v.isNumber()); - QCOMPARE(v.toNumber(), 12345678910.5); - } - { - QScriptValue v(&eng, "ciao"); - QCOMPARE(v.isValid(), true); - QCOMPARE(v.isString(), true); - QCOMPARE(v.isObject(), false); - QCOMPARE(v.toString(), QLatin1String("ciao")); - QCOMPARE(v.engine(), &eng); + QCOMPARE(v.toUInt32(), uint(0x43211234)); } { - QScriptValue v(&eng, QString("ciao")); + QScriptValue v(uint(1)); QCOMPARE(v.isValid(), true); - QCOMPARE(v.isString(), true); + QCOMPARE(v.isNumber(), true); QCOMPARE(v.isObject(), false); - QCOMPARE(v.toString(), QLatin1String("ciao")); - QCOMPARE(v.engine(), &eng); - } - // copy constructor, operator= - { - QScriptValue v(&eng, 1.0); - QScriptValue v2(v); - QCOMPARE(v2.strictlyEquals(v), true); - QCOMPARE(v2.engine(), &eng); - - QScriptValue v3(v); - QCOMPARE(v3.strictlyEquals(v), true); - QCOMPARE(v3.strictlyEquals(v2), true); - QCOMPARE(v3.engine(), &eng); - - QScriptValue v4(&eng, 2.0); - QCOMPARE(v4.strictlyEquals(v), false); - v3 = v4; - QCOMPARE(v3.strictlyEquals(v), false); - QCOMPARE(v3.strictlyEquals(v4), true); - - v2 = QScriptValue(); - QCOMPARE(v2.strictlyEquals(v), false); QCOMPARE(v.toNumber(), 1.0); - - QScriptValue v5(v); - QCOMPARE(v5.strictlyEquals(v), true); - v = QScriptValue(); - QCOMPARE(v5.strictlyEquals(v), false); - QCOMPARE(v5.toNumber(), 1.0); - } - - // constructors that take no engine argument - { - QScriptValue v(QScriptValue::UndefinedValue); - QCOMPARE(v.isValid(), true); - QCOMPARE(v.isUndefined(), true); - QCOMPARE(v.isObject(), false); - QCOMPARE(v.engine(), (QScriptEngine *)0); - } - { - QScriptValue v(QScriptValue::NullValue); - QCOMPARE(v.isValid(), true); - QCOMPARE(v.isNull(), true); - QCOMPARE(v.isObject(), false); - QCOMPARE(v.engine(), (QScriptEngine *)0); - } - { - QScriptValue v(false); - QCOMPARE(v.isValid(), true); - QCOMPARE(v.isBoolean(), true); - QCOMPARE(v.isBool(), true); - QCOMPARE(v.isObject(), false); - QCOMPARE(v.toBoolean(), false); QCOMPARE(v.engine(), (QScriptEngine *)0); } +} + +void tst_QScriptValue::ctor_floatWithEngine() +{ + QScriptEngine eng; { - QScriptValue v(int(1)); + QScriptValue v(&eng, 1.0); QCOMPARE(v.isValid(), true); QCOMPARE(v.isNumber(), true); QCOMPARE(v.isObject(), false); QCOMPARE(v.toNumber(), 1.0); - QCOMPARE(v.engine(), (QScriptEngine *)0); + QCOMPARE(v.engine(), &eng); + } +} + +void tst_QScriptValue::ctor_float() +{ + { + QScriptValue v(12345678910.5); + QVERIFY(v.isNumber()); + QCOMPARE(v.toNumber(), 12345678910.5); } { - QScriptValue v(uint(1)); + QScriptValue v(1.0); QCOMPARE(v.isValid(), true); QCOMPARE(v.isNumber(), true); QCOMPARE(v.isObject(), false); QCOMPARE(v.toNumber(), 1.0); QCOMPARE(v.engine(), (QScriptEngine *)0); } +} + +void tst_QScriptValue::ctor_stringWithEngine() +{ + QScriptEngine eng; { - QScriptValue v(1.0); + QScriptValue v(&eng, "ciao"); QCOMPARE(v.isValid(), true); - QCOMPARE(v.isNumber(), true); + QCOMPARE(v.isString(), true); QCOMPARE(v.isObject(), false); - QCOMPARE(v.toNumber(), 1.0); - QCOMPARE(v.engine(), (QScriptEngine *)0); + QCOMPARE(v.toString(), QLatin1String("ciao")); + QCOMPARE(v.engine(), &eng); } +} + +void tst_QScriptValue::ctor_string() +{ { - QScriptValue v("ciao"); + QScriptValue v(QString("ciao")); QCOMPARE(v.isValid(), true); QCOMPARE(v.isString(), true); QCOMPARE(v.isObject(), false); @@ -285,26 +275,31 @@ void tst_QScriptValue::ctor() QCOMPARE(v.engine(), (QScriptEngine *)0); } { - QScriptValue v(QString("ciao")); + QScriptValue v("ciao"); QCOMPARE(v.isValid(), true); QCOMPARE(v.isString(), true); QCOMPARE(v.isObject(), false); QCOMPARE(v.toString(), QLatin1String("ciao")); QCOMPARE(v.engine(), (QScriptEngine *)0); } +} + +void tst_QScriptValue::ctor_copyAndAssignWithEngine() +{ + QScriptEngine eng; // copy constructor, operator= { - QScriptValue v(1.0); + QScriptValue v(&eng, 1.0); QScriptValue v2(v); QCOMPARE(v2.strictlyEquals(v), true); - QCOMPARE(v2.engine(), (QScriptEngine *)0); + QCOMPARE(v2.engine(), &eng); QScriptValue v3(v); QCOMPARE(v3.strictlyEquals(v), true); QCOMPARE(v3.strictlyEquals(v2), true); - QCOMPARE(v3.engine(), (QScriptEngine *)0); + QCOMPARE(v3.engine(), &eng); - QScriptValue v4(2.0); + QScriptValue v4(&eng, 2.0); QCOMPARE(v4.strictlyEquals(v), false); v3 = v4; QCOMPARE(v3.strictlyEquals(v), false); @@ -320,7 +315,68 @@ void tst_QScriptValue::ctor() QCOMPARE(v5.strictlyEquals(v), false); QCOMPARE(v5.toNumber(), 1.0); } +} + +void tst_QScriptValue::ctor_undefined() +{ + QScriptValue v(QScriptValue::UndefinedValue); + QCOMPARE(v.isValid(), true); + QCOMPARE(v.isUndefined(), true); + QCOMPARE(v.isObject(), false); + QCOMPARE(v.engine(), (QScriptEngine *)0); +} +void tst_QScriptValue::ctor_null() +{ + QScriptValue v(QScriptValue::NullValue); + QCOMPARE(v.isValid(), true); + QCOMPARE(v.isNull(), true); + QCOMPARE(v.isObject(), false); + QCOMPARE(v.engine(), (QScriptEngine *)0); +} + +void tst_QScriptValue::ctor_bool() +{ + QScriptValue v(false); + QCOMPARE(v.isValid(), true); + QCOMPARE(v.isBoolean(), true); + QCOMPARE(v.isBool(), true); + QCOMPARE(v.isObject(), false); + QCOMPARE(v.toBoolean(), false); + QCOMPARE(v.engine(), (QScriptEngine *)0); +} + +void tst_QScriptValue::ctor_copyAndAssign() +{ + QScriptValue v(1.0); + QScriptValue v2(v); + QCOMPARE(v2.strictlyEquals(v), true); + QCOMPARE(v2.engine(), (QScriptEngine *)0); + + QScriptValue v3(v); + QCOMPARE(v3.strictlyEquals(v), true); + QCOMPARE(v3.strictlyEquals(v2), true); + QCOMPARE(v3.engine(), (QScriptEngine *)0); + + QScriptValue v4(2.0); + QCOMPARE(v4.strictlyEquals(v), false); + v3 = v4; + QCOMPARE(v3.strictlyEquals(v), false); + QCOMPARE(v3.strictlyEquals(v4), true); + + v2 = QScriptValue(); + QCOMPARE(v2.strictlyEquals(v), false); + QCOMPARE(v.toNumber(), 1.0); + + QScriptValue v5(v); + QCOMPARE(v5.strictlyEquals(v), true); + v = QScriptValue(); + QCOMPARE(v5.strictlyEquals(v), false); + QCOMPARE(v5.toNumber(), 1.0); +} + +void tst_QScriptValue::ctor_nullEngine() +{ // 0 engine QVERIFY(QScriptValue(0, QScriptValue::UndefinedValue).isUndefined()); QVERIFY(QScriptValue(0, QScriptValue::NullValue).isNull()); |