From 1d48b9ea56e42b2cf963090078ee2162bde23a25 Mon Sep 17 00:00:00 2001 From: Janne Koskinen Date: Wed, 30 Oct 2013 12:08:36 +0200 Subject: Fixed rounding errors in QtQuick1 to int conversions qRound introduced errors when qreal is single precision. Added double signature for qround so that string and int don't lose precision in conversion. Task-number: QTBUG-33625 Change-Id: I58582f57d5cd68fcad3fe9efb5fea5935f61b9e3 Reviewed-by: Olivier Goffart Reviewed-by: Thiago Macieira --- .../qdeclarativevaluetypes/data/qtbug-33625.qml | 12 ++++++++++++ .../qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/qtbug-33625.qml (limited to 'tests/auto') diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/qtbug-33625.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/qtbug-33625.qml new file mode 100644 index 0000000000..977028fc5d --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/qtbug-33625.qml @@ -0,0 +1,12 @@ +import QtQuick 1.0 +Item { + property string stringtest: "16777237" + property int stringint: stringtest + + property int inttest: 16777237 + property int intint: 0 + + Component.onCompleted: { + intint = inttest; + } +} diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index 87a60e30e5..a21ffc634d 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -96,6 +96,7 @@ private slots: void returnValues(); void varAssignment(); void bindingsSpliceCorrectly(); + void qtbug_33625(); private: QDeclarativeEngine engine; @@ -1012,6 +1013,19 @@ void tst_qdeclarativevaluetypes::bindingsSpliceCorrectly() } } +//qreal as float should not limit int to single precision. +void tst_qdeclarativevaluetypes::qtbug_33625() +{ + QDeclarativeComponent component(&engine, TEST_FILE("qtbug-33625.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("intint").toInt(), 16777237); + QCOMPARE(object->property("stringint").toInt(), 16777237); + + delete object; +} + QTEST_MAIN(tst_qdeclarativevaluetypes) #include "tst_qdeclarativevaluetypes.moc" -- cgit v1.2.3