diff options
Diffstat (limited to 'tests/auto/gui/painting')
-rw-r--r-- | tests/auto/gui/painting/painting.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 52 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 63 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp | 21 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpathclipper/qpathclipper.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp | 77 | ||||
-rw-r--r-- | tests/auto/gui/painting/qregion/tst_qregion.cpp | 40 | ||||
-rw-r--r-- | tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp | 2 |
8 files changed, 229 insertions, 30 deletions
diff --git a/tests/auto/gui/painting/painting.pro b/tests/auto/gui/painting/painting.pro index 0f7595c871..831fffab30 100644 --- a/tests/auto/gui/painting/painting.pro +++ b/tests/auto/gui/painting/painting.pro @@ -16,7 +16,7 @@ SUBDIRS=\ qwmatrix \ qpolygon \ -!contains(QT_CONFIG, private_tests): SUBDIRS -= \ +!qtConfig(private_tests): SUBDIRS -= \ qpathclipper \ diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 00e7436c0f..ab893385e3 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -52,6 +52,7 @@ private slots: void name(); void namehex_data(); void namehex(); + void setNamedColor_data(); void setNamedColor(); void constructNamedColorWithSpace(); @@ -525,26 +526,49 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData); #undef rgb -void tst_QColor::setNamedColor() +void tst_QColor::setNamedColor_data() { - for (int i = 0; i < rgbTblSize; ++i) { - QColor expected; - expected.setRgba(rgbTbl[i].value); - - QColor color; - color.setNamedColor(QLatin1String(rgbTbl[i].name)); - QCOMPARE(color, expected); + QTest::addColumn<QColor>("byCtor"); + QTest::addColumn<QColor>("bySetNamedColor"); + QTest::addColumn<QColor>("expected"); + for (const auto e : rgbTbl) { + QColor expected; + expected.setRgba(e.value); + +#define ROW(expr) \ + do { \ + QColor bySetNamedColor; \ + bySetNamedColor.setNamedColor(expr); \ + auto byCtor = QColor(expr); \ + QTest::newRow(e.name + QByteArrayLiteral(#expr)) \ + << byCtor << bySetNamedColor << expected; \ + } while (0) \ + /*end*/ + + ROW(QLatin1String(e.name)); + ROW(QString(QLatin1String(e.name))); // name should be case insensitive - color.setNamedColor(QString(rgbTbl[i].name).toUpper()); - QCOMPARE(color, expected); - + ROW(QLatin1String(QByteArray(e.name).toUpper())); + ROW(QString(e.name).toUpper()); // spaces should be ignored - color.setNamedColor(QString(rgbTbl[i].name).insert(1, ' ')); - QCOMPARE(color, expected); + ROW(QLatin1String(QByteArray(e.name).insert(1, ' '))); + ROW(QString(e.name).insert(1, ' ')); +#undef ROW } } +void tst_QColor::setNamedColor() +{ + QFETCH(QColor, byCtor); + QFETCH(QColor, bySetNamedColor); + QFETCH(QColor, expected); + + QCOMPARE(byCtor, expected); + QCOMPARE(bySetNamedColor, expected); +} + + void tst_QColor::constructNamedColorWithSpace() { QColor whiteSmoke("white smoke"); @@ -556,7 +580,7 @@ void tst_QColor::colorNames() QStringList all = QColor::colorNames(); QCOMPARE(all.size(), rgbTblSize); for (int i = 0; i < all.size(); ++i) - QCOMPARE(all.at(i), QString::fromLatin1(rgbTbl[i].name)); + QCOMPARE(all.at(i), QLatin1String(rgbTbl[i].name)); } void tst_QColor::spec() diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 8a97a9261f..1bd7f67810 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -39,9 +39,7 @@ #include <qimage.h> #include <qthread.h> #include <limits.h> -#if !defined(Q_OS_WINCE) #include <math.h> -#endif #include <qpaintengine.h> #ifndef QT_NO_WIDGETS #include <qdesktopwidget.h> @@ -297,6 +295,9 @@ private slots: void QTBUG50153_drawImage_assert(); + void rotateImage_data(); + void rotateImage(); + private: void fillData(); void setPenColor(QPainter& p); @@ -5061,6 +5062,64 @@ void tst_QPainter::QTBUG50153_drawImage_assert() } } +void tst_QPainter::rotateImage_data() +{ + QTest::addColumn<QImage>("image"); + QTest::addColumn<bool>("smooth"); + + QImage image(128, 128, QImage::Format_RGB32); + for (int y = 0; y < 128; ++y) { + for (int x = 0; x < 128; ++x) { + image.setPixel(x, y, qRgb(x + y, x + y, x + y)); + } + } + + QTest::newRow("fast") << image << false; + QTest::newRow("smooth") << image << true; +} + +void tst_QPainter::rotateImage() +{ + QFETCH(QImage, image); + QFETCH(bool, smooth); + + QImage dest(184, 184, QImage::Format_ARGB32_Premultiplied); + dest.fill(Qt::transparent); + + QPainter painter(&dest); + QTransform transform; + transform.translate(92, 0); + transform.rotate(45); + painter.setTransform(transform); + painter.setRenderHint(QPainter::SmoothPixmapTransform, smooth); + painter.drawImage(0, 0, image); + painter.end(); + + QRgb lastRow = qRgba(0, 0, 0, 0); + for (int y = 0; y < 184; ++y) { + QRgb row = qRgba(0, 0, 0, 0); + for (int x = 0; x < 184; ++x) { + QRgb pixel = dest.pixel(x, y); + if (qAlpha(pixel) < 255) + continue; + if (qAlpha(row) == 0) { + row = pixel; + } else { + QCOMPARE(qRed(pixel), qGreen(pixel)); + QCOMPARE(qGreen(pixel), qBlue(pixel)); + QVERIFY(qAbs(qRed(row) - qRed(pixel)) <= 2); + QVERIFY(qAbs(qGreen(row) - qGreen(pixel)) <= 2); + QVERIFY(qAbs(qBlue(row) - qBlue(pixel)) <= 2); + } + + } + if (qAlpha(row) && qAlpha(lastRow)) + QVERIFY(qGray(lastRow) <= qGray(row)); + lastRow = row; + } + +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index 0261f60479..98f63984b3 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -840,22 +840,23 @@ void tst_QPainterPath::testArcMoveTo_data() QTest::addColumn<QRectF>("rect"); QTest::addColumn<qreal>("angle"); - QList<QRectF> rects; - rects << QRectF(100, 100, 100, 100) - << QRectF(100, 100, -100, 100) - << QRectF(100, 100, 100, -100) - << QRectF(100, 100, -100, -100); - - for (int domain=0; domain<rects.size(); ++domain) { + static Q_CONSTEXPR QRectF rects[] = { + QRectF(100, 100, 100, 100), + QRectF(100, 100, -100, 100), + QRectF(100, 100, 100, -100), + QRectF(100, 100, -100, -100), + }; + + for (uint domain = 0; domain < sizeof rects / sizeof *rects; ++domain) { const QByteArray dB = QByteArray::number(domain); for (int i=-360; i<=360; ++i) { QTest::newRow(("test " + dB + ' ' + QByteArray::number(i)).constData()) - << rects.at(domain) << (qreal) i; + << rects[domain] << (qreal) i; } // test low angles - QTest::newRow("low angles 1") << rects.at(domain) << (qreal) 1e-10; - QTest::newRow("low angles 2") << rects.at(domain) << (qreal)-1e-10; + QTest::newRow("low angles 1") << rects[domain] << (qreal) 1e-10; + QTest::newRow("low angles 2") << rects[domain] << (qreal)-1e-10; } } diff --git a/tests/auto/gui/painting/qpathclipper/qpathclipper.pro b/tests/auto/gui/painting/qpathclipper/qpathclipper.pro index e153460bf2..671220f94b 100644 --- a/tests/auto/gui/painting/qpathclipper/qpathclipper.pro +++ b/tests/auto/gui/painting/qpathclipper/qpathclipper.pro @@ -5,6 +5,6 @@ HEADERS += paths.h SOURCES += tst_qpathclipper.cpp paths.cpp QT += gui-private testlib -requires(contains(QT_CONFIG,private_tests)) +requires(qtConfig(private_tests)) unix:!darwin:!haiku:!integrity: LIBS += -lm 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<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 diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp index d24435198e..6a297dbfc2 100644 --- a/tests/auto/gui/painting/qregion/tst_qregion.cpp +++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp @@ -47,6 +47,7 @@ public: private slots: void moveSemantics(); void boundingRect(); + void rangeFor(); void rects(); void swap(); void setRects(); @@ -136,17 +137,34 @@ void tst_QRegion::boundingRect() } +void tst_QRegion::rangeFor() +{ + // compile-only test for range-for over QRegion, so really useless + // content otherwise: + QRect rect(10, -20, 30, 40); + QRegion region(rect); + int equal = 0; + for (const QRect &r : region) // check this compiles + equal += int(r == rect); // can't use QCOMPARE here b/c of the + // MSVC 201272013 parse bug re: + // do-while in range-for loops + QCOMPARE(equal, 1); +} + void tst_QRegion::rects() { { QRect rect; QRegion region(rect); QVERIFY(region.isEmpty()); + QCOMPARE(region.begin(), region.end()); QVERIFY(region.rects().isEmpty()); } { QRect rect(10, -20, 30, 40); QRegion region(rect); + QCOMPARE(region.end(), region.begin() + 1); + QCOMPARE(*region.begin(), rect); QCOMPARE(region.rects().count(), 1); QCOMPARE(region.rects()[0], rect); } @@ -192,6 +210,7 @@ void tst_QRegion::setRects() region.setRects(&rect, 0); QVERIFY(region.isEmpty()); QCOMPARE(region, QRegion()); + QCOMPARE(region.begin(), region.end()); QVERIFY(!region.boundingRect().isValid()); QVERIFY(region.rects().isEmpty()); } @@ -199,6 +218,7 @@ void tst_QRegion::setRects() QRegion region; QRect rect; region.setRects(&rect, 1); + QCOMPARE(region.begin(), region.end()); QVERIFY(!region.boundingRect().isValid()); QVERIFY(region.rects().isEmpty()); } @@ -206,8 +226,10 @@ void tst_QRegion::setRects() QRegion region; QRect rect(10, -20, 30, 40); region.setRects(&rect, 1); + QCOMPARE(region.end(), region.begin() + 1); QCOMPARE(region.rects().count(), 1); QCOMPARE(region.rects()[0], rect); + QCOMPARE(*region.begin(), rect); } } @@ -320,8 +342,12 @@ void tst_QRegion::emptyPolygonRegion() QRegion r(pa); QTEST(r.isEmpty(), "isEmpty"); + QTEST(int(std::distance(r.begin(), r.end())), "numRects"); + QVector<QRect> rects; + std::copy(r.begin(), r.end(), std::back_inserter(rects)); QTEST(r.rects().count(), "numRects"); QTEST(r.rects(), "rects"); + QCOMPARE(r.rects(), rects); } @@ -860,6 +886,7 @@ void tst_QRegion::isEmpty() QFETCH(QRegion, region); QVERIFY(region.isEmpty()); + QCOMPARE(region.begin(), region.end()); QCOMPARE(region, QRegion()); QCOMPARE(region.rectCount(), 0); QCOMPARE(region.boundingRect(), QRect()); @@ -892,6 +919,11 @@ void tst_QRegion::regionFromPath() path.addRect(0, 100, 100, 1000); QRegion rgn(path.toFillPolygon().toPolygon()); + + QCOMPARE(rgn.end(), rgn.begin() + 2); + QCOMPARE(rgn.begin()[0], QRect(0, 0, 10, 10)); + QCOMPARE(rgn.begin()[1], QRect(0, 100, 100, 1000)); + QCOMPARE(rgn.rects().size(), 2); QCOMPARE(rgn.rects().at(0), QRect(0, 0, 10, 10)); QCOMPARE(rgn.rects().at(1), QRect(0, 100, 100, 1000)); @@ -905,8 +937,14 @@ void tst_QRegion::regionFromPath() path.addRect(10, 10, 80, 80); QRegion rgn(path.toFillPolygon().toPolygon()); - QCOMPARE(rgn.rects().size(), 4); + QCOMPARE(rgn.end(), rgn.begin() + 4); + QCOMPARE(rgn.begin()[0], QRect(0, 0, 100, 10)); + QCOMPARE(rgn.begin()[1], QRect(0, 10, 10, 80)); + QCOMPARE(rgn.begin()[2], QRect(90, 10, 10, 80)); + QCOMPARE(rgn.begin()[3], QRect(0, 90, 100, 10)); + + QCOMPARE(rgn.rects().size(), 4); QCOMPARE(rgn.rects().at(0), QRect(0, 0, 100, 10)); QCOMPARE(rgn.rects().at(1), QRect(0, 10, 10, 80)); QCOMPARE(rgn.rects().at(2), QRect(90, 10, 10, 80)); diff --git a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp index e05d7dd022..a79526c434 100644 --- a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp +++ b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp @@ -114,7 +114,7 @@ void tst_QWMatrix::mapping_data() << QRect( 0, 0, 30, 40 ) << QPolygon( QRect( -300, -400, 300, 400 ) ); -#if (defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(M_PI) +#if defined(Q_OS_WIN) && !defined(M_PI) #define M_PI 3.14159265897932384626433832795f #endif |