diff options
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 6ccfc77c25..15bd031ce3 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -33,6 +33,8 @@ #include <QJSValueIterator> #include <private/qquickvaluetypes_p.h> #include <private/qqmlglobal_p.h> +#include <private/qv4engine_p.h> +#include <private/qv4variantobject_p.h> #include "../../shared/util.h" #include "testtypes.h" @@ -94,6 +96,7 @@ private slots: void toStringConversion(); void enumerableProperties(); void enumProperties(); + void scarceTypes(); private: QQmlEngine engine; @@ -1809,6 +1812,26 @@ void tst_qqmlvaluetypes::enumProperties() QCOMPARE(enumValue.toInt(), int(g.enumProperty())); } +void tst_qqmlvaluetypes::scarceTypes() +{ + // These should not be treated as value types because we want the scarce resource + // mechanism to clear them when going out of scope. The scarce resource mechanism + // only works on QV4::VariantObject as that has an additional level of redirection. + QVERIFY(!QQmlValueTypeFactory::isValueType(qMetaTypeId<QImage>())); + QVERIFY(!QQmlValueTypeFactory::isValueType(qMetaTypeId<QPixmap>())); + + QV4::ExecutionEngine engine; + QV4::Scope scope(&engine); + + QImage img(20, 20, QImage::Format_ARGB32); + QV4::ScopedObject imgValue(scope, engine.fromVariant(QVariant::fromValue(img))); + QCOMPARE(QByteArray(imgValue->vtable()->className), QByteArray("VariantObject")); + + QPixmap pixmap; + QV4::ScopedObject pixmapValue(scope, engine.fromVariant(QVariant::fromValue(img))); + QCOMPARE(QByteArray(pixmapValue->vtable()->className), QByteArray("VariantObject")); +} + QTEST_MAIN(tst_qqmlvaluetypes) |