From ecec9edd5a5ab4157e860268b56dc77dbc49d748 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 4 Sep 2014 20:52:18 +0200 Subject: QPolygon: add a smoke-test for boundingRect() Nothing fancy, just a safety-net for a following refactoring. Change-Id: I5be87c86cd61e24bf96881d2485dd7560ea6184a Reviewed-by: Gunnar Sletta --- tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp | 77 +++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp index 4d6f52bf8a..13b6e28f5f 100644 --- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp +++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp @@ -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("poly"); + QTest::addColumn("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("poly"); + QTest::addColumn("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 -- cgit v1.2.3