diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-03-10 09:26:59 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-03-11 12:00:43 +0000 |
commit | 12f3a1f3172f24bfbcfd8c8d47e7e0fc9b451f45 (patch) | |
tree | 9c6e3b68a680c37bac3066ca8257c6fc8c3f61a2 /tests/auto | |
parent | 48a184a7304ac34bbb7942b19b12d2cc8cad6174 (diff) | |
download | qtscript-12f3a1f3172f24bfbcfd8c8d47e7e0fc9b451f45.tar.gz |
Add verbose messages date conversion tests of tst_QScriptEngine.v5.5.0-alpha1
Task-number: QTBUG-44885
Change-Id: Iac155df75cba2402919f30dce2fa794025f396ce
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index aa4cb9f..dde048b 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -5795,6 +5795,20 @@ void tst_QScriptEngine::qRegExpInport() } } +static QByteArray msgDateRoundtripJSQtJS(int i, uint secs, + const QScriptValue &jsDate2, + const QScriptValue &jsDate) +{ + QString result; + const qsreal diff = jsDate.toNumber() - jsDate2.toNumber(); + QTextStream(&result) << "jsDate2=\"" << jsDate2.toString() + << "\" (" << jsDate2.toNumber() << "), jsDate=\"" + << jsDate.toString() << "\" (" << jsDate.toNumber() + << "), diff=" << diff << "\", i=" << i << ", secs=" << secs + << ", TZ=\"" << qgetenv("TZ") << '"'; + return result.toLocal8Bit(); +} + // QScriptValue::toDateTime() returns a local time, whereas JS dates // are always stored as UTC. Qt Script must respect the current time // zone, and correctly adjust for daylight saving time that may be in @@ -5807,8 +5821,8 @@ void tst_QScriptEngine::dateRoundtripJSQtJS() QScriptValue jsDate = eng.evaluate(QString::fromLatin1("new Date(%0 * 1000.0)").arg(secs)); QDateTime qtDate = jsDate.toDateTime(); QScriptValue jsDate2 = eng.newDate(qtDate); - if (jsDate2.toNumber() != jsDate.toNumber()) - QFAIL(qPrintable(jsDate.toString())); + QVERIFY2(jsDate2.toNumber() == jsDate.toNumber(), + msgDateRoundtripJSQtJS(i, secs, jsDate2, jsDate)); secs += 2*60*60; } } @@ -5826,6 +5840,19 @@ void tst_QScriptEngine::dateRoundtripQtJSQt() } } +static QByteArray msgDateConversionJSQt(int i, uint secs, + const QString &qtUTCDateStr, + const QString &jsUTCDateStr, + const QScriptValue &jsDate) +{ + QString result; + QTextStream(&result) << "qtUTCDateStr=\"" << qtUTCDateStr + << "\", jsUTCDateStr=\"" << jsUTCDateStr << "\", jsDate=\"" + << jsDate.toString() << "\", i=" << i << ", secs=" << secs + << ", TZ=\"" << qgetenv("TZ") << '"'; + return result.toLocal8Bit(); +} + void tst_QScriptEngine::dateConversionJSQt() { uint secs = QDateTime(QDate(2009, 1, 1)).toUTC().toTime_t(); @@ -5836,8 +5863,8 @@ void tst_QScriptEngine::dateConversionJSQt() QString qtUTCDateStr = qtDate.toUTC().toString(Qt::ISODate); QString jsUTCDateStr = jsDate.property("toISOString").call(jsDate).toString(); jsUTCDateStr.remove(jsUTCDateStr.length() - 5, 4); // get rid of milliseconds (".000") - if (qtUTCDateStr != jsUTCDateStr) - QFAIL(qPrintable(jsDate.toString())); + QVERIFY2(qtUTCDateStr == jsUTCDateStr, + msgDateConversionJSQt(i, secs, qtUTCDateStr, jsUTCDateStr, jsDate)); secs += 2*60*60; } } |