Skip to content

Commit

Permalink
chore: Complementary unit test ut-dconfigwrapper
Browse files Browse the repository at this point in the history
unit test

Log: Complementary unit test ut-dconfigwrapper
  • Loading branch information
FeiWang1119 committed Aug 11, 2023
1 parent e9932e6 commit 74b3ea9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
1 change: 1 addition & 0 deletions tests/data.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
<file>qml/DQuickItemViewport_HideSource.qml</file>
<file>qml/SoftwareOpacityMask.qml</file>
<file>qml/DQuickBlitFramebuffer.qml</file>
<file>qml/Config.qml</file>
</qresource>
</RCC>
22 changes: 22 additions & 0 deletions tests/qml/Config.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

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

Item {
id: control
signal key3Changed()
D.Config {
id: exampleConfig
name: "example"
subpath: ""
property string key3 : "1"
onKey3Changed: control.key3Changed()
}
function setKey3(value)
{
exampleConfig.key3 = value
}
}
43 changes: 24 additions & 19 deletions tests/ut_dconfigwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QTest>

#include "private/dconfigwrapper_p.h"
#include "test_helper.hpp"

static constexpr char const *LocalPrefix = "/tmp/example";
static constexpr char const *APP_ID = BIN_NAME;
Expand All @@ -16,7 +17,6 @@ class ut_DConfigWrapper : public ::testing::Test
{
public:
virtual void SetUp();
virtual void TearDown();

static void SetUpTestCase() {
const QString &target = QString("%1/usr/share/dsg/configs/%2/%3.json").arg(LocalPrefix, APP_ID, FILE_NAME);
Expand All @@ -34,35 +34,26 @@ class ut_DConfigWrapper : public ::testing::Test
QDir(LocalPrefix).removeRecursively();
}

ControlHelper<QQuickItem> helper;
DConfigWrapper *config;
QString origiAppId;
};

void ut_DConfigWrapper::SetUp()
{
config = new DConfigWrapper();
}

void ut_DConfigWrapper::TearDown()
{
delete config;
}

TEST_F(ut_DConfigWrapper, componentComplete)
{
config->classBegin();
config->setName("example");
config->componentComplete();

ASSERT_TRUE(helper.load("qrc:/qml/Config.qml"));
config = helper.object->findChild<DConfigWrapper *>();
ASSERT_TRUE(config);
ASSERT_TRUE(config->isValid());
}

TEST_F(ut_DConfigWrapper, setValue)
{
config->classBegin();
config->setName("example");
config->setSubpath("");
config->componentComplete();
ASSERT_EQ(config->name(), "example");
config->setName("example1");
ASSERT_EQ(config->name(), "example");

ASSERT_EQ(config->subpath(), "");

ASSERT_TRUE(config->keyList().contains("key3"));

Expand All @@ -76,4 +67,18 @@ TEST_F(ut_DConfigWrapper, setValue)
ASSERT_TRUE(QTest::qWaitFor([&spy](){
return spy.count() == 1;
}, 500));

config->setProperty("key3", "23");
ASSERT_EQ(config->value("key3").toString(), "23");

config->resetValue("key3");
ASSERT_EQ(config->value("key3").toString(), "application");
}

TEST_F(ut_DConfigWrapper, setValueByQML)
{
QSignalSpy key3Change(helper.object, SIGNAL(key3Changed()));
config->metaObject()->invokeMethod(helper.object, "setKey3", Q_ARG(QVariant, QString("2")));
EXPECT_EQ(key3Change.count(), 1);
EXPECT_EQ(config->value("key3").toString(), "2");
}

0 comments on commit 74b3ea9

Please sign in to comment.