mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
feat: 添加单元测试代码
添加单元测试代码,修改几处测试出的问题 Log: Change-Id: I6aef0f137873044db1b7997ef6974dc7ed7c63aa
This commit is contained in:
parent
7ba28a270c
commit
82f71facef
@ -31,6 +31,55 @@
|
||||
|
||||
DockItemManager *DockItemManager::INSTANCE = nullptr;
|
||||
|
||||
static QGSettingsInterface *GSettingsByApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.app");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
{
|
||||
qWarning("Unless you are doing unit testing, you should't see this message");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QGSettingsInterface *GSettingsByActiveApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.activeapp");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
{
|
||||
qWarning("Unless you are doing unit testing, you should't see this message");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QGSettingsInterface *GSettingsByDockApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.dockapp");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
{
|
||||
qWarning("Unless you are doing unit testing, you should't see this message");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DockItemManager::DockItemManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_appInter(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus(), this))
|
||||
@ -41,7 +90,10 @@ DockItemManager::DockItemManager(QObject *parent)
|
||||
|
||||
// 应用区域
|
||||
for (auto entry : m_appInter->entries()) {
|
||||
AppItem *it = new AppItem(entry, QGSettingsInterface::Type::ImplType);
|
||||
AppItem *it = new AppItem(GSettingsByApp(QGSettingsInterface::ImplType)
|
||||
, GSettingsByActiveApp(QGSettingsInterface::ImplType)
|
||||
, GSettingsByDockApp(QGSettingsInterface::ImplType)
|
||||
, entry);
|
||||
manageItem(it);
|
||||
|
||||
connect(it, &AppItem::requestActivateWindow, m_appInter, &DBusDock::ActivateWindow, Qt::QueuedConnection);
|
||||
@ -190,7 +242,10 @@ void DockItemManager::appItemAdded(const QDBusObjectPath &path, const int index)
|
||||
++insertIndex;
|
||||
}
|
||||
|
||||
AppItem *item = new AppItem(path, QGSettingsInterface::Type::ImplType);
|
||||
AppItem *item = new AppItem(GSettingsByApp(QGSettingsInterface::ImplType)
|
||||
, GSettingsByActiveApp(QGSettingsInterface::ImplType)
|
||||
, GSettingsByDockApp(QGSettingsInterface::ImplType)
|
||||
, path);
|
||||
|
||||
if (m_appIDist.contains(item->appId())) {
|
||||
delete item;
|
||||
|
@ -46,59 +46,11 @@
|
||||
|
||||
QPoint AppItem::MousePressPos;
|
||||
|
||||
static QGSettingsInterface *GSettingsByApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.app");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
{
|
||||
qWarning("Unless you are doing unit testing, you should't see this message");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QGSettingsInterface *GSettingsByActiveApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.activeapp");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
{
|
||||
qWarning("Unless you are doing unit testing, you should't see this message");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static QGSettingsInterface *GSettingsByDockApp(QGSettingsInterface::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case QGSettingsInterface::Type::ImplType:
|
||||
{
|
||||
static QGSettingsInterfaceImpl settings("com.deepin.dde.dock.module.dockapp");
|
||||
return &settings;
|
||||
}
|
||||
default:
|
||||
{
|
||||
qWarning("Unless you are doing unit testing, you should't see this message");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppItem::AppItem(const QDBusObjectPath &entry, QGSettingsInterface::Type type, QWidget *parent)
|
||||
AppItem::AppItem(QGSettingsInterface *appSettings, QGSettingsInterface *activeAppSettings, QGSettingsInterface *dockedAppSettings, const QDBusObjectPath &entry, QWidget *parent)
|
||||
: DockItem(parent)
|
||||
, m_qgAppInterface(GSettingsByApp(type))
|
||||
, m_qgActiveAppInterface(GSettingsByActiveApp(type))
|
||||
, m_qgDockedAppInterface(GSettingsByDockApp(type))
|
||||
, m_qgAppInterface(appSettings)
|
||||
, m_qgActiveAppInterface(activeAppSettings)
|
||||
, m_qgDockedAppInterface(dockedAppSettings)
|
||||
, m_appNameTips(new TipsWidget(this))
|
||||
, m_appPreviewTips(nullptr)
|
||||
, m_itemEntryInter(new DockEntryInter("com.deepin.dde.daemon.Dock", entry.path(), QDBusConnection::sessionBus(), this))
|
||||
|
@ -44,7 +44,7 @@ class AppItem : public DockItem
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AppItem(const QDBusObjectPath &entry, QGSettingsInterface::Type type, QWidget *parent = nullptr);
|
||||
explicit AppItem(QGSettingsInterface *appSettings, QGSettingsInterface *activeAppSettings, QGSettingsInterface *dockedAppSettings, const QDBusObjectPath &entry, QWidget *parent = nullptr);
|
||||
~AppItem() override;
|
||||
|
||||
void checkEntry() override;
|
||||
|
@ -301,6 +301,11 @@ SHMInfo *AppSnapshot::getImageDSHM()
|
||||
{
|
||||
const auto display = QX11Info::display();
|
||||
|
||||
if (!display) {
|
||||
qWarning("QX11Info::display() is 0x0");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Atom atom_prop = XInternAtom(display, "_DEEPIN_DXCB_SHM_INFO", true);
|
||||
if (!atom_prop) {
|
||||
return nullptr;
|
||||
@ -324,6 +329,11 @@ SHMInfo *AppSnapshot::getImageDSHM()
|
||||
XImage *AppSnapshot::getImageXlib()
|
||||
{
|
||||
const auto display = QX11Info::display();
|
||||
if (!display) {
|
||||
qWarning("QX11Info::display() is 0x0");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Window unused_window;
|
||||
int unused_int;
|
||||
unsigned unused_uint, w, h;
|
||||
|
@ -45,10 +45,10 @@ void Test_AppDragWidget::TearDown()
|
||||
|
||||
TEST_F(Test_AppDragWidget, cuntion_test)
|
||||
{
|
||||
QGSettingsMock mock;
|
||||
ON_CALL(mock, get(::testing::_)) .WillByDefault(::testing::Invoke([](const QString& key){return 1.5; }));
|
||||
QGSettingsMock *mock = new QGSettingsMock;
|
||||
ON_CALL(*mock, get(::testing::_)) .WillByDefault(::testing::Invoke([](const QString& key){Q_UNUSED(key); return 1.5; }));
|
||||
|
||||
AppDragWidget *dragWidget = new AppDragWidget(&mock);
|
||||
AppDragWidget *dragWidget = new AppDragWidget(mock);
|
||||
|
||||
QPixmap pix(":/res/all_settings_on.png");
|
||||
dragWidget->setAppPixmap(pix);
|
||||
|
@ -35,54 +35,40 @@ class Test_FloatingPreview : public ::testing::Test
|
||||
public:
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
public:
|
||||
FloatingPreview *view = nullptr;
|
||||
};
|
||||
|
||||
void Test_FloatingPreview::SetUp()
|
||||
{
|
||||
view = new FloatingPreview(new QWidget);
|
||||
}
|
||||
|
||||
void Test_FloatingPreview::TearDown()
|
||||
{
|
||||
delete view;
|
||||
view = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(Test_FloatingPreview, view_test)
|
||||
{
|
||||
FloatingPreview *view = new FloatingPreview(new QWidget);
|
||||
AppSnapshot *shot = new AppSnapshot(1000);
|
||||
view->trackWindow(shot);
|
||||
|
||||
ASSERT_TRUE(view->m_titleBtn->text() == shot->title());
|
||||
|
||||
ASSERT_EQ(view->trackedWindow(), shot);
|
||||
|
||||
ASSERT_EQ(view->trackedWid(), shot->wid());
|
||||
|
||||
QSignalSpy spy(shot, &AppSnapshot::clicked);
|
||||
|
||||
QTest::mouseClick(view, Qt::LeftButton, Qt::NoModifier);
|
||||
|
||||
ASSERT_EQ(spy.count(), 1);
|
||||
|
||||
// view->m_closeBtn3D->click();
|
||||
// view->m_closeBtn3D->click();
|
||||
|
||||
view->hide();
|
||||
ASSERT_TRUE(shot->contentsMargins() == QMargins(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
TEST_F(Test_FloatingPreview, empty_test)
|
||||
{
|
||||
view->trackWindow(nullptr);
|
||||
|
||||
ASSERT_TRUE(view->m_titleBtn->text().isEmpty());
|
||||
ASSERT_EQ(view->trackedWindow(), shot);
|
||||
|
||||
ASSERT_EQ(view->trackedWindow(), nullptr);
|
||||
|
||||
// ASSERT_EQ(view->trackedWid(), 0);
|
||||
delete view;
|
||||
view = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QTest>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@ -28,6 +29,9 @@
|
||||
#include "appitem.h"
|
||||
#include "qgsettingsinterface.h"
|
||||
#undef private
|
||||
#include "mock/QGsettingsMock.h"
|
||||
|
||||
using namespace ::testing;
|
||||
|
||||
class Test_AppItem : public ::testing::Test
|
||||
{
|
||||
@ -40,42 +44,52 @@ public:
|
||||
};
|
||||
|
||||
void Test_AppItem::SetUp()
|
||||
{
|
||||
appItem = new AppItem(QDBusObjectPath("/com/deepin/dde/daemon/Dock/entries/e0T6045b766"), QGSettingsInterface::Type::MockType);
|
||||
{
|
||||
}
|
||||
|
||||
void Test_AppItem::TearDown()
|
||||
{
|
||||
delete appItem;
|
||||
appItem = nullptr;
|
||||
}
|
||||
|
||||
TEST_F(Test_AppItem, coverage_test)
|
||||
{
|
||||
QGSettingsMock mock;
|
||||
|
||||
ON_CALL(mock, type()).WillByDefault(Return(QGSettingsMock::Type::MockType));
|
||||
ON_CALL(mock, keys()).WillByDefault(Return(QStringList() << "enable" << "control"));
|
||||
ON_CALL(mock, get(_)) .WillByDefault(::testing::Invoke([](const QString& key){return true; }));
|
||||
|
||||
appItem = new AppItem(&mock, &mock, &mock, QDBusObjectPath("/com/deepin/dde/daemon/Dock/entries/e0T6045b766"));
|
||||
|
||||
appItem->checkEntry();
|
||||
// ASSERT_FALSE(appItem->isValid());
|
||||
// ASSERT_FALSE(appItem->isValid());
|
||||
|
||||
ASSERT_TRUE(appItem->itemType() == AppItem::App);
|
||||
|
||||
appItem->setDockInfo(Dock::Position::Top, QRect(QPoint(0,0), QPoint(1920, 40)));
|
||||
|
||||
ASSERT_TRUE(appItem->accessibleName() == appItem->m_itemEntryInter->name());
|
||||
}
|
||||
|
||||
TEST_F(Test_AppItem, AppItem_show_test)
|
||||
{
|
||||
appItem->show();
|
||||
|
||||
QThread::msleep(450);
|
||||
|
||||
ASSERT_TRUE(appItem->isVisible());
|
||||
}
|
||||
|
||||
TEST_F(Test_AppItem, AppItem_hide_test)
|
||||
{
|
||||
appItem->hide();
|
||||
|
||||
QThread::msleep(450);
|
||||
|
||||
ASSERT_TRUE(!appItem->isVisible());
|
||||
|
||||
QTest::mouseClick(appItem, Qt::LeftButton, Qt::NoModifier);
|
||||
QTest::qWait(10);
|
||||
QTest::mouseClick(appItem, Qt::MiddleButton, Qt::NoModifier);
|
||||
QTest::qWait(10);
|
||||
QTest::mouseClick(appItem, Qt::LeftButton, Qt::NoModifier, QPoint(-1, -1));
|
||||
QTest::qWait(10);
|
||||
QTest::mouseMove(appItem, appItem->geometry().center());
|
||||
|
||||
delete appItem;
|
||||
appItem = nullptr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user