diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-24 13:48:18 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-25 20:36:37 +0200 |
| commit | 555125416eb1a12e15dddb57207ce7d87751a64b (patch) | |
| tree | f51faf78fcc045c83af7599ccd382bea96e3d10a /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | |
| parent | ede3389a3e152d7436bda6a53dd93e8847ab026e (diff) | |
QmlCompiler: Allow coercing date values to numbers
This is the equivalent of JavaScript's valueOf().
Change-Id: If850519d6dbc7354b447acb6aad8ac04211d059d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 54020ab7c3..e60d3b2505 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -1296,8 +1296,14 @@ void tst_QmlCppCodegen::dateConversions() QCOMPARE(o->property("date").value<QDateTime>(), refDate); QCOMPARE(o->property("time").value<QDateTime>(), refTime); - QCOMPARE(o->property("dateString").toString(), (engine.coerceValue<QDateTime, QString>(refDate))); - QCOMPARE(o->property("timeString").toString(), (engine.coerceValue<QDateTime, QString>(refTime))); + QCOMPARE(o->property("dateString").toString(), + (engine.coerceValue<QDateTime, QString>(refDate))); + QCOMPARE(o->property("dateNumber").toDouble(), + (engine.coerceValue<QDateTime, double>(refDate))); + QCOMPARE(o->property("timeString").toString(), + (engine.coerceValue<QDateTime, QString>(refTime))); + QCOMPARE(o->property("timeNumber").toDouble(), + (engine.coerceValue<QDateTime, double>(refTime))); QMetaObject::invokeMethod(o.data(), "shuffle"); @@ -1308,12 +1314,23 @@ void tst_QmlCppCodegen::dateConversions() const QTime time = ref->myTime(); QCOMPARE(o->property("dateString").toString(), (engine.coerceValue<QDate, QString>(date))); + QCOMPARE(o->property("dateNumber").toDouble(), (engine.coerceValue<QDate, double>(date))); QCOMPARE(o->property("timeString").toString(), (engine.coerceValue<QTime, QString>(time))); + QCOMPARE(o->property("timeNumber").toDouble(), (engine.coerceValue<QTime, double>(time))); QMetaObject::invokeMethod(o.data(), "fool"); QCOMPARE(ref->myDate(), (engine.coerceValue<QTime, QDate>(time))); QCOMPARE(ref->myTime(), (engine.coerceValue<QDate, QTime>(date))); + + QMetaObject::invokeMethod(o.data(), "invalidate"); + QMetaObject::invokeMethod(o.data(), "shuffle"); + + QCOMPARE(o->property("dateString").toString(), "Invalid Date"_L1); + QVERIFY(qIsNaN(o->property("dateNumber").toDouble())); + QCOMPARE(o->property("timeString").toString(), "Invalid Date"_L1); + QVERIFY(qIsNaN(o->property("timeNumber").toDouble())); + } void tst_QmlCppCodegen::deadShoeSize() |
