forked from linuxdeepin/dtkwidget
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#include <gtest/gtest.h> | ||
#include <QLabel> | ||
#include <QTest> | ||
|
||
#include "dwatermarkwidget.h" | ||
DWIDGET_USE_NAMESPACE | ||
class ut_DWaterMarkWidget : public testing::Test | ||
{ | ||
protected: | ||
void SetUp() override | ||
{ | ||
root = new QLabel(); | ||
target = new DWaterMarkWidget(root); | ||
root->resize(600, 600); | ||
|
||
QImage img(":/data/test.png"); | ||
QPixmap pixmap = QPixmap::fromImage(img.scaled(root->size())); | ||
root->setPixmap(pixmap); | ||
} | ||
void TearDown() override | ||
{ | ||
if (root) | ||
delete root; | ||
} | ||
inline bool equalImage(const QImage &source) | ||
{ | ||
QPixmap result = root->grab(); | ||
return result.toImage() == source; | ||
} | ||
|
||
DWaterMarkWidget *target = nullptr; | ||
QLabel *root = nullptr; | ||
}; | ||
|
||
TEST_F(ut_DWaterMarkWidget, paintText) | ||
{ | ||
WaterMarkData data = target->data(); | ||
data.setType(WaterMarkData::Text); | ||
data.setText("deepin water mark"); | ||
data.setLineSpacing(200); | ||
data.setScaleFactor(1.5); | ||
auto font = data.font(); | ||
font.setBold(true); | ||
font.setPointSize(20); | ||
data.setFont(font); | ||
data.setColor(Qt::red); | ||
data.setOpacity(0.5); | ||
target->setData(data); | ||
|
||
EXPECT_TRUE(equalImage(QImage(":/data/watermarks/text.png"))); | ||
} | ||
|
||
TEST_F(ut_DWaterMarkWidget, paintImage) | ||
{ | ||
WaterMarkData data = target->data(); | ||
data.setType(WaterMarkData::Image); | ||
QImage img(":/assets/images/uos.svg"); | ||
data.setImage(img); | ||
data.setLineSpacing(200); | ||
data.setGrayScale(true); | ||
target->setData(data); | ||
|
||
EXPECT_TRUE(equalImage(QImage(":/data/watermarks/image.png"))); | ||
} |