Skip to content

Commit

Permalink
feat: Add UT for BehindWindowBlur
Browse files Browse the repository at this point in the history
  Add UT.
  • Loading branch information
18202781743 authored and FeiWang1119 committed Aug 4, 2023
1 parent 69bdcc1 commit 4e26734
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ file(GLOB TEST_SOURCES
ut_dquickdciicon.cpp
ut_dblurimagenode.cpp
ut_dhandlecontextmenuwindow.cpp
ut_dquickbehindwindowblur.cpp
)
if (EnableDtk5)
list(APPEND TEST_SOURCES
Expand Down
1 change: 1 addition & 0 deletions tests/data.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
<file>qml/DMaskEffectNode_TextureMaterial.qml</file>
<file>qml/DSGBlurImageNode.qml</file>
<file>qml/ContextMenuWindow.qml</file>
<file>qml/DQuickBehindWindowBlur.qml</file>
</qresource>
</RCC>
29 changes: 29 additions & 0 deletions tests/qml/DQuickBehindWindowBlur.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

import QtQuick 2.11
import QtQuick.Window 2.11
import org.deepin.dtk 1.0 as D

Rectangle {
id: control
width: 200; height: 200
color: "red"
Window {
// on top of the Rectangle's window
x: control.Window.window ? control.Window.window.x : 0
y: control.Window.window ? control.Window.window.y : 0
width: 100; height: 100
visible: true

D.DWindow.enabled: true
D.DWindow.alphaBufferSize: 8

D.BehindWindowBlur {
anchors.fill: parent
blendColor: Qt.rgba(0, 255, 0, 0.4)
cornerRadius: 10
}
}
}
31 changes: 31 additions & 0 deletions tests/ut_dquickbehindwindowblur.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gtest/gtest.h>

#include "test_helper.hpp"

#include <QQuickItem>

#include "dquickbehindwindowblur_p.h"
DQUICK_USE_NAMESPACE

TEST(ut_DQuickBehindWindowBlur, properties)
{
QuickViewHelper<> helper("qrc:/qml/DQuickBehindWindowBlur.qml");
ASSERT_TRUE(helper.object);

DQuickBehindWindowBlur *target = helper.object->findChild<DQuickBehindWindowBlur *>();
ASSERT_TRUE(target);

if (!target->valid())
GTEST_SKIP_("don't support BehindWindowBlur, it need WM support.");

EXPECT_EQ(target->blendColor(), QColor(0, 255, 0, 0.4 * 255));
EXPECT_EQ(target->cornerRadius(), 10);

QImage img = helper.view->grabWindow();
EXPECT_NE(img.pixelColor(QPoint(50, 50)), QColor(0, 255, 0, 0.4));
EXPECT_EQ(img.pixelColor(QPoint(150, 50)), Qt::red);
}

0 comments on commit 4e26734

Please sign in to comment.