QPolygon: add a smoke-test for boundingRect()

Nothing fancy, just a safety-net for a following refactoring.

Change-Id: I5be87c86cd61e24bf96881d2485dd7560ea6184a
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
bb10
Marc Mutz 2014-09-04 20:52:18 +02:00
parent 2d1f137173
commit ecec9edd5a
1 changed files with 77 additions and 0 deletions

View File

@ -43,6 +43,10 @@ public:
tst_QPolygon();
private slots:
void boundingRect_data();
void boundingRect();
void boundingRectF_data();
void boundingRectF();
void makeEllipse();
void swap();
};
@ -51,6 +55,79 @@ tst_QPolygon::tst_QPolygon()
{
}
void tst_QPolygon::boundingRect_data()
{
QTest::addColumn<QPolygon>("poly");
QTest::addColumn<QRect>("brect");
#define ROW(args, rect) \
do { \
QPolygon poly; \
poly.setPoints args; \
QTest::newRow(#args) << poly << QRect rect; \
} while (0)
QTest::newRow("empty") << QPolygon() << QRect(0, 0, 0, 0);
ROW((1, 0,1), ( 0, 1, 1, 1));
ROW((2, 0,1, 1,0), ( 0, 0, 2, 2));
ROW((3, -1,1, -1,-1, 1,0), (-1,-1, 3, 3));
#undef ROW
}
void tst_QPolygon::boundingRect()
{
QFETCH(QPolygon, poly);
QFETCH(QRect, brect);
QCOMPARE(poly.boundingRect(), brect);
}
namespace {
struct MyPolygonF : QPolygonF
{
// QPolygonF doesn't have setPoints...
void setPoints(int nPoints, int firstx, int firsty, ...) {
va_list ap;
reserve(nPoints);
*this << QPointF(firstx, firsty);
va_start(ap, firsty);
while (--nPoints) {
const int x = va_arg(ap, int);
const int y = va_arg(ap, int);
*this << QPointF(x, y);
}
va_end(ap);
}
};
}
void tst_QPolygon::boundingRectF_data()
{
QTest::addColumn<QPolygonF>("poly");
QTest::addColumn<QRectF>("brect");
#define ROW(args, rect) \
do { \
MyPolygonF poly; \
poly.setPoints args; \
QTest::newRow(#args) << QPolygonF(poly) << QRectF rect; \
} while (0)
QTest::newRow("empty") << QPolygonF() << QRectF(0, 0, 0, 0);
ROW((1, 0,1), ( 0, 1, 0, 0));
ROW((2, 0,1, 1,0), ( 0, 0, 1, 1));
ROW((3, -1,1, -1,-1, 1,0), (-1,-1, 2, 2));
#undef ROW
}
void tst_QPolygon::boundingRectF()
{
QFETCH(QPolygonF, poly);
QFETCH(QRectF, brect);
QCOMPARE(poly.boundingRect(), brect);
}
void tst_QPolygon::makeEllipse()
{
// create an ellipse with R1 = R2 = R, i.e. a circle