aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlmetaobject
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-03-05 11:54:01 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-07 12:10:27 +0100
commitaed15e776277410fb43ce2d2a9a8924359a58653 (patch)
tree426dfd76e6db21616beaea518b13224844ac9e51 /tests/auto/qml/qqmlmetaobject
parent3f3850e954aac35b916c01546c69783183824b35 (diff)
Make sure QML type "real" always maps to C++ type "double"
The type "real" was documented to be a single-precision float, but that's incorrect. It's always been double. However, signal parameters of type "real" would be mapped to the C++ type "qreal", which can be either float or double depending on the platform. Since JavaScript floating point numbers have double precision, QML should use the same, to avoid potential loss of precision. With this change, "real" behaves the same as the QML "double" type (which already guaranteed double precision). Even though it's redundant, "double" is kept to preserve compatibility. Added tests for the "double" type to the QML meta-object autotest, and a test for the "real" type that ensures there's no loss of precision. Change-Id: I1a77f1fd45082ff670684a935e17d1a46ea75d84 Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlmetaobject')
-rw-r--r--tests/auto/qml/qqmlmetaobject/data/property.double.qml5
-rw-r--r--tests/auto/qml/qqmlmetaobject/data/property.real.qml2
-rw-r--r--tests/auto/qml/qqmlmetaobject/data/signal.6.qml5
-rw-r--r--tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp20
4 files changed, 27 insertions, 5 deletions
diff --git a/tests/auto/qml/qqmlmetaobject/data/property.double.qml b/tests/auto/qml/qqmlmetaobject/data/property.double.qml
new file mode 100644
index 0000000000..65da1889e4
--- /dev/null
+++ b/tests/auto/qml/qqmlmetaobject/data/property.double.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+QtObject {
+ property double test: 1234567890
+}
diff --git a/tests/auto/qml/qqmlmetaobject/data/property.real.qml b/tests/auto/qml/qqmlmetaobject/data/property.real.qml
index de2baf5be2..2268aac8c2 100644
--- a/tests/auto/qml/qqmlmetaobject/data/property.real.qml
+++ b/tests/auto/qml/qqmlmetaobject/data/property.real.qml
@@ -1,5 +1,5 @@
import QtQuick 2.0
QtObject {
- property real test: 21
+ property real test: 1234567890
}
diff --git a/tests/auto/qml/qqmlmetaobject/data/signal.6.qml b/tests/auto/qml/qqmlmetaobject/data/signal.6.qml
new file mode 100644
index 0000000000..a4ec6c0eaa
--- /dev/null
+++ b/tests/auto/qml/qqmlmetaobject/data/signal.6.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+QtObject {
+ signal testSignal(double foo)
+}
diff --git a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp
index 6cadc3524b..f2c50ddbef 100644
--- a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp
+++ b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp
@@ -92,12 +92,18 @@ void tst_QQmlMetaObject::property_data()
<< QByteArray("bool") << int(QMetaType::Bool)
<< true // default
<< QVariant(true) << true << QVariant(false);
+ QTest::newRow("double") << "property.double.qml"
+ << QByteArray("double") << int(QMetaType::Double)
+ << false // default
+ << QVariant(double(1234567890.))
+ << true // writable
+ << QVariant(double(1.23456789));
QTest::newRow("real") << "property.real.qml"
<< QByteArray("double") << int(QMetaType::Double)
<< false // default
- << QVariant(double(21))
+ << QVariant(double(1234567890.))
<< true // writable
- << QVariant(double(37));
+ << QVariant(double(1.23456789));
QTest::newRow("string") << "property.string.qml"
<< QByteArray("QString") << int(QMetaType::QString)
<< true // default
@@ -306,10 +312,10 @@ void tst_QQmlMetaObject::method_data()
<< (QList<QByteArray>() << "QString")
<< (QList<QByteArray>() << "foo");
QTest::newRow("testSignal(int foo, bool bar, real baz)") << "signal.3.qml"
- << "testSignal(int,bool,qreal)"
+ << "testSignal(int,bool,double)"
<< QMetaMethod::Signal
<< ""
- << (QList<QByteArray>() << "int" << "bool" << "qreal")
+ << (QList<QByteArray>() << "int" << "bool" << "double")
<< (QList<QByteArray>() << "foo" << "bar" << "baz");
QTest::newRow("testSignal(variant foo, var bar)") << "signal.4.qml"
<< "testSignal(QVariant,QVariant)"
@@ -323,6 +329,12 @@ void tst_QQmlMetaObject::method_data()
<< ""
<< (QList<QByteArray>() << "QColor" << "QDateTime" << "QUrl")
<< (QList<QByteArray>() << "foo" << "bar" << "baz");
+ QTest::newRow("testSignal(double foo)") << "signal.6.qml"
+ << "testSignal(double)"
+ << QMetaMethod::Signal
+ << ""
+ << (QList<QByteArray>() << "double")
+ << (QList<QByteArray>() << "foo");
}
void tst_QQmlMetaObject::method()