From 5a6c72fd39a9088e9066bb611790577f4cd8fd2f Mon Sep 17 00:00:00 2001 From: Jedrzej Nowacki Date: Fri, 29 Oct 2010 14:26:53 +0200 Subject: Refactor tst_QScriptValue::isDate The test should use _data function. It should be easier to maintain that code. Reviewed-by: Kent Hansen --- tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 32 +++++++++++++++++++--------- tests/auto/qscriptvalue/tst_qscriptvalue.h | 1 + 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index eee2a6e..44318b4 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -1660,18 +1660,30 @@ void tst_QScriptValue::isArray() QCOMPARE(value.isArray(), array); } +void tst_QScriptValue::isDate_data() +{ + newEngine(); + + QTest::addColumn("value"); + QTest::addColumn("date"); + + QTest::newRow("date") << engine->evaluate("new Date()") << true; + QTest::newRow("[]") << engine->evaluate("[]") << false; + QTest::newRow("{}") << engine->evaluate("{}") << false; + QTest::newRow("globalObject") << engine->globalObject() << false; + QTest::newRow("invalid") << QScriptValue() << false; + QTest::newRow("number") << QScriptValue(123) << false; + QTest::newRow("bool") << QScriptValue(false) << false; + QTest::newRow("null") << engine->nullValue() << false; + QTest::newRow("undefined") << engine->undefinedValue() << false; +} + void tst_QScriptValue::isDate() { - QScriptEngine eng; - QVERIFY(eng.evaluate("new Date()").isDate()); - QVERIFY(!eng.evaluate("[]").isDate()); - QVERIFY(!eng.evaluate("{}").isDate()); - QVERIFY(!eng.globalObject().isDate()); - QVERIFY(!QScriptValue().isDate()); - QVERIFY(!QScriptValue(123).isDate()); - QVERIFY(!QScriptValue(false).isDate()); - QVERIFY(!eng.nullValue().isDate()); - QVERIFY(!eng.undefinedValue().isDate()); + QFETCH(QScriptValue, value); + QFETCH(bool, date); + + QCOMPARE(value.isDate(), date); } void tst_QScriptValue::isError() diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h index ad6ca8d..239f668 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.h +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h @@ -98,6 +98,7 @@ private slots: void isArray_data(); void isArray(); void isDate(); + void isDate_data(); void isError(); void isRegExp(); -- cgit v0.12