Skip to content

Commit

Permalink
feat: Add ut for WaterProgressBar
Browse files Browse the repository at this point in the history
  Add ut.
  • Loading branch information
18202781743 committed Jul 24, 2023
1 parent a0fb6ca commit 215d009
Show file tree
Hide file tree
Showing 4 changed files with 97 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 @@ -14,6 +14,7 @@ file(GLOB TEST_SOURCES
ut_windowbuttongroup.cpp
ut_dquickrectangle.cpp
ut_dquickwindow.cpp
ut_waterprogressbar.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 @@ -7,5 +7,6 @@
<file>qml/DQuickRectangle.qml</file>
<file>qml/DQuickWindow.qml</file>
<file>qml/QmlGlobalObject.qml</file>
<file>qml/WaterProgressBar.qml</file>
</qresource>
</RCC>
12 changes: 12 additions & 0 deletions tests/qml/WaterProgressBar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

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

D.WaterProgressBar {
width: 100; height: 100
value: 20
running: true
}
83 changes: 83 additions & 0 deletions tests/ut_waterprogressbar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 <QTest>
#include <QQuickItem>

#include "dquickwaterprogressattribute_p.h"
DQUICK_USE_NAMESPACE

TEST(ut_DQuickWaterProgressAttribute, properties)
{
QQuickItem *water = new QQuickItem;
water->setSize(QSize(100, 100));
water->setProperty("value", 10);

DQuickWaterProgressAttribute attr;
auto attrPops = attr.pops();
EXPECT_GE(attrPops.count(&attrPops), 3);

attr.setWaterProgress(water);
ASSERT_EQ(attr.waterProgress(), water);

attr.setFrontXOffset(10);
ASSERT_EQ(attr.frontXOffset(), 10);

attr.setImageWidth(100);
ASSERT_EQ(attr.imageWidth(), 100);

attr.setImageHeight(100);
ASSERT_EQ(attr.imageHeight(), 100);

WaterPopAttribute *pop = attrPops.at(&attrPops, 0);
ASSERT_TRUE(pop);
EXPECT_LT(pop->sizeRatio(), 1.0);
EXPECT_LT(pop->width(), water->width());
EXPECT_LT(pop->height(), water->height());

const auto popX = pop->x();
const auto popY = pop->y();
const auto popYOffset = pop->yOffset();

attr.setRunning(true);
ASSERT_EQ(attr.running(), true);

// trigger and process `timeout` for DQuickWaterProgressAttribute's timer.
QTest::qWait(50);

EXPECT_NE(popX, pop->x());
EXPECT_NE(popY, pop->y());
EXPECT_NE(popYOffset, pop->yOffset());

attr.setRunning(false);
ASSERT_EQ(attr.running(), false);
}

TEST(ut_DQuickWaterProgressBar, waterProgressBar)
{
ControlHeler<> root("qrc:/qml/WaterProgressBar.qml");
ASSERT_TRUE(root.object);

EXPECT_EQ(root.object->property("value"), 20);
EXPECT_EQ(root.object->property("running"), true);

auto attr = root.object->findChild<DQuickWaterProgressAttribute *>();
ASSERT_TRUE(attr);
auto attrPops = attr->pops();
ASSERT_GE(attrPops.count(&attrPops), 1);

WaterPopAttribute *pop = attrPops.at(&attrPops, 0);
const auto popX = pop->x();

root.object->setProperty("running", false);

// stop update
QTest::qWait(50);

ASSERT_EQ(popX, pop->x());
}

0 comments on commit 215d009

Please sign in to comment.