From 0809a357c13ff1297d6bceee5ab666c2dedd17da Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 31 Jul 2017 15:12:37 +0100 Subject: [PATCH] Improve testWindowScaled test Summary: Comparing a pure blue square isn't a very effective test as someone cropping the image will still pass. Reviewers: #plasma, graesslin Reviewed By: #plasma, graesslin Subscribers: plasma-devel, kwin, #kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D6982 --- autotests/integration/kwin_wayland_test.h | 6 ++++++ autotests/integration/scene_qpainter_test.cpp | 13 ++++++++++++- autotests/integration/test_helpers.cpp | 7 ++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index dbba1d13e1..610820c607 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -124,12 +124,18 @@ QObject *createShellSurface(ShellSurfaceType type, KWayland::Client::Surface *su KWayland::Client::ShellSurface *createShellSurface(KWayland::Client::Surface *surface, QObject *parent = nullptr); KWayland::Client::XdgShellSurface *createXdgShellV5Surface(KWayland::Client::Surface *surface, QObject *parent = nullptr); + /** * Creates a shared memory buffer of @p size in @p color and attaches it to the @p surface. * The @p surface gets damaged and committed, thus it's rendered. **/ void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format = QImage::Format_ARGB32); +/** + * Creates a shared memory buffer using the supplied image @p img and attaches it to the @p surface + */ +void render(KWayland::Client::Surface *surface, const QImage &img); + /** * Waits till a new ShellClient is shown and returns the created ShellClient. * If no ShellClient gets shown during @p timeout @c null is returned. diff --git a/autotests/integration/scene_qpainter_test.cpp b/autotests/integration/scene_qpainter_test.cpp index 67cdd3c8ed..cd3b465c3b 100644 --- a/autotests/integration/scene_qpainter_test.cpp +++ b/autotests/integration/scene_qpainter_test.cpp @@ -223,7 +223,17 @@ void SceneQPainterTest::testWindowScaled() // now let's map the window s->setScale(2); - QVERIFY(Test::renderAndWaitForShown(s.data(), QSize(400, 600), Qt::blue)); + + //draw a blue square@400x600 with red rectangle@200x200 in the middle + const QSize size(400,600); + QImage img(size, QImage::Format_ARGB32); + img.fill(Qt::blue); + QPainter surfacePainter(&img); + surfacePainter.fillRect(200,300,200,200, Qt::red); + + //add buffer + Test::render(s.data(), img); + Test::waitForWaylandWindowShown(); // which should trigger a frame if (frameRenderedSpy.isEmpty()) { @@ -233,6 +243,7 @@ void SceneQPainterTest::testWindowScaled() referenceImage.fill(Qt::black); QPainter painter(&referenceImage); painter.fillRect(0, 0, 200, 300, Qt::blue); + painter.fillRect(100, 150, 100, 100, Qt::red); painter.fillRect(5, 5, 10, 10, Qt::red); //cursor QCOMPARE(referenceImage, *scene->backend()->buffer()); diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 703ea46797..576e1687dd 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -295,8 +295,13 @@ void render(Surface *surface, const QSize &size, const QColor &color, const QIma { QImage img(size, format); img.fill(color); + render(surface, img); +} + +void render(Surface *surface, const QImage &img) +{ surface->attachBuffer(s_waylandConnection.shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), size)); + surface->damage(QRect(QPoint(0, 0), img.size())); surface->commit(Surface::CommitFlag::None); }