summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-04-08 06:55:57 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-04-08 07:23:00 (GMT)
commit3baf285917e2ea3183866768807f2495010602ab (patch)
tree46b1b25adc1b7e7b988f97fc039c6c048b29d3cd /tests
parent7d82f3875cd26c1cb0ad46ae0a9fddeb87e049d6 (diff)
downloadQt-3baf285917e2ea3183866768807f2495010602ab.zip
Qt-3baf285917e2ea3183866768807f2495010602ab.tar.gz
Qt-3baf285917e2ea3183866768807f2495010602ab.tar.bz2
Improve static assignment to QVariant's in the int and double case
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp20
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml14
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp32
3 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
index a1aceb7..f4df130 100644
--- a/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
+++ b/tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp
@@ -520,6 +520,24 @@ void tst_qdeclarativeinstruction::dump()
data->bytecode << i;
}
+ {
+ QDeclarativeInstruction i;
+ i.line = 51;
+ i.type = QDeclarativeInstruction::StoreVariantInteger;
+ i.storeInteger.value = 11;
+ i.storeInteger.propertyIndex = 32;
+ data->bytecode << i;
+ }
+
+ {
+ QDeclarativeInstruction i;
+ i.line = 52;
+ i.type = QDeclarativeInstruction::StoreVariantDouble;
+ i.storeDouble.value = 33.7;
+ i.storeDouble.propertyIndex = 19;
+ data->bytecode << i;
+ }
+
QStringList expect;
expect
<< "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments"
@@ -575,6 +593,8 @@ void tst_qdeclarativeinstruction::dump()
<< "47\t\tNA\tDEFER\t\t\t7"
<< "48\t\t48\tSTORE_IMPORTED_SCRIPT\t2"
<< "49\t\t50\tXXX UNKOWN INSTRUCTION\t1234"
+ << "50\t\t51\tSTORE_VARIANT_INTEGER\t\t32\t11"
+ << "51\t\t52\tSTORE_VARIANT_DOUBLE\t\t19\t33.7"
<< "-------------------------------------------------------------------------------";
messages = QStringList();
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml
new file mode 100644
index 0000000..a1d33ef
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/assignLiteralToVariant.qml
@@ -0,0 +1,14 @@
+import Qt 4.6
+
+QtObject {
+ property var test1: 1
+ property var test2: 1.7
+ property var test3: "Hello world!"
+ property var test4: "#FF008800"
+ property var test5: "10,10,10x10"
+ property var test6: "10,10"
+ property var test7: "10x10"
+ property var test8: "100,100,100"
+ property var test9: String("#FF008800")
+}
+
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index bf10a01..bfb56ba 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -87,6 +87,7 @@ private slots:
void assignBasicTypes();
void assignTypeExtremes();
void assignCompositeToType();
+ void assignLiteralToVariant();
void customParserTypes();
void rootAsQmlComponent();
void inlineQmlComponents();
@@ -479,6 +480,37 @@ void tst_qdeclarativelanguage::assignCompositeToType()
QVERIFY(object != 0);
}
+// Test that literals are stored correctly in variant properties
+void tst_qdeclarativelanguage::assignLiteralToVariant()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("assignLiteralToVariant.qml"));
+ VERIFY_ERRORS(0);
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test1").userType(), (int)QVariant::Int);
+ QCOMPARE(object->property("test2").userType(), (int)QMetaType::Double);
+ QCOMPARE(object->property("test3").userType(), (int)QVariant::String);
+ QCOMPARE(object->property("test4").userType(), (int)QVariant::Color);
+ QCOMPARE(object->property("test5").userType(), (int)QVariant::RectF);
+ QCOMPARE(object->property("test6").userType(), (int)QVariant::PointF);
+ QCOMPARE(object->property("test7").userType(), (int)QVariant::SizeF);
+ QCOMPARE(object->property("test8").userType(), (int)QVariant::Vector3D);
+ QCOMPARE(object->property("test9").userType(), (int)QVariant::String);
+
+ QVERIFY(object->property("test1") == QVariant(1));
+ QVERIFY(object->property("test2") == QVariant((double)1.7));
+ QVERIFY(object->property("test3") == QVariant(QString(QLatin1String("Hello world!"))));
+ QVERIFY(object->property("test4") == QVariant(QColor::fromRgb(0xFF008800)));
+ QVERIFY(object->property("test5") == QVariant(QRectF(10, 10, 10, 10)));
+ QVERIFY(object->property("test6") == QVariant(QPointF(10, 10)));
+ QVERIFY(object->property("test7") == QVariant(QSizeF(10, 10)));
+ QVERIFY(object->property("test8") == QVariant(QVector3D(100, 100, 100)));
+ QVERIFY(object->property("test9") == QVariant(QString(QLatin1String("#FF008800"))));
+
+ delete object;
+}
+
// Tests that custom parser types can be instantiated
void tst_qdeclarativelanguage::customParserTypes()
{