aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlvaluetypes
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes')
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index 45cbbebdc3..ac9ec37ab3 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -91,6 +91,7 @@ private slots:
void customValueType();
void customValueTypeInQml();
void gadgetInheritance();
+ void toStringConversion();
private:
QQmlEngine engine;
@@ -1559,6 +1560,35 @@ void tst_qqmlvaluetypes::gadgetInheritance()
QCOMPARE(value.property("baseProperty").toInt(), 42);
}
+struct StringLessGadget {
+ Q_GADGET
+};
+
+Q_DECLARE_METATYPE(StringLessGadget)
+
+static QString StringLessGadget_to_QString(const StringLessGadget &)
+{
+ return QLatin1String("Surprise!");
+}
+
+void tst_qqmlvaluetypes::toStringConversion()
+{
+ QJSEngine engine;
+
+ StringLessGadget g;
+ QJSValue value = engine.toScriptValue(g);
+
+ QJSValue method = value.property("toString");
+ QJSValue stringConversion = method.callWithInstance(value);
+ QCOMPARE(stringConversion.toString(), QString("StringLessGadget()"));
+
+ QMetaType::registerConverter<StringLessGadget, QString>(StringLessGadget_to_QString);
+
+ stringConversion = method.callWithInstance(value);
+ QCOMPARE(stringConversion.toString(), StringLessGadget_to_QString(g));
+}
+
+
QTEST_MAIN(tst_qqmlvaluetypes)
#include "tst_qqmlvaluetypes.moc"