summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-07-14 12:26:16 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-24 00:18:24 +0200
commit9d36032370f7b81279ff8774afd7dea4ea57ee6a (patch)
treed750ccd6cd317f056d13495a03fde5881134ec89 /tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
parent2d3b31171d8fce2ab364ca2ceea4e75020933334 (diff)
Implement QMetaType::canConvert() and use it in QVariant
Use the fact that we return the conversion function as a lambda to find out reliably whether a conversion between two types can be done. This requires some minor adjustments to our tests: * Nothing can convert to an unknown type and vice versa * Adjust results to the fact that we don't convert from char to QString anymore (where the old method was incorrect) * QStringList->QString requires some adjustments, as we only convert if the string list has exactly one element. For now we return true in canConvert(), but the conversion behavior in this case is something we should rethink, as it is very surprising. Change-Id: I3f5f87ee9cb99d690f5a7d13b13d6a6313d8038e Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp')
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index a722e53f48..d4af02baf1 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -477,7 +477,7 @@ void tst_QVariant::canConvert_data()
<< var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
var = QVariant();
QTest::newRow("Invalid")
- << var << N << N << N << N << N << N << N << N << N << N << N << N << N << Y << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N;
+ << var << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N;
var = QVariant(QList<QVariant>());
QTest::newRow("List")
<< var << N << N << N << N << N << N << N << N << N << N << N << N << N << N << N << Y << N << N << N << N << N << N << N << N << N << N << N << Y << N << N << N;
@@ -520,12 +520,12 @@ void tst_QVariant::canConvert_data()
var = QVariant::fromValue<signed char>(-1);
QTest::newRow("SChar")
<< var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
- var = QVariant((short)-3);
+ var = QVariant::fromValue((short)-3);
QTest::newRow("Short")
- << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
- var = QVariant((ushort)7);
+ << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
+ var = QVariant::fromValue((ushort)7);
QTest::newRow("UShort")
- << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << Y << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
+ << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
var = QVariant::fromValue<QJsonValue>(QJsonValue(QStringLiteral("hello")));
QTest::newRow("JsonValue")
<< var << N << N << Y << N << N << N << N << N << N << Y << N << N << Y << N << N << Y << Y << Y << N << N << N << N << N << N << N << N << Y << N << N << Y << Y;
@@ -2705,17 +2705,17 @@ void tst_QVariant::canConvertQStringList_data() const
QTest::addColumn<QStringList>("input");
QTest::addColumn<QString>("result");
- QTest::newRow("An empty list") << false << QStringList() << QString();
+ QTest::newRow("An empty list") << true << QStringList() << QString();
QTest::newRow("A single item") << true << QStringList(QLatin1String("foo")) << QString::fromLatin1("foo");
QTest::newRow("A single, but empty item") << true << QStringList(QString()) << QString();
QStringList l;
l << "a" << "b";
- QTest::newRow("Two items") << false << l << QString();
+ QTest::newRow("Two items") << true << l << QString();
l << "c";
- QTest::newRow("Three items") << false << l << QString();
+ QTest::newRow("Three items") << true << l << QString();
}
template<typename T> void convertMetaType()