mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat: 添加单元测试代码
添加单元测试代码 Log: Change-Id: I9cebdef6989322b8deefd039bee7b1c8658e6dbf
This commit is contained in:
parent
c45b917a64
commit
55d34b91e3
@ -62,6 +62,7 @@ include_directories(
|
||||
frame/util
|
||||
frame/window
|
||||
frame/xcb
|
||||
frame/mockinterface
|
||||
)
|
||||
|
||||
aux_source_directory(frame/controller CONTROLLER)
|
||||
@ -75,6 +76,7 @@ aux_source_directory(frame/qss QSSPATH)
|
||||
aux_source_directory(frame/util UTIL)
|
||||
aux_source_directory(frame/window WINDOW)
|
||||
aux_source_directory(frame/xcb XCB)
|
||||
aux_source_directory(frame/mockinterface MOCKINTERFACE)
|
||||
|
||||
file(GLOB SRC_PATH
|
||||
${CONTROLLER}
|
||||
@ -86,6 +88,7 @@ file(GLOB SRC_PATH
|
||||
${UTIL}
|
||||
${WINDOW}
|
||||
${XCB}
|
||||
${MOCKINTERFACE}
|
||||
)
|
||||
|
||||
add_subdirectory("frame")
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "launcheritem.h"
|
||||
#include "pluginsitem.h"
|
||||
#include "traypluginitem.h"
|
||||
#include "qgsettingsinterfaceimpl.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGSettings>
|
||||
@ -36,7 +37,7 @@ DockItemManager::DockItemManager(QObject *parent)
|
||||
, m_pluginsInter(new DockPluginsController(this))
|
||||
{
|
||||
//固定区域:启动器
|
||||
m_itemList.append(new LauncherItem);
|
||||
m_itemList.append(new LauncherItem(new QGSettingsInterfaceImpl("com.deepin.dde.dock.module.launcher")));
|
||||
|
||||
// 应用区域
|
||||
for (auto entry : m_appInter->entries()) {
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "launcheritem.h"
|
||||
#include "themeappicon.h"
|
||||
#include "imagefactory.h"
|
||||
#include "qgsettingsinterface.h"
|
||||
#include "qgsettingsinterfaceimpl.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QProcess>
|
||||
@ -32,18 +34,23 @@
|
||||
|
||||
DCORE_USE_NAMESPACE
|
||||
|
||||
LauncherItem::LauncherItem(QWidget *parent)
|
||||
LauncherItem::LauncherItem(QGSettingsInterface *interface, QWidget *parent)
|
||||
: DockItem(parent)
|
||||
, m_launcherInter(new LauncherInter("com.deepin.dde.Launcher", "/com/deepin/dde/Launcher", QDBusConnection::sessionBus(), this))
|
||||
, m_tips(new TipsWidget(this))
|
||||
, m_gsettings(new QGSettings("com.deepin.dde.dock.module.launcher"))
|
||||
, m_gsettings(interface)
|
||||
{
|
||||
m_launcherInter->setSync(true, false);
|
||||
|
||||
m_tips->setVisible(false);
|
||||
m_tips->setObjectName("launcher");
|
||||
|
||||
connect(m_gsettings, &QGSettings::changed, this, &LauncherItem::onGSettingsChanged);
|
||||
if (m_gsettings->type() == QGSettingsInterface::REAL) {
|
||||
QGSettingsInterfaceImpl *impl = dynamic_cast<QGSettingsInterfaceImpl *>(m_gsettings);
|
||||
if (!impl)
|
||||
qWarning("Error!");
|
||||
connect(impl->gsettings(), &QGSettings::changed, this, &LauncherItem::onGSettingsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void LauncherItem::refershIcon()
|
||||
|
@ -24,19 +24,19 @@
|
||||
|
||||
#include "dockitem.h"
|
||||
#include "../widgets/tipswidget.h"
|
||||
#include "qgsettingsinterface.h"
|
||||
|
||||
#include <com_deepin_dde_launcher.h>
|
||||
|
||||
|
||||
using LauncherInter = com::deepin::dde::Launcher;
|
||||
|
||||
class QGSettings;
|
||||
class QGSettingsInterface;
|
||||
class LauncherItem : public DockItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LauncherItem(QWidget *parent = nullptr) ;
|
||||
explicit LauncherItem(QGSettingsInterface *interface, QWidget *parent = nullptr);
|
||||
|
||||
inline ItemType itemType() const override {return Launcher;}
|
||||
|
||||
@ -61,7 +61,7 @@ private:
|
||||
QPixmap m_icon;
|
||||
LauncherInter *m_launcherInter;
|
||||
TipsWidget *m_tips;
|
||||
QGSettings* m_gsettings;
|
||||
QGSettingsInterface* m_gsettings;
|
||||
};
|
||||
|
||||
#endif // LAUNCHERITEM_H
|
||||
|
29
frame/mockinterface/qgsettingsinterface.h
Normal file
29
frame/mockinterface/qgsettingsinterface.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef QGSETTINGSINTERFACE_H
|
||||
#define QGSETTINGSINTERFACE_H
|
||||
|
||||
#include <QVariant>
|
||||
#include <QStringList>
|
||||
|
||||
class QGSettings;
|
||||
class QGSettingsInterface
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
REAL, // 持有真正的QGSettings指针
|
||||
FAKE // Mock类
|
||||
};
|
||||
|
||||
virtual ~QGSettingsInterface() {}
|
||||
|
||||
virtual Type type() = 0;
|
||||
virtual QGSettings *gsettings() = 0;
|
||||
virtual QVariant get(const QString &key) const = 0;
|
||||
virtual void set(const QString &key, const QVariant &value) = 0;
|
||||
virtual bool trySet(const QString &key, const QVariant &value) = 0;
|
||||
virtual QStringList keys() const = 0;
|
||||
virtual QVariantList choices(const QString &key) const = 0;
|
||||
virtual void reset(const QString &key) = 0;
|
||||
static bool isSchemaInstalled(const QByteArray &schema_id) {Q_UNUSED(schema_id); return false;}
|
||||
|
||||
};
|
||||
#endif // QGSETTINGSINTERFACE_H
|
60
frame/mockinterface/qgsettingsinterfaceimpl.cpp
Normal file
60
frame/mockinterface/qgsettingsinterfaceimpl.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <QGSettings>
|
||||
#include <QVariant>
|
||||
|
||||
#include "qgsettingsinterfaceimpl.h"
|
||||
|
||||
QGSettingsInterfaceImpl::QGSettingsInterfaceImpl(const QByteArray &schema_id, const QByteArray &path, QObject *parent)
|
||||
: m_gsettings(new QGSettings(schema_id, path, parent))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QGSettingsInterfaceImpl::~QGSettingsInterfaceImpl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QGSettingsInterface::Type QGSettingsInterfaceImpl::type()
|
||||
{
|
||||
return Type::REAL;
|
||||
}
|
||||
|
||||
QGSettings *QGSettingsInterfaceImpl::gsettings()
|
||||
{
|
||||
return m_gsettings;
|
||||
}
|
||||
|
||||
QVariant QGSettingsInterfaceImpl::get(const QString &key) const
|
||||
{
|
||||
return m_gsettings->get(key);
|
||||
}
|
||||
|
||||
void QGSettingsInterfaceImpl::set(const QString &key, const QVariant &value)
|
||||
{
|
||||
return m_gsettings->set(key, value);
|
||||
}
|
||||
|
||||
bool QGSettingsInterfaceImpl::trySet(const QString &key, const QVariant &value)
|
||||
{
|
||||
return m_gsettings->trySet(key, value);
|
||||
}
|
||||
|
||||
QStringList QGSettingsInterfaceImpl::keys() const
|
||||
{
|
||||
return m_gsettings->keys();
|
||||
}
|
||||
|
||||
QVariantList QGSettingsInterfaceImpl::choices(const QString &key) const
|
||||
{
|
||||
return m_gsettings->choices(key);
|
||||
}
|
||||
|
||||
void QGSettingsInterfaceImpl::reset(const QString &key)
|
||||
{
|
||||
return m_gsettings->reset(key);
|
||||
}
|
||||
|
||||
bool QGSettingsInterfaceImpl::isSchemaInstalled(const QByteArray &schema_id)
|
||||
{
|
||||
return QGSettings::isSchemaInstalled(schema_id);
|
||||
}
|
28
frame/mockinterface/qgsettingsinterfaceimpl.h
Normal file
28
frame/mockinterface/qgsettingsinterfaceimpl.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef QGSETTINGSINTERFACEIMPL_H
|
||||
#define QGSETTINGSINTERFACEIMPL_H
|
||||
#include <QObject>
|
||||
|
||||
#include "qgsettingsinterface.h"
|
||||
|
||||
class QGSettings;
|
||||
class QGSettingsInterfaceImpl : public QGSettingsInterface
|
||||
{
|
||||
public:
|
||||
QGSettingsInterfaceImpl(const QByteArray &schema_id, const QByteArray &path = QByteArray(), QObject *parent = nullptr);
|
||||
~QGSettingsInterfaceImpl() override;
|
||||
|
||||
virtual Type type() override;
|
||||
virtual QGSettings *gsettings() override;
|
||||
virtual QVariant get(const QString &key) const override;
|
||||
virtual void set(const QString &key, const QVariant &value) override;
|
||||
virtual bool trySet(const QString &key, const QVariant &value) override;
|
||||
virtual QStringList keys() const override;
|
||||
virtual QVariantList choices(const QString &key) const override;
|
||||
virtual void reset(const QString &key) override;
|
||||
static bool isSchemaInstalled(const QByteArray &schema_id);
|
||||
|
||||
private:
|
||||
QGSettings *m_gsettings;
|
||||
};
|
||||
|
||||
#endif // QGSETTINGSINTERFACEIMPL_H
|
59
frame/mockinterface/qgsettingsinterfacemock.cpp
Normal file
59
frame/mockinterface/qgsettingsinterfacemock.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <QGSettings>
|
||||
#include <QVariant>
|
||||
|
||||
#include "qgsettingsinterfacemock.h"
|
||||
|
||||
QGSettingsInterfaceMock::QGSettingsInterfaceMock(const QByteArray &schema_id, const QByteArray &path, QObject *parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QGSettingsInterfaceMock::~QGSettingsInterfaceMock()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QGSettingsInterface::Type QGSettingsInterfaceMock::type()
|
||||
{
|
||||
return Type::FAKE;
|
||||
}
|
||||
|
||||
QGSettings *QGSettingsInterfaceMock::gsettings()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QVariant QGSettingsInterfaceMock::get(const QString &key) const
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void QGSettingsInterfaceMock::set(const QString &key, const QVariant &value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool QGSettingsInterfaceMock::trySet(const QString &key, const QVariant &value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList QGSettingsInterfaceMock::keys() const
|
||||
{
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QVariantList QGSettingsInterfaceMock::choices(const QString &key) const
|
||||
{
|
||||
return QVariantList();
|
||||
}
|
||||
|
||||
void QGSettingsInterfaceMock::reset(const QString &key)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool QGSettingsInterfaceMock::isSchemaInstalled(const QByteArray &schema_id)
|
||||
{
|
||||
return false;
|
||||
}
|
25
frame/mockinterface/qgsettingsinterfacemock.h
Normal file
25
frame/mockinterface/qgsettingsinterfacemock.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef QGSETTINGSINTERFACEMOCK_H
|
||||
#define QGSETTINGSINTERFACEMOCK_H
|
||||
#include <QObject>
|
||||
|
||||
#include "qgsettingsinterface.h"
|
||||
|
||||
class QGSettings;
|
||||
class QGSettingsInterfaceMock : public QGSettingsInterface
|
||||
{
|
||||
public:
|
||||
QGSettingsInterfaceMock(const QByteArray &schema_id, const QByteArray &path = QByteArray(), QObject *parent = nullptr);
|
||||
~QGSettingsInterfaceMock() override;
|
||||
|
||||
virtual Type type() override;
|
||||
virtual QGSettings *gsettings() override;
|
||||
virtual QVariant get(const QString &key) const override;
|
||||
virtual void set(const QString &key, const QVariant &value) override;
|
||||
virtual bool trySet(const QString &key, const QVariant &value) override;
|
||||
virtual QStringList keys() const override;
|
||||
virtual QVariantList choices(const QString &key) const override;
|
||||
virtual void reset(const QString &key) override;
|
||||
static bool isSchemaInstalled(const QByteArray &schema_id);
|
||||
};
|
||||
|
||||
#endif // QGSETTINGSINTERFACEMOCK_H
|
@ -30,7 +30,6 @@ pkg_check_modules(XCB_EWMH REQUIRED xcb-ewmh x11)
|
||||
add_executable(${BIN_NAME} ${SRCS} ${INTERFACES} ${SRC_PATH} ../frame/item/item.qrc ../frame/frame.qrc)
|
||||
|
||||
# 包含路径
|
||||
|
||||
target_include_directories(${BIN_NAME} PUBLIC
|
||||
${DtkWidget_INCLUDE_DIRS}
|
||||
${XCB_EWMH_INCLUDE_DIRS}
|
||||
|
54
tests/ut_launcheritem.cpp
Normal file
54
tests/ut_launcheritem.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd.
|
||||
*
|
||||
* Author: chenjun <chenjun@uniontech.com>
|
||||
*
|
||||
* Maintainer: chenjun <chenjun@uniontech.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "launcheritem.h"
|
||||
#include "qgsettingsinterfacemock.h"
|
||||
|
||||
class Test_LauncherItem : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
public:
|
||||
LauncherItem *launcherItem = nullptr;
|
||||
};
|
||||
|
||||
void Test_LauncherItem::SetUp()
|
||||
{
|
||||
launcherItem = new LauncherItem(new QGSettingsInterfaceMock("com.deepin.dde.dock.module.launcher"));
|
||||
}
|
||||
|
||||
void Test_LauncherItem::TearDown()
|
||||
{
|
||||
delete launcherItem;
|
||||
launcherItem = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(Test_LauncherItem, dockitem_test)
|
||||
{
|
||||
ASSERT_NE(launcherItem, nullptr);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user