diff options
Diffstat (limited to 'tests/auto/gui')
27 files changed, 732 insertions, 59 deletions
diff --git a/tests/auto/gui/image/qicon/qicon.pro b/tests/auto/gui/image/qicon/qicon.pro index f48fe90dd8..6ff20ec8fa 100644 --- a/tests/auto/gui/image/qicon/qicon.pro +++ b/tests/auto/gui/image/qicon/qicon.pro @@ -7,4 +7,4 @@ qtHaveModule(widgets): QT += widgets SOURCES += tst_qicon.cpp RESOURCES = tst_qicon.qrc -TESTDATA += icons/* *.png *.svg *.svgz +TESTDATA += icons/* second_icons/* *.png *.svg *.svgz diff --git a/tests/auto/gui/image/qicon/icons/testtheme/32x32/actions/appointment-new.png b/tests/auto/gui/image/qicon/second_icons/testtheme/32x32/actions/appointment-new.png Binary files differindex 85daef3b0b..85daef3b0b 100644 --- a/tests/auto/gui/image/qicon/icons/testtheme/32x32/actions/appointment-new.png +++ b/tests/auto/gui/image/qicon/second_icons/testtheme/32x32/actions/appointment-new.png diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 550dd5bc33..add6da9efb 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -559,10 +559,12 @@ void tst_QIcon::task184901_badCache() void tst_QIcon::fromTheme() { - QString searchPath = QLatin1String(":/icons"); - QIcon::setThemeSearchPaths(QStringList() << searchPath); - QVERIFY(QIcon::themeSearchPaths().size() == 1); - QCOMPARE(searchPath, QIcon::themeSearchPaths()[0]); + QString firstSearchPath = QLatin1String(":/icons"); + QString secondSearchPath = QLatin1String(":/second_icons"); + QIcon::setThemeSearchPaths(QStringList() << firstSearchPath << secondSearchPath); + QVERIFY(QIcon::themeSearchPaths().size() == 2); + QCOMPARE(firstSearchPath, QIcon::themeSearchPaths()[0]); + QCOMPARE(secondSearchPath, QIcon::themeSearchPaths()[1]); QString themeName("testtheme"); QIcon::setThemeName(themeName); @@ -576,6 +578,14 @@ void tst_QIcon::fromTheme() QVERIFY(appointmentIcon.availableSizes().contains(QSize(32, 32))); QVERIFY(appointmentIcon.availableSizes().contains(QSize(22, 22))); + // Test fallback to less specific icon + QIcon specificAppointmentIcon = QIcon::fromTheme("appointment-new-specific"); + QVERIFY(!QIcon::hasThemeIcon("appointment-new-specific")); + QVERIFY(QIcon::hasThemeIcon("appointment-new")); + QCOMPARE(specificAppointmentIcon.name(), QString::fromLatin1("appointment-new")); + QCOMPARE(specificAppointmentIcon.availableSizes(), appointmentIcon.availableSizes()); + QCOMPARE(specificAppointmentIcon.pixmap(32).cacheKey(), appointmentIcon.pixmap(32).cacheKey()); + // Test icon from parent theme QIcon abIcon = QIcon::fromTheme("address-book-new"); QVERIFY(!abIcon.isNull()); diff --git a/tests/auto/gui/image/qicon/tst_qicon.qrc b/tests/auto/gui/image/qicon/tst_qicon.qrc index dc11a87ddd..1505ca925b 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.qrc +++ b/tests/auto/gui/image/qicon/tst_qicon.qrc @@ -5,7 +5,7 @@ <file>rect.png</file> <file>./icons/testtheme/16x16/actions/appointment-new.png</file> <file>./icons/testtheme/22x22/actions/appointment-new.png</file> -<file>./icons/testtheme/32x32/actions/appointment-new.png</file> +<file>./second_icons/testtheme/32x32/actions/appointment-new.png</file> <file>./icons/testtheme/index.theme</file> <file>./icons/testtheme/scalable/actions/svg-only.svg</file> <file>./icons/themeparent/16x16/actions/address-book-new.png</file> diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index ed1d915670..9feec3f6c7 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -776,6 +776,13 @@ void tst_QImage::convertToFormat_data() << int(QImage::Format_ARGB32) << 0xff00ff00; QTest::newRow("blue rgb30 -> argb32") << int(QImage::Format_RGB30) << 0xff0000ff << int(QImage::Format_ARGB32) << 0xff0000ff; + + QTest::newRow("white gray8 -> argb pm") << int(QImage::Format_Grayscale8) << 0xfffffeffu + << int(QImage::Format_ARGB32_Premultiplied) << 0xfffefefeu; + QTest::newRow("gray gray8 -> argb pm") << int(QImage::Format_Grayscale8) << 0xff565557u + << int(QImage::Format_ARGB32_Premultiplied) << 0xff555555u; + QTest::newRow("black gray8 -> argb pm") << int(QImage::Format_Grayscale8) << 0xff000100u + << int(QImage::Format_ARGB32_Premultiplied) << 0xff000000u; } @@ -1005,6 +1012,10 @@ void tst_QImage::rotate_data() << QImage::Format_RGBX8888 << d; QTest::newRow(qPrintable(title.arg("Format_RGBA8888_Premultiplied"))) << QImage::Format_RGBA8888_Premultiplied << d; + QTest::newRow(qPrintable(title.arg("Format_Alpha8"))) + << QImage::Format_Alpha8 << d; + QTest::newRow(qPrintable(title.arg("Format_Grayscale8"))) + << QImage::Format_Grayscale8 << d; } } @@ -2093,16 +2104,20 @@ void tst_QImage::fillPixel_data() QTest::newRow("ARGB32, transparent") << QImage::Format_ARGB32 << 0x0u << 0x00000000u; QTest::newRow("ARGB32pm, transparent") << QImage::Format_ARGB32_Premultiplied << 0x0u << 0x00000000u; QTest::newRow("RGBA8888pm, transparent") << QImage::Format_RGBA8888_Premultiplied << 0x0u << 0x00000000u; + QTest::newRow("Alpha8, transparent") << QImage::Format_Alpha8 << 0x0u << 0x00000000u; QTest::newRow("RGB16, red") << QImage::Format_RGB16 << (uint)qConvertRgb32To16(0xffff0000) << 0xffff0000u; QTest::newRow("RGB32, red") << QImage::Format_RGB32 << 0xffff0000u << 0xffff0000u; QTest::newRow("ARGB32, red") << QImage::Format_ARGB32 << 0xffff0000u << 0xffff0000u; QTest::newRow("RGBA8888, red") << QImage::Format_RGBA8888 << 0xff0000ffu << 0xffff0000u; + QTest::newRow("Grayscale8, grey") << QImage::Format_Grayscale8 << 0xff808080u << 0xff808080u; + QTest::newRow("RGB32, semi-red") << QImage::Format_RGB32 << 0x80ff0000u << 0xffff0000u; QTest::newRow("ARGB32, semi-red") << QImage::Format_ARGB32 << 0x80ff0000u << 0x80ff0000u; QTest::newRow("ARGB32pm, semi-red") << QImage::Format_ARGB32 << 0x80800000u << 0x80800000u; QTest::newRow("RGBA8888pm, semi-red") << QImage::Format_RGBA8888_Premultiplied << 0x80000080u << 0x80800000u; + QTest::newRow("Alpha8, semi-red") << QImage::Format_Alpha8 << 0x80000080u << 0x80000000u; } void tst_QImage::fillPixel() diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index f1c1012371..f6b8fbcab9 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -487,13 +487,13 @@ void tst_QImageReader::imageFormat_data() QTest::addColumn<QImage::Format>("imageFormat"); QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm") << QImage::Format_Mono; - QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm") << QImage::Format_Indexed8; + QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm") << QImage::Format_Grayscale8; QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm") << QImage::Format_RGB32; QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm") << QImage::Format_RGB32; QTest::newRow("ppm-3") << QString("runners.ppm") << QByteArray("ppm") << QImage::Format_RGB32; QTest::newRow("ppm-4") << QString("test.ppm") << QByteArray("ppm") << QImage::Format_RGB32; - QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg") << QImage::Format_Indexed8; + QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg") << QImage::Format_Grayscale8; QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_RGB32; QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg") << QImage::Format_RGB32; diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 6a7bbc3119..a327932a3c 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -281,7 +281,7 @@ void tst_QPixmap::fromImage() image.fill(0x7f7f7f7f); const QPixmap pixmap = QPixmap::fromImage(image); -#ifdef Q_WS_X11 +#ifdef Q_DEAD_CODE_FROM_QT4_X11 if (pixmap.handle()->classId() == QPlatformPixmap::X11Class && !pixmap.x11PictureHandle()) QSKIP("Requires XRender support"); #endif @@ -510,7 +510,7 @@ void tst_QPixmap::fill() else pm = QPixmap(400, 400); -#if defined(Q_WS_X11) +#if defined(Q_DEAD_CODE_FROM_QT4_X11) if (!bitmap && pm.handle()->classId() == QPlatformPixmap::X11Class && !pm.x11PictureHandle()) QSKIP("Requires XRender support"); #endif @@ -540,7 +540,7 @@ void tst_QPixmap::fill() void tst_QPixmap::fill_transparent() { QPixmap pixmap(10, 10); -#ifdef Q_WS_X11 +#ifdef Q_DEAD_CODE_FROM_QT4_X11 if (pixmap.handle()->classId() == QPlatformPixmap::X11Class && !pixmap.x11PictureHandle()) QSKIP("Requires XRender support"); #endif diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index 310fd58b7f..b14d2cf288 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -812,6 +812,33 @@ void tst_QGuiApplication::quitOnLastWindowClosed() QCOMPARE(spy.count(), 1); QVERIFY(spy2.count() > 15); // Should be around 20 if closing did not cause the quit } + { + int argc = 0; + QGuiApplication app(argc, 0); + app.setQuitOnLastWindowClosed(false); + + QTimer timer; + timer.setInterval(2000); + timer.setSingleShot(true); + QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit())); + + QSignalSpy spy(&app, SIGNAL(lastWindowClosed())); + QSignalSpy spy2(&timer, SIGNAL(timeout())); + + QPointer<QWindow> mainWindow = new QWindow; + + mainWindow->show(); + + QTimer::singleShot(1000, mainWindow, SLOT(close())); // This should not quit the application + timer.start(); + + app.exec(); + + QCOMPARE(spy2.count(), 1); // quit timer fired + QCOMPARE(spy.count(), 1); // lastWindowClosed emitted + + app.setQuitOnLastWindowClosed(true); // restore underlying static to default value + } } static Qt::ScreenOrientation testOrientationToSend = Qt::PrimaryOrientation; diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 61ba99c7de..41a53ddd55 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -63,6 +63,7 @@ private slots: void positioning_data(); void positioning(); void positioningDuringMinimized(); + void platformSurface(); void isExposed(); void isActive(); void testInputEvents(); @@ -161,10 +162,21 @@ public: { m_received[event->type()]++; m_order << event->type(); - if (event->type() == QEvent::Expose) + switch (event->type()) { + case QEvent::Expose: m_exposeRegion = static_cast<QExposeEvent *>(event)->region(); - else if (event->type() == QEvent::Move) + break; + + case QEvent::PlatformSurface: + m_surfaceventType = static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType(); + break; + + case QEvent::Move: m_framePositionsOnMove << framePosition(); + break; + default: + break; + } return QWindow::event(event); } @@ -184,11 +196,17 @@ public: return m_exposeRegion; } + QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const + { + return m_surfaceventType; + } + QVector<QPoint> m_framePositionsOnMove; private: QHash<QEvent::Type, int> m_received; QVector<QEvent::Type> m_order; QRegion m_exposeRegion; + QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType; }; void tst_QWindow::eventOrderOnShow() @@ -355,6 +373,63 @@ void tst_QWindow::positioningDuringMinimized() QTRY_COMPARE(window.geometry(), newGeometry); } +class PlatformWindowFilter : public QObject +{ + Q_OBJECT +public: + PlatformWindowFilter(QObject *parent = 0) + : QObject(parent) + , m_window(Q_NULLPTR) + , m_alwaysExisted(true) + {} + + void setWindow(Window *window) { m_window = window; } + + bool eventFilter(QObject *o, QEvent *e) + { + // Check that the platform surface events are delivered synchronously. + // If they are, the native platform surface should always exist when we + // receive a QPlatformSurfaceEvent + if (e->type() == QEvent::PlatformSurface && o == m_window) { + m_alwaysExisted &= (m_window->handle() != Q_NULLPTR); + } + return false; + } + + bool surfaceExisted() const { return m_alwaysExisted; } + +private: + Window *m_window; + bool m_alwaysExisted; +}; + +void tst_QWindow::platformSurface() +{ + QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); + + Window window; + PlatformWindowFilter filter; + filter.setWindow(&window); + window.installEventFilter(&filter); + + window.setGeometry(geometry); + QCOMPARE(window.geometry(), geometry); + window.create(); + + QTRY_VERIFY(window.received(QEvent::PlatformSurface) == 1); + QTRY_VERIFY(window.surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated); + QTRY_VERIFY(window.handle() != Q_NULLPTR); + + window.destroy(); + QTRY_VERIFY(window.received(QEvent::PlatformSurface) == 2); + QTRY_VERIFY(window.surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed); + QTRY_VERIFY(window.handle() == Q_NULLPTR); + + // Check for synchronous delivery of platform surface events and that the platform + // surface always existed upon event delivery + QTRY_VERIFY(filter.surfaceExisted()); +} + void tst_QWindow::isExposed() { QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize); diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp index cdbc242640..c4cad91006 100644 --- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp @@ -54,6 +54,9 @@ private slots: void normalize_data(); void normalize(); + void inverted_data(); + void inverted(); + void compare(); void add_data(); @@ -80,6 +83,9 @@ private slots: void fromAxisAndAngle_data(); void fromAxisAndAngle(); + void fromRotationMatrix_data(); + void fromRotationMatrix(); + void slerp_data(); void slerp(); @@ -291,6 +297,32 @@ void tst_QQuaternion::normalize() QCOMPARE(v.length(), 1.0f); } +void tst_QQuaternion::inverted_data() +{ + // Use the same test data as the length test. + length_data(); +} +void tst_QQuaternion::inverted() +{ + QFETCH(float, x); + QFETCH(float, y); + QFETCH(float, z); + QFETCH(float, w); + QFETCH(float, len); + + QQuaternion v(w, x, y, z); + QQuaternion u = v.inverted(); + if (v.isNull()) { + QVERIFY(u.isNull()); + } else { + len *= len; + QCOMPARE(-u.x() * len, v.x()); + QCOMPARE(-u.y() * len, v.y()); + QCOMPARE(-u.z() * len, v.z()); + QCOMPARE(u.scalar() * len, v.scalar()); + } +} + // Test the comparison operators for quaternions. void tst_QQuaternion::compare() { @@ -696,6 +728,25 @@ void tst_QQuaternion::fromAxisAndAngle() QVERIFY(qFuzzyCompare(answer.scalar(), result.scalar())); } +// Test quaternion convertion to and from rotation matrix. +void tst_QQuaternion::fromRotationMatrix_data() +{ + fromAxisAndAngle_data(); +} +void tst_QQuaternion::fromRotationMatrix() +{ + QFETCH(float, x1); + QFETCH(float, y1); + QFETCH(float, z1); + QFETCH(float, angle); + + QQuaternion result = QQuaternion::fromAxisAndAngle(QVector3D(x1, y1, z1), angle); + QMatrix3x3 rot3x3 = result.toRotationMatrix(); + QQuaternion answer = QQuaternion::fromRotationMatrix(rot3x3); + + QVERIFY(qFuzzyCompare(answer, result) || qFuzzyCompare(-answer, result)); +} + // Test spherical interpolation of quaternions. void tst_QQuaternion::slerp_data() { diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp index 2d4b6d16b0..2b3fbff000 100644 --- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp @@ -36,6 +36,7 @@ #include <QtGui/qvector2d.h> #include <QtGui/qvector3d.h> #include <QtGui/qvector4d.h> +#include <QtGui/qmatrix4x4.h> class tst_QVectorND : public QObject { @@ -113,6 +114,13 @@ private slots: void divide4_data(); void divide4(); + void divideFactor2_data(); + void divideFactor2(); + void divideFactor3_data(); + void divideFactor3(); + void divideFactor4_data(); + void divideFactor4(); + void negate2_data(); void negate2(); void negate3_data(); @@ -142,6 +150,11 @@ private slots: void dotProduct4_data(); void dotProduct4(); + void project_data(); + void project(); + void unproject_data(); + void unproject(); + void properties(); void metaTypes(); }; @@ -1623,16 +1636,154 @@ void tst_QVectorND::multiplyFactor4() QCOMPARE(v3.w(), v1.w() * factor); } -// Test vector division by a factor for 2D vectors. +// Test component-wise vector division for 2D vectors. void tst_QVectorND::divide2_data() { // Use the same test data as the multiply test. - multiplyFactor2_data(); + multiply2_data(); } void tst_QVectorND::divide2() { QFETCH(float, x1); QFETCH(float, y1); + QFETCH(float, x2); + QFETCH(float, y2); + QFETCH(float, x3); + QFETCH(float, y3); + + QVector2D v1(x1, y1); + QVector2D v2(x2, y2); + QVector2D v3(x3, y3); + + if (v2.x() != 0.0f && v2.y() != 0.0f) { + QVERIFY((v3 / v2) == v1); + + QVector2D v4(v3); + v4 /= v2; + QVERIFY(v4 == v1); + + QCOMPARE(v4.x(), v3.x() / v2.x()); + QCOMPARE(v4.y(), v3.y() / v2.y()); + } + if (v1.x() != 0.0f && v1.y() != 0.0f) { + QVERIFY((v3 / v1) == v2); + + QVector2D v4(v3); + v4 /= v1; + QVERIFY(v4 == v2); + + QCOMPARE(v4.x(), v3.x() / v1.x()); + QCOMPARE(v4.y(), v3.y() / v1.y()); + } +} + +// Test component-wise vector division for 3D vectors. +void tst_QVectorND::divide3_data() +{ + // Use the same test data as the multiply test. + multiply3_data(); +} +void tst_QVectorND::divide3() +{ + QFETCH(float, x1); + QFETCH(float, y1); + QFETCH(float, z1); + QFETCH(float, x2); + QFETCH(float, y2); + QFETCH(float, z2); + QFETCH(float, x3); + QFETCH(float, y3); + QFETCH(float, z3); + + QVector3D v1(x1, y1, z1); + QVector3D v2(x2, y2, z2); + QVector3D v3(x3, y3, z3); + + if (v2.x() != 0.0f && v2.y() != 0.0f && v2.z() != 0.0f) { + QVERIFY((v3 / v2) == v1); + + QVector3D v4(v3); + v4 /= v2; + QVERIFY(v4 == v1); + + QCOMPARE(v4.x(), v3.x() / v2.x()); + QCOMPARE(v4.y(), v3.y() / v2.y()); + QCOMPARE(v4.z(), v3.z() / v2.z()); + } + if (v1.x() != 0.0f && v1.y() != 0.0f && v1.z() != 0.0f) { + QVERIFY((v3 / v1) == v2); + + QVector3D v4(v3); + v4 /= v1; + QVERIFY(v4 == v2); + + QCOMPARE(v4.x(), v3.x() / v1.x()); + QCOMPARE(v4.y(), v3.y() / v1.y()); + QCOMPARE(v4.z(), v3.z() / v1.z()); + } +} + +// Test component-wise vector division for 4D vectors. +void tst_QVectorND::divide4_data() +{ + // Use the same test data as the multiply test. + multiply4_data(); +} +void tst_QVectorND::divide4() +{ + QFETCH(float, x1); + QFETCH(float, y1); + QFETCH(float, z1); + QFETCH(float, w1); + QFETCH(float, x2); + QFETCH(float, y2); + QFETCH(float, z2); + QFETCH(float, w2); + QFETCH(float, x3); + QFETCH(float, y3); + QFETCH(float, z3); + QFETCH(float, w3); + + QVector4D v1(x1, y1, z1, w1); + QVector4D v2(x2, y2, z2, w2); + QVector4D v3(x3, y3, z3, w3); + + if (v2.x() != 0.0f && v2.y() != 0.0f && v2.z() != 0.0f && v2.w() != 0.0f) { + QVERIFY((v3 / v2) == v1); + + QVector4D v4(v3); + v4 /= v2; + QVERIFY(v4 == v1); + + QCOMPARE(v4.x(), v3.x() / v2.x()); + QCOMPARE(v4.y(), v3.y() / v2.y()); + QCOMPARE(v4.z(), v3.z() / v2.z()); + QCOMPARE(v4.w(), v3.w() / v2.w()); + } + if (v1.x() != 0.0f && v1.y() != 0.0f && v1.z() != 0.0f && v1.w() != 0.0f) { + QVERIFY((v3 / v1) == v2); + + QVector4D v4(v3); + v4 /= v1; + QVERIFY(v4 == v2); + + QCOMPARE(v4.x(), v3.x() / v1.x()); + QCOMPARE(v4.y(), v3.y() / v1.y()); + QCOMPARE(v4.z(), v3.z() / v1.z()); + QCOMPARE(v4.w(), v3.w() / v1.w()); + } +} + +// Test vector division by a factor for 2D vectors. +void tst_QVectorND::divideFactor2_data() +{ + // Use the same test data as the multiplyFactor test. + multiplyFactor2_data(); +} +void tst_QVectorND::divideFactor2() +{ + QFETCH(float, x1); + QFETCH(float, y1); QFETCH(float, factor); QFETCH(float, x2); QFETCH(float, y2); @@ -1654,12 +1805,12 @@ void tst_QVectorND::divide2() } // Test vector division by a factor for 3D vectors. -void tst_QVectorND::divide3_data() +void tst_QVectorND::divideFactor3_data() { - // Use the same test data as the multiply test. + // Use the same test data as the multiplyFactor test. multiplyFactor3_data(); } -void tst_QVectorND::divide3() +void tst_QVectorND::divideFactor3() { QFETCH(float, x1); QFETCH(float, y1); @@ -1687,12 +1838,12 @@ void tst_QVectorND::divide3() } // Test vector division by a factor for 4D vectors. -void tst_QVectorND::divide4_data() +void tst_QVectorND::divideFactor4_data() { - // Use the same test data as the multiply test. + // Use the same test data as the multiplyFactor test. multiplyFactor4_data(); } -void tst_QVectorND::divide4() +void tst_QVectorND::divideFactor4() { QFETCH(float, x1); QFETCH(float, y1); @@ -2291,6 +2442,158 @@ void tst_QVectorND::dotProduct4() QCOMPARE(QVector4D::dotProduct(v1, v2), d); } +void tst_QVectorND::project_data() +{ + QTest::addColumn<QVector3D>("point"); + QTest::addColumn<QRect>("viewport"); + QTest::addColumn<QMatrix4x4>("projection"); + QTest::addColumn<QMatrix4x4>("view"); + QTest::addColumn<QVector2D>("result"); + + QMatrix4x4 projection; + projection.ortho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 1000.0f); + + QMatrix4x4 view; + // Located at (0, 0, 10), looking at origin, y is up + view.lookAt(QVector3D(0.0f, 0.0f, 10.0f), QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); + + QMatrix4x4 nullMatrix(0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f); + + QTest::newRow("center") + << QVector3D(0.0f, 0.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector2D(400.0f, 300.0f); + + QTest::newRow("topLeft") + << QVector3D(-1.0f, 1.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector2D(0.0f, 600.0f); + + QTest::newRow("topRight") + << QVector3D(1.0f, 1.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector2D(800.0f, 600.0f); + + QTest::newRow("bottomLeft") + << QVector3D(-1.0f, -1.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector2D(0.0f, 0.0f); + + QTest::newRow("bottomRight") + << QVector3D(1.0f, -1.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector2D(800.0f, 0.0f); + + QTest::newRow("nullMatrix") + << QVector3D(0.0f, 0.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << nullMatrix + << nullMatrix + << QVector2D(400.0f, 300.0f); +} + +void tst_QVectorND::project() +{ + QFETCH(QVector3D, point); + QFETCH(QRect, viewport); + QFETCH(QMatrix4x4, projection); + QFETCH(QMatrix4x4, view); + QFETCH(QVector2D, result); + + QVector3D project = point.project(view, projection, viewport); + + QCOMPARE(project.toVector2D(), result); +} + +void tst_QVectorND::unproject_data() +{ + QTest::addColumn<QVector3D>("point"); + QTest::addColumn<QRect>("viewport"); + QTest::addColumn<QMatrix4x4>("projection"); + QTest::addColumn<QMatrix4x4>("view"); + QTest::addColumn<QVector3D>("result"); + + QMatrix4x4 projection; + projection.ortho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 1000.0f); + + QMatrix4x4 view; + // Located at (0, 0, 10), looking at origin, y is up + view.lookAt(QVector3D(0.0f, 0.0f, 10.0f), QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); + + QMatrix4x4 nullMatrix(0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 0.0f); + + QTest::newRow("center") + << QVector3D(400.0f, 300.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector3D(0.0f, 0.0f, 9.9f); + + QTest::newRow("topLeft") + << QVector3D(0.0f, 600.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector3D(-1.0f, 1.0f, 9.9f); + + QTest::newRow("topRight") + << QVector3D(800.0f, 600.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector3D(1.0f, 1.0f, 9.9f); + + QTest::newRow("bottomLeft") + << QVector3D(0.0f, 0.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector3D(-1.0, -1.0f, 9.9f); + + QTest::newRow("bottomRight") + << QVector3D(800.0f, 0.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << projection + << view + << QVector3D(1.0f, -1.0f, 9.9f); + + QTest::newRow("nullMatrix") + << QVector3D(400.0f, 300.0f, 0.0f) + << QRect(0.0f, 0.0f, 800.0f, 600.0f) + << nullMatrix + << nullMatrix + << QVector3D(0.0f, 0.0f, -1.0f); + +} + +void tst_QVectorND::unproject() +{ + QFETCH(QVector3D, point); + QFETCH(QRect, viewport); + QFETCH(QMatrix4x4, projection); + QFETCH(QMatrix4x4, view); + QFETCH(QVector3D, result); + + QVector3D unproject = point.unproject(view, projection, viewport); + QVERIFY(qFuzzyCompare(unproject, result)); +} + class tst_QVectorNDProperties : public QObject { Q_OBJECT diff --git a/tests/auto/gui/painting/qbrush/qbrush.pro b/tests/auto/gui/painting/qbrush/qbrush.pro index 526de12815..0cb11398dc 100644 --- a/tests/auto/gui/painting/qbrush/qbrush.pro +++ b/tests/auto/gui/painting/qbrush/qbrush.pro @@ -1,5 +1,5 @@ CONFIG += testcase CONFIG += parallel_test TARGET = tst_qbrush -QT += testlib +QT += testlib gui-private SOURCES += tst_qbrush.cpp diff --git a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp index d252a0e87c..5ffba431ff 100644 --- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp +++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp @@ -37,6 +37,7 @@ #include "qbrush.h" #include <QPainter> #include <QBitmap> +#include <private/qpixmap_raster_p.h> #include <qdebug.h> @@ -69,6 +70,9 @@ private slots: void nullBrush(); void isOpaque(); void debug(); + + void textureBrushStream(); + void textureBrushComparison(); }; @@ -407,5 +411,59 @@ void tst_QBrush::debug() qDebug() << pixmap_brush; // don't crash } +void tst_QBrush::textureBrushStream() +{ + QPixmap pixmap_source(10, 10); + QImage image_source(10, 10, QImage::Format_RGB32); + + fill(&pixmap_source); + fill(&image_source); + + QBrush pixmap_brush; + pixmap_brush.setTexture(pixmap_source); + QBrush image_brush; + image_brush.setTextureImage(image_source); + + QByteArray data1; + QByteArray data2; + { + QDataStream stream1(&data1, QIODevice::WriteOnly); + QDataStream stream2(&data2, QIODevice::WriteOnly); + stream1 << pixmap_brush; + stream2 << image_brush; + } + + QBrush loadedBrush1; + QBrush loadedBrush2; + { + QDataStream stream1(&data1, QIODevice::ReadOnly); + QDataStream stream2(&data2, QIODevice::ReadOnly); + stream1 >> loadedBrush1; + stream2 >> loadedBrush2; + } + + QCOMPARE(loadedBrush1.style(), Qt::TexturePattern); + QCOMPARE(loadedBrush2.style(), Qt::TexturePattern); + QCOMPARE(loadedBrush1.texture(), pixmap_source); + QCOMPARE(loadedBrush2.textureImage(), image_source); +} + +void tst_QBrush::textureBrushComparison() +{ + QImage image1(10, 10, QImage::Format_RGB32); + QRasterPlatformPixmap* ppixmap = new QRasterPlatformPixmap(QPlatformPixmap::PixmapType); + ppixmap->fromImage(image1, Qt::NoFormatConversion); + QPixmap pixmap(ppixmap); + QImage image2(image1); + + QBrush pixmapBrush, imageBrush1, imageBrush2; + pixmapBrush.setTexture(pixmap); + imageBrush1.setTextureImage(image1); + imageBrush2.setTextureImage(image2); + + QVERIFY(imageBrush1 == imageBrush2); + QVERIFY(pixmapBrush == imageBrush1); +} + QTEST_MAIN(tst_QBrush) #include "tst_qbrush.moc" diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 405f84d527..3b3334ba1f 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -102,7 +102,7 @@ private slots: void achromaticHslHue(); -#ifdef Q_WS_X11 +#ifdef Q_DEAD_CODE_FROM_QT4_X11 void setallowX11ColorNames(); #endif }; @@ -1373,7 +1373,7 @@ void tst_QColor::achromaticHslHue() QCOMPARE(hsl.hslHue(), -1); } -#ifdef Q_WS_X11 +#ifdef Q_DEAD_CODE_FROM_QT4_X11 void tst_QColor::setallowX11ColorNames() { #if defined(Q_OS_IRIX) diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 8a0705630d..9ca8e78fff 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -501,7 +501,7 @@ void tst_QPainter::drawPixmap_comp() destPm.fill(c1); srcPm.fill(c2); -#if defined(Q_WS_X11) +#if defined(Q_DEAD_CODE_FROM_QT4_X11) if (!destPm.x11PictureHandle()) QSKIP("Requires XRender support"); #endif @@ -3443,7 +3443,8 @@ void tst_QPainter::drawImage_data() for (int srcFormat = QImage::Format_Mono; srcFormat < QImage::NImageFormats; ++srcFormat) { for (int dstFormat = QImage::Format_Mono; dstFormat < QImage::NImageFormats; ++dstFormat) { - if (dstFormat == QImage::Format_Indexed8) + // Indexed8 can't be painted to, and Alpha8 can't hold a color. + if (dstFormat == QImage::Format_Indexed8 || dstFormat == QImage::Format_Alpha8) continue; for (int odd_x = 0; odd_x <= 1; ++odd_x) { for (int odd_width = 0; odd_width <= 1; ++odd_width) { diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index a03bf2ba4e..6bfec61363 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -37,9 +37,7 @@ #include <qfile.h> #include <qpainterpath.h> #include <qpen.h> - -#define _USE_MATH_DEFINES -#include <math.h> +#include <qmath.h> class tst_QPainterPath : public QObject { diff --git a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp index f55260c572..3bccfb75f7 100644 --- a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp +++ b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp @@ -36,9 +36,7 @@ #include <qfile.h> #include <QPainterPathStroker> - -#define _USE_MATH_DEFINES -#include <math.h> +#include <qmath.h> class tst_QPainterPathStroker : public QObject { diff --git a/tests/auto/gui/painting/qpathclipper/qpathclipper.pro b/tests/auto/gui/painting/qpathclipper/qpathclipper.pro index 18f7ccef2f..b90bca8df3 100644 --- a/tests/auto/gui/painting/qpathclipper/qpathclipper.pro +++ b/tests/auto/gui/painting/qpathclipper/qpathclipper.pro @@ -8,4 +8,4 @@ QT += gui-private testlib requires(contains(QT_CONFIG,private_tests)) -unix:!mac:LIBS+=-lm +unix:!mac:!haiku:LIBS+=-lm diff --git a/tests/auto/gui/painting/qpolygon/qpolygon.pro b/tests/auto/gui/painting/qpolygon/qpolygon.pro index f3e75d7e9e..4783e4b5d4 100644 --- a/tests/auto/gui/painting/qpolygon/qpolygon.pro +++ b/tests/auto/gui/painting/qpolygon/qpolygon.pro @@ -4,6 +4,6 @@ TARGET = tst_qpolygon QT += testlib SOURCES += tst_qpolygon.cpp -unix:!mac:LIBS+=-lm +unix:!mac:!haiku:LIBS+=-lm diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp index 091265285f..95028a29fd 100644 --- a/tests/auto/gui/painting/qregion/tst_qregion.cpp +++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp @@ -38,7 +38,7 @@ #include <qbitmap.h> #include <qpainter.h> #include <qpolygon.h> -#ifdef Q_WS_X11 +#ifdef Q_DEAD_CODE_FROM_QT4_X11 #include <private/qt_x11_p.h> #endif @@ -82,7 +82,7 @@ private slots: void isEmpty_data(); void isEmpty(); -#if defined(Q_WS_X11) && defined(QT_BUILD_INTERNAL) +#if defined(Q_DEAD_CODE_FROM_QT4_X11) && defined(QT_BUILD_INTERNAL) void clipRectangles(); #endif @@ -848,7 +848,7 @@ void tst_QRegion::isEmpty() QVERIFY(region.rects().isEmpty()); } -#if defined(Q_WS_X11) && defined(QT_BUILD_INTERNAL) +#if defined(Q_DEAD_CODE_FROM_QT4_X11) && defined(QT_BUILD_INTERNAL) void tst_QRegion::clipRectangles() { QRegion region(30, 30, 30, 30); diff --git a/tests/auto/gui/painting/qtransform/qtransform.pro b/tests/auto/gui/painting/qtransform/qtransform.pro index 1b5c2a4f25..d59c040fb8 100644 --- a/tests/auto/gui/painting/qtransform/qtransform.pro +++ b/tests/auto/gui/painting/qtransform/qtransform.pro @@ -4,4 +4,4 @@ TARGET = tst_qtransform SOURCES += tst_qtransform.cpp QT += testlib -unix:!mac:LIBS+=-lm +unix:!mac:!haiku:LIBS+=-lm diff --git a/tests/auto/gui/painting/qwmatrix/qwmatrix.pro b/tests/auto/gui/painting/qwmatrix/qwmatrix.pro index e0e260555a..b3bec3d4ff 100644 --- a/tests/auto/gui/painting/qwmatrix/qwmatrix.pro +++ b/tests/auto/gui/painting/qwmatrix/qwmatrix.pro @@ -4,4 +4,4 @@ TARGET = tst_qwmatrix SOURCES += tst_qwmatrix.cpp QT += testlib -unix:!mac:LIBS+=-lm +unix:!mac:!haiku:LIBS+=-lm diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 89ad66c1e8..a8834563a1 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -98,6 +98,8 @@ private slots: void textureblitterPartTargetRectTransform(); void defaultSurfaceFormat(); + void imageFormatPainting(); + #ifdef USE_GLX void glxContextWrap(); #endif @@ -718,6 +720,68 @@ void tst_QOpenGL::fboHandleNulledAfterContextDestroyed() QCOMPARE(fbo->handle(), 0U); } +void tst_QOpenGL::imageFormatPainting() +{ + QScopedPointer<QSurface> surface(createSurface(QSurface::Window)); + + QOpenGLContext ctx; + QVERIFY(ctx.create()); + + QVERIFY(ctx.makeCurrent(surface.data())); + + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QOpenGLFramebufferObject not supported on this platform"); + + QOpenGLFramebufferObjectFormat fboFormat; + fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); + + const QSize size(128, 128); + QOpenGLFramebufferObject fbo(size, fboFormat); + + if (fbo.attachment() != QOpenGLFramebufferObject::CombinedDepthStencil) + QSKIP("FBOs missing combined depth~stencil support"); + + QVERIFY(fbo.bind()); + + QImage alpha(128, 128, QImage::Format_Alpha8); + alpha.fill(127); + + QPainter fboPainter; + QOpenGLPaintDevice device(fbo.width(), fbo.height()); + + QVERIFY(fboPainter.begin(&device)); + fboPainter.fillRect(0, 0, 128, 128, qRgb(255, 0, 255)); + fboPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); + fboPainter.drawImage(0, 0, alpha); + fboPainter.end(); + + QImage fb = fbo.toImage(); + QCOMPARE(fb.pixel(0, 0), qRgba(127, 0, 127, 127)); + + QImage grayscale(128, 128, QImage::Format_Grayscale8); + grayscale.fill(128); + + QVERIFY(fboPainter.begin(&device)); + fboPainter.setCompositionMode(QPainter::CompositionMode_Plus); + fboPainter.drawImage(0, 0, grayscale); + fboPainter.end(); + + fb = fbo.toImage(); + QCOMPARE(fb.pixel(0, 0), qRgb(255, 128, 255)); + + QImage argb(128, 128, QImage::Format_ARGB32); + argb.fill(qRgba(255, 255, 255, 128)); + + QVERIFY(fboPainter.begin(&device)); + fboPainter.setCompositionMode(QPainter::CompositionMode_SourceOver); + fboPainter.drawImage(0, 0, argb); + fboPainter.end(); + + fb = fbo.toImage(); + QCOMPARE(fb.pixel(0, 0), qRgb(255, 192, 255)); + +} + void tst_QOpenGL::openGLPaintDevice_data() { QTest::addColumn<int>("surfaceClass"); diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index f60a229c08..380aaa87f9 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -591,10 +591,6 @@ void tst_QFont::serialize_data() QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5; font = basicFont; - font.setRawMode(true); - QTest::newRow("rawMode") << font << QDataStream::Qt_1_0; - - font = basicFont; font.setKerning(false); QTest::newRow("kerning") << font << QDataStream::Qt_4_0; diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index 969c8f9ce7..8cb32dabd1 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -948,7 +948,7 @@ void tst_QRawFont::rawFontFromInvalidData() QVERIFY(!font.isValid()); - invalidData.fill(255, 1024); + invalidData.fill(char(255), 1024); font.loadFromData(invalidData, 10, QFont::PreferDefaultHinting); QVERIFY(!font.isValid()); diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 4cab2b8a51..139cafa1fa 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -78,6 +78,8 @@ private slots: void find2(); void findWithRegExp_data(); void findWithRegExp(); + void findWithRegularExpression_data(); + void findWithRegularExpression(); void findMultiple(); void basicIsModifiedChecks(); void moreIsModified(); @@ -188,6 +190,7 @@ private slots: private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); + void buildRegExpData(); QTextDocument *doc; QTextCursor cursor; @@ -344,21 +347,7 @@ void tst_QTextDocument::find() void tst_QTextDocument::findWithRegExp_data() { - QTest::addColumn<QString>("haystack"); - QTest::addColumn<QString>("needle"); - QTest::addColumn<int>("flags"); - QTest::addColumn<int>("from"); - QTest::addColumn<int>("anchor"); - QTest::addColumn<int>("position"); - - // match integers 0 to 99 - QTest::newRow("1") << "23" << "^\\d\\d?$" << int(QTextDocument::FindCaseSensitively) << 0 << 0 << 2; - // match ampersands but not & - QTest::newRow("2") << "His & hers & theirs" << "&(?!amp;)"<< int(QTextDocument::FindCaseSensitively) << 0 << 15 << 16; - //backward search - QTest::newRow("3") << QString::fromLatin1("HelloBlahWorld Blah Hah") - << "h" << int(QTextDocument::FindBackward) << 18 << 8 << 9; - + buildRegExpData(); } void tst_QTextDocument::findWithRegExp() @@ -385,6 +374,34 @@ void tst_QTextDocument::findWithRegExp() } } +void tst_QTextDocument::findWithRegularExpression_data() +{ + buildRegExpData(); +} + +void tst_QTextDocument::findWithRegularExpression() +{ + QFETCH(QString, haystack); + QFETCH(QString, needle); + QFETCH(int, flags); + QFETCH(int, from); + QFETCH(int, anchor); + QFETCH(int, position); + + cursor.insertText(haystack); + //search using a regular expression + QRegularExpression expr(needle); + QTextDocument::FindFlags flg(flags); + cursor = doc->find(expr, from, flg); + + if (anchor != -1) { + QCOMPARE(cursor.anchor(), anchor); + QCOMPARE(cursor.position(), position); + } else { + QVERIFY(cursor.isNull()); + } +} + void tst_QTextDocument::find2() { doc->setPlainText("aaa"); @@ -2594,6 +2611,24 @@ void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &d QCOMPARE(doc.toHtml(), expectedHtml); } +void tst_QTextDocument::buildRegExpData() +{ + QTest::addColumn<QString>("haystack"); + QTest::addColumn<QString>("needle"); + QTest::addColumn<int>("flags"); + QTest::addColumn<int>("from"); + QTest::addColumn<int>("anchor"); + QTest::addColumn<int>("position"); + + // match integers 0 to 99 + QTest::newRow("1") << "23" << "^\\d\\d?$" << int(QTextDocument::FindCaseSensitively) << 0 << 0 << 2; + // match ampersands but not & + QTest::newRow("2") << "His & hers & theirs" << "&(?!amp;)"<< int(QTextDocument::FindCaseSensitively) << 0 << 15 << 16; + //backward search + QTest::newRow("3") << QString::fromLatin1("HelloBlahWorld Blah Hah") + << "h" << int(QTextDocument::FindBackward) << 18 << 8 << 9; +} + void tst_QTextDocument::backgroundImage_toHtml() { CREATE_DOC_AND_CURSOR(); diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index e95de3df45..51e993a7d6 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -67,6 +67,7 @@ private slots: void clippedTableCell(); void floatingTablePageBreak(); void imageAtRightAlignedTab(); + void blockVisibility(); private: QTextDocument *doc; @@ -312,5 +313,46 @@ void tst_QTextDocumentLayout::imageAtRightAlignedTab() QCOMPARE(doc->idealWidth(), 300.0); } +void tst_QTextDocumentLayout::blockVisibility() +{ + QTextCursor cursor(doc); + for (int i = 0; i < 10; ++i) { + if (!doc->isEmpty()) + cursor.insertBlock(); + cursor.insertText(QString::number(i)); + } + + qreal margin = doc->documentMargin(); + QSizeF emptySize(2 * margin, 2 * margin); + QSizeF halfSize = doc->size(); + halfSize.rheight() -= 2 * margin; + halfSize.rheight() /= 2; + halfSize.rheight() += 2 * margin; + + for (int i = 0; i < 10; i += 2) { + QTextBlock block = doc->findBlockByNumber(i); + block.setVisible(false); + doc->markContentsDirty(block.position(), block.length()); + } + + QCOMPARE(doc->size(), halfSize); + + for (int i = 1; i < 10; i += 2) { + QTextBlock block = doc->findBlockByNumber(i); + block.setVisible(false); + doc->markContentsDirty(block.position(), block.length()); + } + + QCOMPARE(doc->size(), emptySize); + + for (int i = 0; i < 10; i += 2) { + QTextBlock block = doc->findBlockByNumber(i); + block.setVisible(true); + doc->markContentsDirty(block.position(), block.length()); + } + + QCOMPARE(doc->size(), halfSize); +} + QTEST_MAIN(tst_QTextDocumentLayout) #include "tst_qtextdocumentlayout.moc" |