diff options
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 13 | ||||
-rw-r--r-- | tests/auto/gui/text/qtexttable/tst_qtexttable.cpp | 115 |
2 files changed, 128 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 0ab483222d..7d2d009213 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -2507,6 +2507,19 @@ void tst_QImage::inplaceConversion() } if (image.depth() == imageConverted.depth()) QCOMPARE(imageConverted.constScanLine(0), originalPtr); + + { + // Test attempted inplace conversion of images created on existing, readonly buffer + static const quint32 readOnlyData[] = { 0x00010203U, 0x04050607U, 0x08091011U, 0x12131415U }; + + QImage roImage((const uchar *)readOnlyData, 2, 2, format); + QImage inplaceConverted = std::move(roImage).convertToFormat(dest_format); + + QImage roImage2((const uchar *)readOnlyData, 2, 2, format); + QImage normalConverted = roImage2.convertToFormat(dest_format); + + QCOMPARE(normalConverted, inplaceConverted); + } #endif } diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp index 0ee066be63..c8d3122e6d 100644 --- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp +++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp @@ -44,6 +44,11 @@ #ifndef QT_NO_WIDGETS #include <qtextedit.h> #endif +#ifndef QT_NO_PRINTER +#include <QPagedPaintDevice> +#include <QPainter> +#include <QPaintEngine> +#endif typedef QList<int> IntList; @@ -96,6 +101,9 @@ private slots: void QTBUG11282_insertBeforeMergedEnding(); #endif void QTBUG22011_insertBeforeRowSpan(); +#ifndef QT_NO_PRINTER + void QTBUG31330_renderBackground(); +#endif private: QTextTable *create2x2Table(); @@ -1024,5 +1032,112 @@ void tst_QTextTable::QTBUG22011_insertBeforeRowSpan() QCOMPARE(table->columns(), 6); } +#ifndef QT_NO_PRINTER +namespace { +class QTBUG31330_PaintDevice : public QPagedPaintDevice +{ +public: + class PaintEngine : public QPaintEngine + { + public: + QList<QRectF> rects; + + PaintEngine() + : QPaintEngine(0) + {} + virtual Type type() const + { + return User; + } + virtual bool begin(QPaintDevice *) + { + return true; + } + virtual bool end() + { + return true; + } + virtual void updateState(const QPaintEngineState &) + {} + virtual void drawRects(const QRect *, int) + {} + virtual void drawRects(const QRectF *r, int) + { + if (painter()->brush() == QBrush(Qt::green)) + { + rects.append(*r); + } + } + virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) + {} + }; + + int pages; + QPaintEngine* engine; + + QTBUG31330_PaintDevice(QPaintEngine* engine) + : pages(1), engine(engine) + { + QPageLayout layout = pageLayout(); + layout.setUnits(QPageLayout::Point); + setPageLayout(layout); + } + virtual int metric(PaintDeviceMetric metric) const + { + if (PdmDevicePixelRatio == metric) + return 1; + if (PdmDpiY == metric) + return 96; + if (PdmDpiX == metric) + return 96; + if (PdmHeight == metric) + return 1000; + if (PdmWidth == metric) + return 700; + return 900; + } + virtual QPaintEngine *paintEngine() const + { + return engine; + } + bool newPage() + { + ++pages; + return true; + } +}; +} + +void tst_QTextTable::QTBUG31330_renderBackground() +{ + QTextDocument doc; + QTextCursor cursor(&doc); + QTextTable* table = cursor.insertTable(4, 2); + + QTextTableCell cell = table->cellAt(3, 0); + + QTextCharFormat cellFormat = cell.format(); + cellFormat.setBackground(QBrush(Qt::green)); + cell.setFormat(cellFormat); + + QTextCursor tc = cell.firstCursorPosition(); + for (int i = 0; i < 60; ++i) { + tc.insertBlock(); + } + QTBUG31330_PaintDevice::PaintEngine engine; + QTBUG31330_PaintDevice paintDevice(&engine); + paintDevice.setPageSize(QPagedPaintDevice::A4); + doc.print(&paintDevice); + + QVERIFY(paintDevice.pages >= 2); + QCOMPARE(engine.rects.count(), paintDevice.pages); + for (int i = 0; i < engine.rects.count(); ++i) { + QRectF rect = engine.rects[i]; + QVERIFY(rect.top() > 0); + QVERIFY(rect.bottom() < 1000); + } +} +#endif + QTEST_MAIN(tst_QTextTable) #include "tst_qtexttable.moc" |