summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@nokia.com>2012-08-01 16:02:10 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-22 04:04:57 +0200
commit09dd19df5c4b708960e5aade568eb15d996ef200 (patch)
tree3a997704b1324dfb45f69d892128399affcac242 /tests/auto/corelib/tools
parent7f469ef4cc614925d7a4fdb3380ff5470e25b03b (diff)
Do not consider sign in qIsNull.
The current implementation of qIsNull only returns true if the value is positive zero. This behaviour is not useful for use cases like QPointF::isNull, where QPointF(-0, -0).isNull() will return false. There doesn't seem to be a reason why the function exhibits this behaviour (-0.0 is not accounted for in the unit tests), and for the case of QSizeF::scale it causes a bug: qIsNull is used to check for division by 0.0 before it proceeds, which fails in the case of -0.0. Task-number: QTBUG-7303 Change-Id: I767e5280bd26614e8e78ae62b274eb9bc4ade385 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qpointf/tst_qpointf.cpp5
-rw-r--r--tests/auto/corelib/tools/qsizef/tst_qsizef.cpp31
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
index d949de5143..df8c7d1d54 100644
--- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
+++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
@@ -111,6 +111,11 @@ void tst_QPointF::isNull()
QVERIFY(!point.isNull());
point.rx() -= 2;
QVERIFY(!point.isNull());
+
+ QPointF nullNegativeZero(qreal(-0.0), qreal(-0.0));
+ QCOMPARE(nullNegativeZero.x(), (qreal)-0.0f);
+ QCOMPARE(nullNegativeZero.y(), (qreal)-0.0f);
+ QVERIFY(nullNegativeZero.isNull());
}
void tst_QPointF::manhattanLength_data()
diff --git a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
index a098abe5b0..67c8c4c550 100644
--- a/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
+++ b/tests/auto/corelib/tools/qsizef/tst_qsizef.cpp
@@ -48,6 +48,9 @@ class tst_QSizeF : public QObject
{
Q_OBJECT
private slots:
+ void isNull_data();
+ void isNull();
+
void scale();
void expandedTo();
@@ -60,6 +63,34 @@ private slots:
void transpose();
};
+void tst_QSizeF::isNull_data()
+{
+ QTest::addColumn<qreal>("width");
+ QTest::addColumn<qreal>("height");
+ QTest::addColumn<bool>("isNull");
+
+ QTest::newRow("0, 0") << qreal(0.0) << qreal(0.0) << true;
+ QTest::newRow("-0, -0") << qreal(-0.0) << qreal(-0.0) << true;
+ QTest::newRow("0, -0") << qreal(0) << qreal(-0.0) << true;
+ QTest::newRow("-0, 0") << qreal(-0.0) << qreal(0) << true;
+ QTest::newRow("-0.1, 0") << qreal(-0.1) << qreal(0) << false;
+ QTest::newRow("0, -0.1") << qreal(0) << qreal(-0.1) << false;
+ QTest::newRow("0.1, 0") << qreal(0.1) << qreal(0) << false;
+ QTest::newRow("0, 0.1") << qreal(0) << qreal(0.1) << false;
+}
+
+void tst_QSizeF::isNull()
+{
+ QFETCH(qreal, width);
+ QFETCH(qreal, height);
+ QFETCH(bool, isNull);
+
+ QSizeF size(width, height);
+ QCOMPARE(size.width(), width);
+ QCOMPARE(size.height(), height);
+ QCOMPARE(size.isNull(), isNull);
+}
+
void tst_QSizeF::scale() {
QSizeF t1(10.4, 12.8);
t1.scale(60.6, 60.6, Qt::IgnoreAspectRatio);