diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-18 15:46:24 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-19 00:29:45 +0000 |
commit | e09acc38d3af64c2136ee8b6ab4f01a83492ba17 (patch) | |
tree | f5713d97eba1f314fd1f329e89d7a2cc1607242f /tests | |
parent | 92ebe65589ac0e173d297817b07704b2b6f897ee (diff) |
QJSValue: Allow casting integers to enums
You can also cast enums to integers, after all.
Change-Id: I283d3dd280eeb44ba22bb45ca9be69e5358d5781
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 453be4e6065a323e7fc0ea93fa0bee845d2020cd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qjsvalue/tst_qjsvalue.cpp | 17 | ||||
-rw-r--r-- | tests/auto/qml/qjsvalue/tst_qjsvalue.h | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp index fd2eb40717..2b91ca0019 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp @@ -2872,4 +2872,21 @@ void tst_QJSValue::jsFunctionInVariant() } } +void tst_QJSValue::integerToEnum() +{ + QJSEngine engine; + + QJSValue enumVal = engine.toScriptValue(QQmlComponent::Error); + QJSValue intVal(static_cast<int>(QQmlComponent::Error)); + + QVERIFY(enumVal.equals(intVal)); + QVERIFY(intVal.equals(enumVal)); + + QCOMPARE(qjsvalue_cast<QQmlComponent::Status>(intVal), QQmlComponent::Error); + QCOMPARE(qjsvalue_cast<QQmlComponent::Status>(enumVal), QQmlComponent::Error); + + QCOMPARE(qjsvalue_cast<int>(intVal), static_cast<int>(QQmlComponent::Error)); + QCOMPARE(qjsvalue_cast<int>(enumVal), static_cast<int>(QQmlComponent::Error)); +} + QTEST_MAIN(tst_QJSValue) diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.h b/tests/auto/qml/qjsvalue/tst_qjsvalue.h index 0b35b58c58..db6ed4e413 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.h +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.h @@ -148,6 +148,7 @@ private slots: void deleteFromDifferentThread(); void stringAndUrl(); void jsFunctionInVariant(); + void integerToEnum(); private: void newEngine() |