summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-04-08 07:21:40 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-04-08 07:23:01 (GMT)
commitbe8a7153d613586d69ac528153a6b8ccbe931aa6 (patch)
tree56faa5dbcce91cbf6557c2f4187f583a8ffc5491 /tests
parent3baf285917e2ea3183866768807f2495010602ab (diff)
downloadQt-be8a7153d613586d69ac528153a6b8ccbe931aa6.zip
Qt-be8a7153d613586d69ac528153a6b8ccbe931aa6.tar.gz
Qt-be8a7153d613586d69ac528153a6b8ccbe931aa6.tar.bz2
Make string -> int conversion consistent in bindings
QTBUG-9538
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml18
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp1
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.h65
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp27
4 files changed, 111 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml b/tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml
new file mode 100644
index 0000000..30a77e8
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/numberAssignment.qml
@@ -0,0 +1,18 @@
+import Qt.test 1.0
+
+NumberAssignment {
+ test1: if (1) 6.7
+ test2: if (1) "6.7"
+ test3: if (1) 6
+ test4: if (1) "6"
+
+ test5: if (1) 6.7
+ test6: if (1) "6.7"
+ test7: if (1) 6
+ test8: if (1) "6"
+
+ test9: if (1) 6.7
+ test10: if (1) "6.7"
+ test11: if (1) 6
+ test12: if (1) "6"
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
index a3bcb6a..0d07055 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
@@ -80,6 +80,7 @@ void registerTypes()
qmlRegisterExtendedType<MyBaseExtendedObject, BaseExtensionObject>("Qt.test", 1,0, "MyBaseExtendedObject");
qmlRegisterExtendedType<MyExtendedObject, ExtensionObject>("Qt.test", 1,0, "MyExtendedObject");
qmlRegisterType<MyTypeObject>("Qt.test", 1,0, "MyTypeObject");
+ qmlRegisterType<NumberAssignment>("Qt.test", 1,0, "NumberAssignment");
}
#include "testtypes.moc"
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
index faad8b7..4424419 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
@@ -600,6 +600,71 @@ private:
QVariantList m_actuals;
};
+class NumberAssignment : public QObject
+{
+ Q_OBJECT
+public:
+ Q_PROPERTY(qreal test1 READ test1 WRITE setTest1);
+ qreal _test1;
+ qreal test1() const { return _test1; }
+ void setTest1(qreal v) { _test1 = v; }
+
+ Q_PROPERTY(qreal test2 READ test2 WRITE setTest2);
+ qreal _test2;
+ qreal test2() const { return _test2; }
+ void setTest2(qreal v) { _test2 = v; }
+
+ Q_PROPERTY(qreal test3 READ test3 WRITE setTest3);
+ qreal _test3;
+ qreal test3() const { return _test3; }
+ void setTest3(qreal v) { _test3 = v; }
+
+ Q_PROPERTY(qreal test4 READ test4 WRITE setTest4);
+ qreal _test4;
+ qreal test4() const { return _test4; }
+ void setTest4(qreal v) { _test4 = v; }
+
+ Q_PROPERTY(int test5 READ test5 WRITE setTest5);
+ int _test5;
+ int test5() const { return _test5; }
+ void setTest5(int v) { _test5 = v; }
+
+ Q_PROPERTY(int test6 READ test6 WRITE setTest6);
+ int _test6;
+ int test6() const { return _test6; }
+ void setTest6(int v) { _test6 = v; }
+
+ Q_PROPERTY(int test7 READ test7 WRITE setTest7);
+ int _test7;
+ int test7() const { return _test7; }
+ void setTest7(int v) { _test7 = v; }
+
+ Q_PROPERTY(int test8 READ test8 WRITE setTest8);
+ int _test8;
+ int test8() const { return _test8; }
+ void setTest8(int v) { _test8 = v; }
+
+ Q_PROPERTY(unsigned int test9 READ test9 WRITE setTest9);
+ unsigned int _test9;
+ unsigned int test9() const { return _test9; }
+ void setTest9(unsigned int v) { _test9 = v; }
+
+ Q_PROPERTY(unsigned int test10 READ test10 WRITE setTest10);
+ unsigned int _test10;
+ unsigned int test10() const { return _test10; }
+ void setTest10(unsigned int v) { _test10 = v; }
+
+ Q_PROPERTY(unsigned int test11 READ test11 WRITE setTest11);
+ unsigned int _test11;
+ unsigned int test11() const { return _test11; }
+ void setTest11(unsigned int v) { _test11 = v; }
+
+ Q_PROPERTY(unsigned int test12 READ test12 WRITE setTest12);
+ unsigned int _test12;
+ unsigned int test12() const { return _test12; }
+ void setTest12(unsigned int v) { _test12 = v; }
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 32d407f..0e2b497 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -132,6 +132,7 @@ private slots:
void qlistqobjectMethods();
void strictlyEquals();
void compiled();
+ void numberAssignment();
void bug1();
void dynamicCreationCrash();
@@ -2116,6 +2117,32 @@ void tst_qdeclarativeecmascript::compiled()
delete object;
}
+// Test that numbers assigned in bindings as strings work consistently
+void tst_qdeclarativeecmascript::numberAssignment()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("numberAssignment.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QVERIFY(object->property("test1") == QVariant((qreal)6.7));
+ QVERIFY(object->property("test2") == QVariant((qreal)6.7));
+ QVERIFY(object->property("test3") == QVariant((qreal)6));
+ QVERIFY(object->property("test4") == QVariant((qreal)6));
+
+ QVERIFY(object->property("test5") == QVariant((int)7));
+ QVERIFY(object->property("test6") == QVariant((int)7));
+ QVERIFY(object->property("test7") == QVariant((int)6));
+ QVERIFY(object->property("test8") == QVariant((int)6));
+
+ QVERIFY(object->property("test9") == QVariant((unsigned int)7));
+ QVERIFY(object->property("test10") == QVariant((unsigned int)7));
+ QVERIFY(object->property("test11") == QVariant((unsigned int)6));
+ QVERIFY(object->property("test12") == QVariant((unsigned int)6));
+
+ delete object;
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"