aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine
diff options
context:
space:
mode:
authorFawzi Mohamed <fawzi.mohamed@qt.io>2020-08-18 17:32:15 +0200
committerFawzi Mohamed <fawzi.mohamed@qt.io>2020-08-20 14:58:18 +0200
commit2879ab208f07d2fa01ea5c8b5de1ab8c182cb2da (patch)
treeb4f87fc9c41a3654802348769c5826b0d7a23605 /tests/auto/qml/qjsengine
parentad0fd44600e689da9b04680a5905b5a81cc53641 (diff)
tst_qjsengine: Fix comparison related failures
The new QMetaType/QVariant comparison is strict, so that several comparisons now fail. so we try to convert before comparing. Remaining ugliness: QString -> QChar conversion not provided, so change input to string QVariant(static_cast<QObject *>(x)) != QVariant(x) if x is a subclass of QObject. Change-Id: Ie0b7ba40d36a5e935976d1947d95295c48cd0c23 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qjsengine')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 95747ef3ab..ed6e6be398 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -537,7 +537,7 @@ void tst_QJSEngine::toScriptValue_data()
QTest::newRow("qpointf") << QVariant(QPointF(42, 24));
QTest::newRow("qvariantlist") << QVariant(QVariantList() << 42.24 << 5 << "hello");
QTest::newRow("qvariantlist_point") << QVariant(QVariantList() << 42.24 << QPointF(42.24, 24.42) << QPointF(24.42, 42.24));
- QVariantMap vm; vm.insert("test", 55); vm.insert("abc", 42.42);;
+ QVariantMap vm; vm.insert("test", 55); vm.insert("abc", 42.42);
QTest::newRow("qvariantmap") << QVariant(vm);
vm.clear(); vm.insert("point1", QPointF(42.24, 24.42)); vm.insert("point2", QPointF(42.24, 24.42));
QTest::newRow("qvariantmap_point") << QVariant(vm);
@@ -560,6 +560,11 @@ void tst_QJSEngine::toScriptValue()
QJSValue outputJS = engine.toScriptValue(input);
QVariant output = engine.fromScriptValue<QVariant>(outputJS);
+ if (input.metaType().id() == QMetaType::QChar) {
+ if (!input.convert(QMetaType::QString))
+ QFAIL("cannot convert to the original value");
+ } else if (!output.convert(input.metaType().id()))
+ QFAIL("cannot convert to the original value");
QCOMPARE(input, output);
}
@@ -568,8 +573,8 @@ void tst_QJSEngine::toScriptValuenotroundtripped_data()
QTest::addColumn<QVariant>("input");
QTest::addColumn<QVariant>("output");
- QTest::newRow("QList<QObject*>") << QVariant::fromValue(QList<QObject*>() << this) << QVariant(QVariantList() << QVariant::fromValue(this));
- QTest::newRow("QObjectList") << QVariant::fromValue(QObjectList() << this) << QVariant(QVariantList() << QVariant::fromValue(this));
+ QTest::newRow("QList<QObject*>") << QVariant::fromValue(QList<QObject*>() << this) << QVariant(QVariantList() << QVariant::fromValue<QObject *>(this));
+ QTest::newRow("QObjectList") << QVariant::fromValue(QObjectList() << this) << QVariant(QVariantList() << QVariant::fromValue<QObject *>(this));
QTest::newRow("QList<QPoint>") << QVariant::fromValue(QList<QPointF>() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42)) << QVariant(QVariantList() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42));
QTest::newRow("QVector<QPoint>") << QVariant::fromValue(QVector<QPointF>() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42)) << QVariant(QVariantList() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42));
QTest::newRow("VoidStar") << QVariant(int(QMetaType::VoidStar), nullptr) << QVariant(int(QMetaType::Nullptr), nullptr);