Improve QPoint and QPointF auto tests.

Improve test coverage for QPoint and QPointF.
Separate QPointF tests into their own project.

Change-Id: Id28dc5b85aba9fc179d87b2bca1d99854f27a5ab
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mitch Curtis 2012-07-05 17:06:31 +02:00 committed by Qt by Nokia
parent fe40b8f4ad
commit 376135c403
4 changed files with 669 additions and 62 deletions

View File

@ -41,7 +41,6 @@
#include <QtTest/QtTest>
#include <qcoreapplication.h>
#include <qdebug.h>
#include <qpoint.h>
@ -49,84 +48,302 @@ class tst_QPoint : public QObject
{
Q_OBJECT
private slots:
void getSetCheck();
void division();
void isNull();
void manhattanLength_data();
void manhattanLength();
void getSet_data();
void getSet();
void rx();
void ry();
void operator_add_data();
void operator_add();
void operator_subtract_data();
void operator_subtract();
void operator_multiply_data();
void operator_multiply();
void operator_divide_data();
void operator_divide();
void operator_unary_minus_data();
void operator_unary_minus();
void operator_eq_data();
void operator_eq();
#ifndef QT_NO_DATASTREAM
void stream_data();
void stream();
#endif
};
void tst_QPoint::isNull()
{
QPoint point(0, 0);
QVERIFY(point.isNull());
++point.rx();
QVERIFY(!point.isNull());
point.rx() -= 2;
QVERIFY(!point.isNull());
}
void tst_QPoint::manhattanLength_data()
{
QTest::addColumn<QPoint>("point");
QTest::addColumn<int>("expected");
QTest::newRow("(0, 0)") << QPoint(0, 0) << 0;
QTest::newRow("(10, 0)") << QPoint(10, 0) << 10;
QTest::newRow("(0, 10)") << QPoint(0, 10) << 10;
QTest::newRow("(10, 20)") << QPoint(10, 20) << 30;
QTest::newRow("(-10, -20)") << QPoint(-10, -20) << 30;
}
void tst_QPoint::manhattanLength()
{
{
QPoint p(10, 20);
QCOMPARE(p.manhattanLength(), 30);
}
{
QPointF p(10., 20.);
QCOMPARE(p.manhattanLength(), 30.);
}
{
QPointF p(10.1, 20.2);
QCOMPARE(p.manhattanLength(), 30.3);
}
QFETCH(QPoint, point);
QFETCH(int, expected);
QCOMPARE(point.manhattanLength(), expected);
}
// Testing get/set functions
void tst_QPoint::getSetCheck()
void tst_QPoint::getSet_data()
{
QPoint obj1;
// int QPoint::x()
// void QPoint::setX(int)
obj1.setX(0);
QCOMPARE(0, obj1.x());
obj1.setX(INT_MIN);
QCOMPARE(INT_MIN, obj1.x());
obj1.setX(INT_MAX);
QCOMPARE(INT_MAX, obj1.x());
QTest::addColumn<int>("i");
// int QPoint::y()
// void QPoint::setY(int)
obj1.setY(0);
QCOMPARE(0, obj1.y());
obj1.setY(INT_MIN);
QCOMPARE(INT_MIN, obj1.y());
obj1.setY(INT_MAX);
QCOMPARE(INT_MAX, obj1.y());
QPointF obj2;
// qreal QPointF::x()
// void QPointF::setX(qreal)
obj2.setX(0.0);
QCOMPARE(0.0, obj2.x());
obj2.setX(1.1);
QCOMPARE(1.1, obj2.x());
// qreal QPointF::y()
// void QPointF::setY(qreal)
obj2.setY(0.0);
QCOMPARE(0.0, obj2.y());
obj2.setY(1.1);
QCOMPARE(1.1, obj2.y());
QTest::newRow("0") << 0;
QTest::newRow("INT_MIN") << INT_MIN;
QTest::newRow("INT_MAX") << INT_MAX;
}
static inline qreal dot(const QPointF &a, const QPointF &b)
void tst_QPoint::getSet()
{
return a.x() * b.x() + a.y() * b.y();
QFETCH(int, i);
QPoint point;
point.setX(i);
QCOMPARE(point.x(), i);
point.setY(i);
QCOMPARE(point.y(), i);
}
void tst_QPoint::division()
void tst_QPoint::rx()
{
{
QPointF p(1e-14, 1e-14);
p = p / sqrt(dot(p, p));
qFuzzyCompare(dot(p, p), 1);
}
{
QPointF p(1e-14, 1e-14);
p /= sqrt(dot(p, p));
qFuzzyCompare(dot(p, p), 1);
}
const QPoint originalPoint(-1, 0);
QPoint point(originalPoint);
++point.rx();
QCOMPARE(point.x(), originalPoint.x() + 1);
}
void tst_QPoint::ry()
{
const QPoint originalPoint(0, -1);
QPoint point(originalPoint);
++point.ry();
QCOMPARE(point.y(), originalPoint.y() + 1);
}
void tst_QPoint::operator_add_data()
{
QTest::addColumn<QPoint>("point1");
QTest::addColumn<QPoint>("point2");
QTest::addColumn<QPoint>("expected");
QTest::newRow("(0, 0) + (0, 0)") << QPoint(0, 0) << QPoint(0, 0) << QPoint(0, 0);
QTest::newRow("(0, 9) + (1, 0)") << QPoint(0, 9) << QPoint(1, 0) << QPoint(1, 9);
QTest::newRow("(INT_MIN, 0) + (1, 0)") << QPoint(INT_MIN, 0) << QPoint(1, 0) << QPoint(INT_MIN + 1, 0);
QTest::newRow("(INT_MAX, 0) + (-1, 0)") << QPoint(INT_MAX, 0) << QPoint(-1, 0) << QPoint(INT_MAX - 1, 0);
}
void tst_QPoint::operator_add()
{
QFETCH(QPoint, point1);
QFETCH(QPoint, point2);
QFETCH(QPoint, expected);
QCOMPARE(point1 + point2, expected);
point1 += point2;
QCOMPARE(point1, expected);
}
void tst_QPoint::operator_subtract_data()
{
QTest::addColumn<QPoint>("point1");
QTest::addColumn<QPoint>("point2");
QTest::addColumn<QPoint>("expected");
QTest::newRow("(0, 0) - (0, 0)") << QPoint(0, 0) << QPoint(0, 0) << QPoint(0, 0);
QTest::newRow("(0, 9) - (1, 0)") << QPoint(0, 9) << QPoint(1, 0) << QPoint(-1, 9);
QTest::newRow("(INT_MAX, 0) - (1, 0)") << QPoint(INT_MAX, 0) << QPoint(1, 0) << QPoint(INT_MAX - 1, 0);
QTest::newRow("(INT_MIN, 0) - (-1, 0)") << QPoint(INT_MIN, 0) << QPoint(-1, 0) << QPoint(INT_MIN - -1, 0);
}
void tst_QPoint::operator_subtract()
{
QFETCH(QPoint, point1);
QFETCH(QPoint, point2);
QFETCH(QPoint, expected);
QCOMPARE(point1 - point2, expected);
point1 -= point2;
QCOMPARE(point1, expected);
}
enum PrimitiveType { Int, Float, Double };
Q_DECLARE_METATYPE(PrimitiveType)
void tst_QPoint::operator_multiply_data()
{
QTest::addColumn<QPoint>("point");
QTest::addColumn<double>("factorAsDouble");
QTest::addColumn<PrimitiveType>("type");
QTest::addColumn<QPoint>("expected");
QTest::newRow("(0, 0) * 0.0") << QPoint(0, 0) << 0.0 << Double << QPoint(0, 0);
QTest::newRow("(INT_MIN, 1) * 0.5") << QPoint(INT_MIN, 1) << 0.5 << Double << QPoint(qRound(INT_MIN * 0.5), 1);
QTest::newRow("(INT_MAX, 2) * 0.5") << QPoint(INT_MAX, 2) << 0.5 << Double << QPoint(qRound(INT_MAX * 0.5), 1);
QTest::newRow("(0, 0) * 0") << QPoint(0, 0) << 0.0 << Int << QPoint(0, 0);
QTest::newRow("(INT_MIN + 1, 0) * -1") << QPoint(INT_MIN + 1, 0) << -1.0 << Int << QPoint((INT_MIN + 1) * -1, 0);
QTest::newRow("(INT_MAX, 0) * -1") << QPoint(INT_MAX, 0) << -1.0 << Int << QPoint(INT_MAX * -1, 0);
QTest::newRow("(0, 0) * 0.0f") << QPoint(0, 0) << 0.0 << Float << QPoint(0, 0);
QTest::newRow("(INT_MIN, 0) * -0.5f") << QPoint(INT_MIN, 0) << -0.5 << Float << QPoint(qRound(INT_MIN * -0.5f), 0);
}
template<typename T>
void multiplyTest(QPoint point, double factor, const QPoint &expected)
{
T factorAsT = static_cast<T>(factor);
QCOMPARE(point * factorAsT, expected);
// Test with reversed argument version.
QCOMPARE(factorAsT * point, expected);
point *= factorAsT;
QCOMPARE(point, expected);
}
void tst_QPoint::operator_multiply()
{
QFETCH(QPoint, point);
QFETCH(double, factorAsDouble);
QFETCH(PrimitiveType, type);
QFETCH(QPoint, expected);
if (type == Int)
multiplyTest<int>(point, factorAsDouble, expected);
else if (type == Float)
multiplyTest<float>(point, factorAsDouble, expected);
else if (type == Double)
multiplyTest<double>(point, factorAsDouble, expected);
}
void tst_QPoint::operator_divide_data()
{
QTest::addColumn<QPoint>("point");
QTest::addColumn<qreal>("divisor");
QTest::addColumn<QPoint>("expected");
QTest::newRow("(0, 0) / 1") << QPoint(0, 0) << qreal(1) << QPoint(0, 0);
QTest::newRow("(0, 9) / 2") << QPoint(0, 9) << qreal(2) << QPoint(0, 5);
QTest::newRow("(INT_MAX, 0) / 2") << QPoint(INT_MAX, 0) << qreal(2) << QPoint(qRound(INT_MAX / qreal(2)), 0);
QTest::newRow("(INT_MIN, 0) / -1.5") << QPoint(INT_MIN, 0) << qreal(-1.5) << QPoint(qRound(INT_MIN / qreal(-1.5)), 0);
}
void tst_QPoint::operator_divide()
{
QFETCH(QPoint, point);
QFETCH(qreal, divisor);
QFETCH(QPoint, expected);
QCOMPARE(point / divisor, expected);
point /= divisor;
QCOMPARE(point, expected);
}
void tst_QPoint::operator_unary_minus_data()
{
QTest::addColumn<QPoint>("point");
QTest::addColumn<QPoint>("expected");
QTest::newRow("-(0, 0)") << QPoint(0, 0) << QPoint(0, 0);
QTest::newRow("-(-1, 0)") << QPoint(-1, 0) << QPoint(1, 0);
QTest::newRow("-(0, -1)") << QPoint(0, -1) << QPoint(0, 1);
QTest::newRow("-(-INT_MAX, INT_MAX)") << QPoint(-INT_MAX, INT_MAX) << QPoint(INT_MAX, -INT_MAX);
}
void tst_QPoint::operator_unary_minus()
{
QFETCH(QPoint, point);
QFETCH(QPoint, expected);
QCOMPARE(-point, expected);
}
void tst_QPoint::operator_eq_data()
{
QTest::addColumn<QPoint>("point1");
QTest::addColumn<QPoint>("point2");
QTest::addColumn<bool>("expectEqual");
QTest::newRow("(0, 0) == (0, 0)") << QPoint(0, 0) << QPoint(0, 0) << true;
QTest::newRow("(-1, 0) == (-1, 0)") << QPoint(-1, 0) << QPoint(-1, 0) << true;
QTest::newRow("(-1, 0) != (0, 0)") << QPoint(-1, 0) << QPoint(0, 0) << false;
QTest::newRow("(-1, 0) != (0, -1)") << QPoint(-1, 0) << QPoint(0, -1) << false;
QTest::newRow("(1, 99999) != (-1, 99999)") << QPoint(1, 99999) << QPoint(-1, 99999) << false;
QTest::newRow("(INT_MIN, INT_MIN) == (INT_MIN, INT_MIN)") << QPoint(INT_MIN, INT_MIN) << QPoint(INT_MIN, INT_MIN) << true;
QTest::newRow("(INT_MAX, INT_MAX) == (INT_MAX, INT_MAX)") << QPoint(INT_MAX, INT_MAX) << QPoint(INT_MAX, INT_MAX) << true;
}
void tst_QPoint::operator_eq()
{
QFETCH(QPoint, point1);
QFETCH(QPoint, point2);
QFETCH(bool, expectEqual);
bool equal = point1 == point2;
QCOMPARE(equal, expectEqual);
bool notEqual = point1 != point2;
QCOMPARE(notEqual, !expectEqual);
}
#ifndef QT_NO_DATASTREAM
void tst_QPoint::stream_data()
{
QTest::addColumn<QPoint>("point");
QTest::newRow("(0, 0)") << QPoint(0, 0);
QTest::newRow("(-1, 1)") << QPoint(-1, 1);
QTest::newRow("(1, -1)") << QPoint(1, -1);
QTest::newRow("(INT_MIN, INT_MAX)") << QPoint(INT_MIN, INT_MAX);
}
void tst_QPoint::stream()
{
QFETCH(QPoint, point);
QBuffer tmp;
QVERIFY(tmp.open(QBuffer::ReadWrite));
QDataStream stream(&tmp);
// Ensure that stream returned is the same stream we inserted into.
QDataStream &insertionStreamRef(stream << point);
QVERIFY(&insertionStreamRef == &stream);
tmp.seek(0);
QPoint pointFromStream;
QDataStream &extractionStreamRef(stream >> pointFromStream);
QVERIFY(&extractionStreamRef == &stream);
QCOMPARE(pointFromStream, point);
}
#endif
QTEST_MAIN(tst_QPoint)
#include "tst_qpoint.moc"

View File

@ -0,0 +1,4 @@
CONFIG += testcase parallel_test
TARGET = tst_qpointf
QT = core testlib
SOURCES = tst_qpointf.cpp

View File

@ -0,0 +1,385 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <qdebug.h>
#include <qpoint.h>
class tst_QPointF : public QObject
{
Q_OBJECT
public:
tst_QPointF();
private slots:
void isNull();
void manhattanLength_data();
void manhattanLength();
void getSet_data();
void getSet();
void rx();
void ry();
void operator_add_data();
void operator_add();
void operator_subtract_data();
void operator_subtract();
void operator_multiply_data();
void operator_multiply();
void operator_divide_data();
void operator_divide();
void division();
void operator_unary_minus_data();
void operator_unary_minus();
void operator_eq_data();
void operator_eq();
void toPoint_data();
void toPoint();
#ifndef QT_NO_DATASTREAM
void stream_data();
void stream();
#endif
private:
const qreal QREAL_MIN;
const qreal QREAL_MAX;
};
tst_QPointF::tst_QPointF()
: QREAL_MIN(std::numeric_limits<qreal>::min()),
QREAL_MAX(std::numeric_limits<qreal>::max())
{
}
void tst_QPointF::isNull()
{
QPointF point(0, 0);
QVERIFY(point.isNull());
++point.rx();
QVERIFY(!point.isNull());
point.rx() -= 2;
QVERIFY(!point.isNull());
}
void tst_QPointF::manhattanLength_data()
{
QTest::addColumn<QPointF>("point");
QTest::addColumn<qreal>("expected");
QTest::newRow("(0, 0)") << QPointF(0, 0) << qreal(0);
QTest::newRow("(10, 0)") << QPointF(10, 0) << qreal(10);
QTest::newRow("(0, 10)") << QPointF(0, 10) << qreal(10);
QTest::newRow("(10, 20)") << QPointF(10, 20) << qreal(30);
QTest::newRow("(10.1, 20.2)") << QPointF(10.1, 20.2) << qreal(30.3);
QTest::newRow("(-10.1, -20.2)") << QPointF(-10.1, -20.2) << qreal(30.3);
}
void tst_QPointF::manhattanLength()
{
QFETCH(QPointF, point);
QFETCH(qreal, expected);
QCOMPARE(point.manhattanLength(), expected);
}
void tst_QPointF::getSet_data()
{
QTest::addColumn<qreal>("r");
QTest::newRow("0") << qreal(0);
QTest::newRow("-1") << qreal(-1);
QTest::newRow("1") << qreal(1);
QTest::newRow("QREAL_MAX") << qreal(QREAL_MAX);
QTest::newRow("QREAL_MIN") << qreal(QREAL_MIN);
}
void tst_QPointF::getSet()
{
QFETCH(qreal, r);
QPointF point;
point.setX(r);
QCOMPARE(point.x(), r);
point.setY(r);
QCOMPARE(point.y(), r);
}
void tst_QPointF::rx()
{
const QPointF originalPoint(-1, 0);
QPointF point(originalPoint);
++point.rx();
QCOMPARE(point.x(), originalPoint.x() + 1);
}
void tst_QPointF::ry()
{
const QPointF originalPoint(0, -1);
QPointF point(originalPoint);
++point.ry();
QCOMPARE(point.y(), originalPoint.y() + 1);
}
void tst_QPointF::operator_add_data()
{
QTest::addColumn<QPointF>("point1");
QTest::addColumn<QPointF>("point2");
QTest::addColumn<QPointF>("expected");
QTest::newRow("(0, 0) + (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << QPointF(0, 0);
QTest::newRow("(0, 9) + (1, 0)") << QPointF(0, 9) << QPointF(1, 0) << QPointF(1, 9);
QTest::newRow("(QREAL_MIN, 0) + (1, 0)") << QPointF(QREAL_MIN, 0) << QPointF(1, 0) << QPointF(QREAL_MIN + 1, 0);
QTest::newRow("(QREAL_MAX, 0) + (-1, 0)") << QPointF(QREAL_MAX, 0) << QPointF(-1, 0) << QPointF(QREAL_MAX - 1, 0);
}
void tst_QPointF::operator_add()
{
QFETCH(QPointF, point1);
QFETCH(QPointF, point2);
QFETCH(QPointF, expected);
QCOMPARE(point1 + point2, expected);
point1 += point2;
QCOMPARE(point1, expected);
}
void tst_QPointF::operator_subtract_data()
{
QTest::addColumn<QPointF>("point1");
QTest::addColumn<QPointF>("point2");
QTest::addColumn<QPointF>("expected");
QTest::newRow("(0, 0) - (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << QPointF(0, 0);
QTest::newRow("(0, 9) - (1, 0)") << QPointF(0, 9) << QPointF(1, 0) << QPointF(-1, 9);
QTest::newRow("(QREAL_MAX, 0) - (1, 0)") << QPointF(QREAL_MAX, 0) << QPointF(1, 0) << QPointF(QREAL_MAX - 1, 0);
QTest::newRow("(QREAL_MIN, 0) - (-1, 0)") << QPointF(QREAL_MIN, 0) << QPointF(-1, 0) << QPointF(QREAL_MIN - -1, 0);
}
void tst_QPointF::operator_subtract()
{
QFETCH(QPointF, point1);
QFETCH(QPointF, point2);
QFETCH(QPointF, expected);
QCOMPARE(point1 - point2, expected);
point1 -= point2;
QCOMPARE(point1, expected);
}
void tst_QPointF::operator_multiply_data()
{
QTest::addColumn<QPointF>("point");
QTest::addColumn<qreal>("factor");
QTest::addColumn<QPointF>("expected");
QTest::newRow("(0, 0) * 0.0") << QPointF(0, 0) << qreal(0) << QPointF(0, 0);
QTest::newRow("(QREAL_MIN, 1) * 0.5") << QPointF(QREAL_MIN, 1) << qreal(0.5) << QPointF(QREAL_MIN * 0.5, 0.5);
QTest::newRow("(QREAL_MAX, 2) * 0.5") << QPointF(QREAL_MAX, 2) << qreal(0.5) << QPointF(QREAL_MAX * 0.5, 1);
}
void tst_QPointF::operator_multiply()
{
QFETCH(QPointF, point);
QFETCH(qreal, factor);
QFETCH(QPointF, expected);
QCOMPARE(point * factor, expected);
// Test with reversed argument version.
QCOMPARE(factor * point, expected);
point *= factor;
QCOMPARE(point, expected);
}
void tst_QPointF::operator_divide_data()
{
QTest::addColumn<QPointF>("point");
QTest::addColumn<qreal>("divisor");
QTest::addColumn<QPointF>("expected");
QTest::newRow("(0, 0) / 1") << QPointF(0, 0) << qreal(1) << QPointF(0, 0);
QTest::newRow("(0, 9) / 2") << QPointF(0, 9) << qreal(2) << QPointF(0, 4.5);
QTest::newRow("(QREAL_MAX, 0) / 2") << QPointF(QREAL_MAX, 0) << qreal(2) << QPointF(QREAL_MAX / qreal(2), 0);
QTest::newRow("(QREAL_MIN, 0) / -1.5") << QPointF(QREAL_MIN, 0) << qreal(-1.5) << QPointF(QREAL_MIN / qreal(-1.5), 0);
}
void tst_QPointF::operator_divide()
{
QFETCH(QPointF, point);
QFETCH(qreal, divisor);
QFETCH(QPointF, expected);
QCOMPARE(point / divisor, expected);
point /= divisor;
QCOMPARE(point, expected);
}
static inline qreal dot(const QPointF &a, const QPointF &b)
{
return a.x() * b.x() + a.y() * b.y();
}
void tst_QPointF::division()
{
{
QPointF p(1e-14, 1e-14);
p = p / sqrt(dot(p, p));
qFuzzyCompare(dot(p, p), 1);
}
{
QPointF p(1e-14, 1e-14);
p /= sqrt(dot(p, p));
qFuzzyCompare(dot(p, p), 1);
}
}
void tst_QPointF::operator_unary_minus_data()
{
QTest::addColumn<QPointF>("point");
QTest::addColumn<QPointF>("expected");
QTest::newRow("-(0, 0)") << QPointF(0, 0) << QPointF(0, 0);
QTest::newRow("-(-1, 0)") << QPointF(-1, 0) << QPointF(1, 0);
QTest::newRow("-(0, -1)") << QPointF(0, -1) << QPointF(0, 1);
QTest::newRow("-(1.2345, 0)") << QPointF(1.2345, 0) << QPointF(-1.2345, 0);
QTest::newRow("-(-QREAL_MAX, QREAL_MAX)")
<< QPointF(-QREAL_MAX, QREAL_MAX) << QPointF(QREAL_MAX, -QREAL_MAX);
}
void tst_QPointF::operator_unary_minus()
{
QFETCH(QPointF, point);
QFETCH(QPointF, expected);
QCOMPARE(-point, expected);
}
void tst_QPointF::operator_eq_data()
{
QTest::addColumn<QPointF>("point1");
QTest::addColumn<QPointF>("point2");
QTest::addColumn<bool>("expectEqual");
QTest::newRow("(0, 0) == (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << true;
QTest::newRow("(-1, 0) == (-1, 0)") << QPointF(-1, 0) << QPointF(-1, 0) << true;
QTest::newRow("(-1, 0) != (0, 0)") << QPointF(-1, 0) << QPointF(0, 0) << false;
QTest::newRow("(-1, 0) != (0, -1)") << QPointF(-1, 0) << QPointF(0, -1) << false;
QTest::newRow("(-1.125, 0.25) == (-1.125, 0.25)") << QPointF(-1.125, 0.25) << QPointF(-1.125, 0.25) << true;
QTest::newRow("(QREAL_MIN, QREAL_MIN) == (QREAL_MIN, QREAL_MIN)")
<< QPointF(QREAL_MIN, QREAL_MIN) << QPointF(QREAL_MIN, QREAL_MIN) << true;
QTest::newRow("(QREAL_MAX, QREAL_MAX) == (QREAL_MAX, QREAL_MAX)")
<< QPointF(QREAL_MAX, QREAL_MAX) << QPointF(QREAL_MAX, QREAL_MAX) << true;
}
void tst_QPointF::operator_eq()
{
QFETCH(QPointF, point1);
QFETCH(QPointF, point2);
QFETCH(bool, expectEqual);
bool equal = point1 == point2;
QCOMPARE(equal, expectEqual);
bool notEqual = point1 != point2;
QCOMPARE(notEqual, !expectEqual);
}
void tst_QPointF::toPoint_data()
{
QTest::addColumn<QPointF>("pointf");
QTest::addColumn<QPoint>("expected");
QTest::newRow("(0.0, 0.0) ==> (0, 0)") << QPointF(0, 0) << QPoint(0, 0);
QTest::newRow("(0.5, 0.5) ==> (1, 1)") << QPointF(0.5, 0.5) << QPoint(1, 1);
QTest::newRow("(-0.5, -0.5) ==> (0, 0)") << QPointF(-0.5, -0.5) << QPoint(0, 0);
}
void tst_QPointF::toPoint()
{
QFETCH(QPointF, pointf);
QFETCH(QPoint, expected);
QCOMPARE(pointf.toPoint(), expected);
}
#ifndef QT_NO_DATASTREAM
void tst_QPointF::stream_data()
{
QTest::addColumn<QPointF>("point");
QTest::newRow("(0, 0.5)") << QPointF(0, 0.5);
QTest::newRow("(-1, 1)") << QPointF(-1, 1);
QTest::newRow("(1, -1)") << QPointF(1, -1);
QTest::newRow("(INT_MIN, INT_MAX)") << QPointF(INT_MIN, INT_MAX);
}
void tst_QPointF::stream()
{
QFETCH(QPointF, point);
QBuffer tmp;
QVERIFY(tmp.open(QBuffer::ReadWrite));
QDataStream stream(&tmp);
// Ensure that stream returned is the same stream we inserted into.
QDataStream& insertionStreamRef(stream << point);
QVERIFY(&insertionStreamRef == &stream);
tmp.seek(0);
QPointF pointFromStream;
QDataStream& extractionStreamRef(stream >> pointFromStream);
QVERIFY(&extractionStreamRef == &stream);
QCOMPARE(pointFromStream, point);
}
#endif
QTEST_MAIN(tst_QPointF)
#include "tst_qpointf.moc"

View File

@ -23,6 +23,7 @@ SUBDIRS=\
qmargins \
qpair \
qpoint \
qpointf \
qqueue \
qrect \
qregexp \