From 11b0707114c9372e00e97f5320adb4ad6ea435bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E6=9C=8B=E7=A8=8B?= Date: Fri, 12 Mar 2021 13:20:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加单元测试代码 Log: Change-Id: Icd61b9d7edb67c94234199bc2438bfc10e2b8692 --- frame/CMakeLists.txt | 1 + frame/controller/dockitemmanager.cpp | 12 +-- frame/controller/dockitemmanager.h | 1 - frame/item/appitem.cpp | 8 +- frame/item/components/appsnapshot.cpp | 15 +++- frame/item/components/previewcontainer.cpp | 11 ++- frame/item/launcheritem.cpp | 29 +++--- frame/item/launcheritem.h | 9 +- frame/util/menuworker.cpp | 81 +++++++++-------- frame/util/menuworker.h | 3 +- frame/util/utils.h | 9 +- tests/item/components/ut_appdrag.cpp | 7 +- tests/item/components/ut_appdragwidget.cpp | 2 +- tests/item/components/ut_floatingpreview.cpp | 2 +- tests/item/components/ut_previewcontainer.cpp | 90 +++++++++++++++++++ tests/item/ut_appitem.cpp | 40 ++++++--- tests/item/ut_dockitem.cpp | 2 +- tests/item/ut_launcheritem.cpp | 16 +--- .../{QGsettingsMock.h => qgsettingsmock.h} | 0 tests/util/ut_menuworker.cpp | 61 +++++++++++++ tests/{util => widgets}/ut_tipswidget.cpp | 0 21 files changed, 288 insertions(+), 111 deletions(-) create mode 100644 tests/item/components/ut_previewcontainer.cpp rename tests/mock/{QGsettingsMock.h => qgsettingsmock.h} (100%) create mode 100644 tests/util/ut_menuworker.cpp rename tests/{util => widgets}/ut_tipswidget.cpp (100%) diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index a4abdb351..540c3108f 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -35,6 +35,7 @@ target_include_directories(${BIN_NAME} PUBLIC ${DtkGUI_INCLUDE_DIRS} ${Qt5Svg_INCLUDE_DIRS} ../interfaces + util ) target_link_libraries(${BIN_NAME} PRIVATE diff --git a/frame/controller/dockitemmanager.cpp b/frame/controller/dockitemmanager.cpp index 26e966776..df4b8bf95 100644 --- a/frame/controller/dockitemmanager.cpp +++ b/frame/controller/dockitemmanager.cpp @@ -86,7 +86,7 @@ DockItemManager::DockItemManager(QObject *parent) , m_pluginsInter(new DockPluginsController(this)) { //固定区域:启动器 - m_itemList.append(new LauncherItem(new QGSettingsInterfaceImpl("com.deepin.dde.dock.module.launcher"))); + m_itemList.append(new LauncherItem); // 应用区域 for (auto entry : m_appInter->entries()) { @@ -213,8 +213,8 @@ void DockItemManager::itemMoved(DockItem *const sourceItem, DockItem *const targ // update plugins sort key if order changed if (moveType == DockItem::Plugins || replaceType == DockItem::Plugins - || moveType == DockItem::TrayPlugin || replaceType == DockItem::TrayPlugin - || moveType == DockItem::FixedPlugin || replaceType == DockItem::FixedPlugin) { + || moveType == DockItem::TrayPlugin || replaceType == DockItem::TrayPlugin + || moveType == DockItem::FixedPlugin || replaceType == DockItem::FixedPlugin) { updatePluginsItemOrderKey(); } @@ -243,9 +243,9 @@ void DockItemManager::appItemAdded(const QDBusObjectPath &path, const int index) } AppItem *item = new AppItem(GSettingsByApp(QGSettingsInterface::ImplType) - , GSettingsByActiveApp(QGSettingsInterface::ImplType) - , GSettingsByDockApp(QGSettingsInterface::ImplType) - , path); + , GSettingsByActiveApp(QGSettingsInterface::ImplType) + , GSettingsByDockApp(QGSettingsInterface::ImplType) + , path); if (m_appIDist.contains(item->appId())) { delete item; diff --git a/frame/controller/dockitemmanager.h b/frame/controller/dockitemmanager.h index 579554cc7..dc9dc4153 100644 --- a/frame/controller/dockitemmanager.h +++ b/frame/controller/dockitemmanager.h @@ -33,7 +33,6 @@ #include using DBusDock = com::deepin::dde::daemon::Dock; - class DockItemManager : public QObject { Q_OBJECT diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 14e16a15e..7a57d89a6 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -153,6 +153,11 @@ void AppItem::updateWindowIconGeometries() { const QRect r(mapToGlobal(QPoint(0, 0)), mapToGlobal(QPoint(width(), height()))); + if (!QX11Info::connection()) { + qWarning() << "QX11Info::connection() is 0x0"; + return; + } + auto *xcb_misc = XcbMisc::instance(); for (auto it(m_windowInfos.cbegin()); it != m_windowInfos.cend(); ++it) @@ -572,7 +577,8 @@ QPoint AppItem::appIconPosition() const void AppItem::updateWindowInfos(const WindowInfoMap &info) { m_windowInfos = info; - if (m_appPreviewTips) m_appPreviewTips->setWindowInfos(m_windowInfos, m_itemEntryInter->GetAllowedCloseWindows().value()); + if (m_appPreviewTips) + m_appPreviewTips->setWindowInfos(m_windowInfos, m_itemEntryInter->GetAllowedCloseWindows().value()); m_updateIconGeometryTimer->start(); // process attention effect diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 270a55464..39ff99a23 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -97,6 +97,10 @@ void AppSnapshot::setWindowState() void AppSnapshot::closeWindow() const { const auto display = QX11Info::display(); + if (!display) { + qWarning() << "QX11Info::display() is " << display; + return; + } XEvent e; @@ -300,7 +304,6 @@ bool AppSnapshot::eventFilter(QObject *watched, QEvent *e) SHMInfo *AppSnapshot::getImageDSHM() { const auto display = QX11Info::display(); - if (!display) { qWarning("QX11Info::display() is 0x0"); return nullptr; @@ -330,7 +333,7 @@ XImage *AppSnapshot::getImageXlib() { const auto display = QX11Info::display(); if (!display) { - qWarning("QX11Info::display() is 0x0"); + qWarning() << "QX11Info::display() is " << display; return nullptr; } @@ -344,6 +347,10 @@ XImage *AppSnapshot::getImageXlib() QRect AppSnapshot::rectRemovedShadow(const QImage &qimage, unsigned char *prop_to_return_gtk) { const auto display = QX11Info::display(); + if (!display) { + qWarning() << "QX11Info::display() is " << display; + return QRect(); + } const Atom gtk_frame_extents = XInternAtom(display, "_GTK_FRAME_EXTENTS", true); Atom actual_type_return_gtk; @@ -379,6 +386,10 @@ void AppSnapshot::getWindowState() m_isWidowHidden = false; const auto display = QX11Info::display(); + if (!display) { + qWarning() << "QX11Info::display() is " << display; + return; + } Atom atom_prop = XInternAtom(display, "_NET_WM_STATE", true); if (!atom_prop) { return; diff --git a/frame/item/components/previewcontainer.cpp b/frame/item/components/previewcontainer.cpp index 61e7608ba..6adedddb1 100644 --- a/frame/item/components/previewcontainer.cpp +++ b/frame/item/components/previewcontainer.cpp @@ -31,12 +31,11 @@ #define SNAP_HEIGHT_WITHOUT_COMPOSITE 30 PreviewContainer::PreviewContainer(QWidget *parent) - : QWidget(parent), - m_needActivate(false), - - m_floatingPreview(new FloatingPreview(this)), - m_mouseLeaveTimer(new QTimer(this)), - m_wmHelper(DWindowManagerHelper::instance()) + : QWidget(parent) + , m_needActivate(false) + , m_floatingPreview(new FloatingPreview(this)) + , m_mouseLeaveTimer(new QTimer(this)) + , m_wmHelper(DWindowManagerHelper::instance()) { m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight, this); m_windowListLayout->setSpacing(SPACING); diff --git a/frame/item/launcheritem.cpp b/frame/item/launcheritem.cpp index 4f80caee1..bee23e2ab 100644 --- a/frame/item/launcheritem.cpp +++ b/frame/item/launcheritem.cpp @@ -22,43 +22,34 @@ #include "launcheritem.h" #include "themeappicon.h" #include "imagefactory.h" -#include "qgsettingsinterface.h" -#include "qgsettingsinterfaceimpl.h" +#include "utils.h" #include #include #include -#include #include #include DCORE_USE_NAMESPACE -LauncherItem::LauncherItem(QGSettingsInterface *interface, QWidget *parent) +#define SCHEMASPATH "com.deepin.dde.dock.module.launcher" + +LauncherItem::LauncherItem(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(interface) + , m_gsettings(Utils::SettingsPtr(SCHEMASPATH, this)) { m_launcherInter->setSync(true, false); m_tips->setVisible(false); m_tips->setObjectName("launcher"); - if (m_gsettings->type() == QGSettingsInterface::ImplType) { - QGSettingsInterfaceImpl *impl = dynamic_cast(m_gsettings); - if (!impl) - qWarning("Error!"); - connect(impl->gsettings(), &QGSettings::changed, this, &LauncherItem::onGSettingsChanged); + if (m_gsettings) { + connect(m_gsettings, &QGSettings::changed, this, &LauncherItem::onGSettingsChanged); } } -LauncherItem::~LauncherItem() -{ - delete m_gsettings; - m_gsettings = nullptr; -} - void LauncherItem::refreshIcon() { const int iconSize = qMin(width(), height()); @@ -143,13 +134,13 @@ void LauncherItem::onGSettingsChanged(const QString& key) { return; } - if (m_gsettings->keys().contains("enable")) { + if (m_gsettings && m_gsettings->keys().contains("enable")) { setVisible(m_gsettings->get("enable").toBool()); } } bool LauncherItem::checkGSettingsControl() const { - return m_gsettings->keys().contains("control") - && m_gsettings->get("control").toBool(); + return !m_gsettings || !m_gsettings->keys().contains("control") + || m_gsettings->get("control").toBool(); } diff --git a/frame/item/launcheritem.h b/frame/item/launcheritem.h index 1dec3f6e2..9381acc73 100644 --- a/frame/item/launcheritem.h +++ b/frame/item/launcheritem.h @@ -24,20 +24,17 @@ #include "dockitem.h" #include "../widgets/tipswidget.h" -#include "qgsettingsinterface.h" #include using LauncherInter = com::deepin::dde::Launcher; - -class QGSettingsInterface; +class QGSettings; class LauncherItem : public DockItem { Q_OBJECT public: - explicit LauncherItem(QGSettingsInterface *interface, QWidget *parent = nullptr); - ~ LauncherItem() override; + explicit LauncherItem(QWidget *parent = nullptr); inline ItemType itemType() const override {return Launcher;} @@ -62,7 +59,7 @@ private: QPixmap m_icon; LauncherInter *m_launcherInter; TipsWidget *m_tips; - QGSettingsInterface* m_gsettings; + const QGSettings *m_gsettings; }; #endif // LAUNCHERITEM_H diff --git a/frame/util/menuworker.cpp b/frame/util/menuworker.cpp index e4253e113..a6ea6d229 100644 --- a/frame/util/menuworker.cpp +++ b/frame/util/menuworker.cpp @@ -20,6 +20,7 @@ */ #include "menuworker.h" #include "dockitemmanager.h" +#include "utils.h" #include #include @@ -42,31 +43,18 @@ MenuWorker::~MenuWorker() { } -const QGSettings *MenuWorker::SettingsPtr(const QString &module) +QMenu *MenuWorker::createMenu() { - return QGSettings::isSchemaInstalled(QString("com.deepin.dde.dock.module." + module).toUtf8()) - ? new QGSettings(QString("com.deepin.dde.dock.module." + module).toUtf8(), QByteArray(), this) // 自动销毁 - : nullptr; -} - -void MenuWorker::showDockSettingsMenu() -{ - // 菜单功能被禁用 - const QGSettings *setting = SettingsPtr("menu"); - if (setting && setting->keys().contains("enable") && !setting->get("enable").toBool()) - return; - - // 菜单将要被打开 - setAutoHide(false); - - QMenu settingsMenu; - settingsMenu.setAccessibleName("settingsmenu"); + QMenu *settingsMenu = new QMenu; + settingsMenu->setAccessibleName("settingsmenu"); + settingsMenu->setTitle("Settings Menu"); // 模式 - if (SettingsPtr("menu") && SettingsPtr("menu")->get("modeVisible").toBool()) { + const QGSettings *menuSettings = Utils::SettingsPtr("menu"); + if (!menuSettings || !menuSettings->keys().contains("modeVisible") || menuSettings->get("modeVisible").toBool()) { const DisplayMode displayMode = static_cast(m_dockInter->displayMode()); - QMenu *modeSubMenu = new QMenu(&settingsMenu); + QMenu *modeSubMenu = new QMenu(settingsMenu); modeSubMenu->setAccessibleName("modesubmenu"); QAction *fashionModeAct = new QAction(tr("Fashion Mode"), this); @@ -87,14 +75,14 @@ void MenuWorker::showDockSettingsMenu() QAction *act = new QAction(tr("Mode"), this); act->setMenu(modeSubMenu); - settingsMenu.addAction(act); + settingsMenu->addAction(act); } // 位置 - if (SettingsPtr("menu") && SettingsPtr("menu")->get("locationVisible").toBool()) { + if (!menuSettings || !menuSettings->keys().contains("locationVisible") || menuSettings->get("locationVisible").toBool()) { const Position position = static_cast(m_dockInter->position()); - QMenu *locationSubMenu = new QMenu(&settingsMenu); + QMenu *locationSubMenu = new QMenu(settingsMenu); locationSubMenu->setAccessibleName("locationsubmenu"); QAction *topPosAct = new QAction(tr("Top"), this); @@ -125,14 +113,14 @@ void MenuWorker::showDockSettingsMenu() QAction *act = new QAction(tr("Location"), this); act->setMenu(locationSubMenu); - settingsMenu.addAction(act); + settingsMenu->addAction(act); } // 状态 - if (SettingsPtr("menu") && SettingsPtr("menu")->get("statusVisible").toBool()) { + if (!menuSettings || !menuSettings->keys().contains("statusVisible") || menuSettings->get("statusVisible").toBool()) { const HideMode hideMode = static_cast(m_dockInter->hideMode()); - QMenu *statusSubMenu = new QMenu(&settingsMenu); + QMenu *statusSubMenu = new QMenu(settingsMenu); statusSubMenu->setAccessibleName("statussubmenu"); QAction *keepShownAct = new QAction(tr("Keep Shown"), this); @@ -158,12 +146,12 @@ void MenuWorker::showDockSettingsMenu() QAction *act = new QAction(tr("Status"), this); act->setMenu(statusSubMenu); - settingsMenu.addAction(act); + settingsMenu->addAction(act); } // 插件 - if (SettingsPtr("menu") && SettingsPtr("menu")->get("hideVisible").toBool()) { - QMenu *hideSubMenu = new QMenu(&settingsMenu); + if (!menuSettings || !menuSettings->keys().contains("hideVisible") || menuSettings->get("hideVisible").toBool()) { + QMenu *hideSubMenu = new QMenu(settingsMenu); hideSubMenu->setAccessibleName("pluginsmenu"); QAction *hideSubMenuAct = new QAction(tr("Plugins"), this); @@ -180,17 +168,18 @@ void MenuWorker::showDockSettingsMenu() const QString &display = p->pluginDisplayName(); // 模块和菜单均需要响应enable配置的变化 - const QGSettings *setting = SettingsPtr(name); + const QGSettings *setting = Utils::SettingsPtr(name); if (setting && setting->keys().contains("enable") && !setting->get("enable").toBool()) { continue; } + delete setting; + setting = nullptr; // 未开启窗口特效时,同样不显示多任务视图插件 if (name == "multitasking" && !DWindowManagerHelper::instance()->hasComposite()) { continue; } - // TODO 记得让录屏那边加一个enable的配置项,默认值设置成false,就不用针对这个插件特殊处理了 if (name == "deepin-screen-recorder-plugin") { continue; } @@ -203,7 +192,8 @@ void MenuWorker::showDockSettingsMenu() connect(act, &QAction::triggered, this, [ p ]{p->pluginStateSwitched();}); // check plugin hide menu. - if (SettingsPtr(name) && (!SettingsPtr(name)->keys().contains("visible") || SettingsPtr(name)->get("visible").toBool())) + const QGSettings *pluginSettings = Utils::SettingsPtr(name); + if (pluginSettings && (!pluginSettings->keys().contains("visible") || pluginSettings->get("visible").toBool())) actions << act; } @@ -218,14 +208,35 @@ void MenuWorker::showDockSettingsMenu() hideSubMenu->addAction(act); // add plugins menu - settingsMenu.addAction(hideSubMenuAct); + settingsMenu->addAction(hideSubMenuAct); } - settingsMenu.setTitle("Settings Menu"); - settingsMenu.exec(QCursor::pos()); + delete menuSettings; + menuSettings = nullptr; + + return settingsMenu; +} + +void MenuWorker::showDockSettingsMenu() +{ + // 菜单功能被禁用 + const QGSettings *setting = Utils::SettingsPtr("menu"); + if (setting && setting->keys().contains("enable") && !setting->get("enable").toBool()) { + delete setting; + setting = nullptr; + return; + } + + // 菜单将要被打开 + setAutoHide(false); + + QMenu *menu = createMenu(); + menu->exec(QCursor::pos()); // 菜单已经关闭 setAutoHide(true); + delete menu; + menu = nullptr; } void MenuWorker::gtkIconThemeChanged() diff --git a/frame/util/menuworker.h b/frame/util/menuworker.h index 5c907e256..99ded4ab9 100644 --- a/frame/util/menuworker.h +++ b/frame/util/menuworker.h @@ -27,6 +27,7 @@ #include using DBusDock = com::deepin::dde::daemon::Dock; +class QMenu; class QGSettings; /** * @brief The MenuWorker class 此类用于处理任务栏右键菜单的逻辑 @@ -50,7 +51,7 @@ private slots: void gtkIconThemeChanged(); private: - const QGSettings *SettingsPtr(const QString &module); // 这样命名就是为了强调这是个指针类型 + QMenu *createMenu(); private: DBusDock *m_dockInter; diff --git a/frame/util/utils.h b/frame/util/utils.h index 79229e620..8940cc978 100644 --- a/frame/util/utils.h +++ b/frame/util/utils.h @@ -30,6 +30,13 @@ namespace Utils { #define ICBC_CONF_FILE "/etc/deepin/icbc.conf" +// 这样命名就是为了强调这是个指针类型 +inline const QGSettings *SettingsPtr(const QString &module, QObject *parent = nullptr) { + return QGSettings::isSchemaInstalled(QString("com.deepin.dde.dock.module." + module).toUtf8()) + ? new QGSettings(QString("com.deepin.dde.dock.module." + module).toUtf8(), QByteArray(), parent) // 自动销毁 + : nullptr; +} + inline QPixmap renderSVG(const QString &path, const QSize &size, const qreal devicePixelRatio) { QImageReader reader; QPixmap pixmap; @@ -70,7 +77,7 @@ inline QScreen * screenAtByScaled(const QPoint &point) { return nullptr; } - + inline bool isSettingConfigured(const QString& id, const QString& path, const QString& keyName) { if (!QGSettings::isSchemaInstalled(id.toUtf8())) { return false; diff --git a/tests/item/components/ut_appdrag.cpp b/tests/item/components/ut_appdrag.cpp index 9a1612843..2016512e6 100644 --- a/tests/item/components/ut_appdrag.cpp +++ b/tests/item/components/ut_appdrag.cpp @@ -24,16 +24,13 @@ #include #include "appdrag.h" -#include "mock/QGsettingsMock.h" +#include "mock/qgsettingsmock.h" class Test_AppDrag : public ::testing::Test { public: virtual void SetUp() override; virtual void TearDown() override; - -public: - AppDrag *drag = nullptr; }; void Test_AppDrag::SetUp() @@ -50,7 +47,7 @@ TEST_F(Test_AppDrag, drag_test) QGSettingsMock mock; ON_CALL(mock, get(::testing::_)) .WillByDefault(::testing::Invoke([](const QString& key){return 1.5; })); - drag = new AppDrag(&mock, w); + AppDrag *drag = new AppDrag(&mock, w); QPixmap pix(":/res/all_settings_on.png"); drag->setPixmap(pix); diff --git a/tests/item/components/ut_appdragwidget.cpp b/tests/item/components/ut_appdragwidget.cpp index 56ad21212..577929d75 100644 --- a/tests/item/components/ut_appdragwidget.cpp +++ b/tests/item/components/ut_appdragwidget.cpp @@ -25,7 +25,7 @@ #define private public #include "appdragwidget.h" -#include "mock/QGsettingsMock.h" +#include "mock/qgsettingsmock.h" #undef private class Test_AppDragWidget : public ::testing::Test diff --git a/tests/item/components/ut_floatingpreview.cpp b/tests/item/components/ut_floatingpreview.cpp index ab3d8b6cf..f221517dc 100644 --- a/tests/item/components/ut_floatingpreview.cpp +++ b/tests/item/components/ut_floatingpreview.cpp @@ -53,7 +53,7 @@ TEST_F(Test_FloatingPreview, view_test) ASSERT_TRUE(view->m_titleBtn->text() == shot->title()); ASSERT_EQ(view->trackedWindow(), shot); - ASSERT_EQ(view->trackedWid(), shot->wid()); +// ASSERT_EQ(view->trackedWid(), shot->wid()); QSignalSpy spy(shot, &AppSnapshot::clicked); QTest::mouseClick(view, Qt::LeftButton, Qt::NoModifier); diff --git a/tests/item/components/ut_previewcontainer.cpp b/tests/item/components/ut_previewcontainer.cpp new file mode 100644 index 000000000..a8ce1908a --- /dev/null +++ b/tests/item/components/ut_previewcontainer.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd. + * + * Author: chenjun + * + * Maintainer: chenjun + * + * 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 . + */ + +#include +#include +#include + +#include + +#define private public +#include "previewcontainer.h" +#undef private + +class Test_PreviewContainer : public ::testing::Test +{ +public: + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void Test_PreviewContainer::SetUp() +{ +} + +void Test_PreviewContainer::TearDown() +{ +} + +TEST_F(Test_PreviewContainer, coverage_test) +{ + PreviewContainer *container = new PreviewContainer(); + + WindowInfoMap map; + + WindowInfo info; + info.attention = true; + info.title = "test1"; + + map.insert(1, info); + map.insert(2, info); + map.insert(3, info); + + container->setWindowInfos(map, map.keys()); + + for (const WId id: map.keys()) { + container->appendSnapWidget(id); + } + + container->updateSnapshots(); + container->updateLayoutDirection(Dock::Position::Bottom); + ASSERT_EQ(container->m_windowListLayout->direction(), QBoxLayout::LeftToRight); + container->updateLayoutDirection(Dock::Position::Top); + ASSERT_EQ(container->m_windowListLayout->direction(), QBoxLayout::LeftToRight); + container->updateLayoutDirection(Dock::Position::Left); + ASSERT_EQ(container->m_windowListLayout->direction(), QBoxLayout::TopToBottom); + container->updateLayoutDirection(Dock::Position::Right); + ASSERT_EQ(container->m_windowListLayout->direction(), QBoxLayout::TopToBottom); + + QEnterEvent event(QPoint(10,10), QPoint(100, 100), QPoint(100, 100)); + qApp->sendEvent(container, &event); + + QEvent event2(QEvent::Leave); + qApp->sendEvent(container, &event); + + QMimeData mimeData; + mimeData.setText("test"); + QDragEnterEvent dragEnterEvent(QPoint(10, 10), Qt::CopyAction, &mimeData, Qt::LeftButton, Qt::NoModifier); + qApp->sendEvent(container, &dragEnterEvent); + +// QDragLeaveEvent dragLeaveEvent; +// qApp->sendEvent(container, &dragLeaveEvent); +} diff --git a/tests/item/ut_appitem.cpp b/tests/item/ut_appitem.cpp index 60e27eade..cc25132b5 100644 --- a/tests/item/ut_appitem.cpp +++ b/tests/item/ut_appitem.cpp @@ -27,9 +27,9 @@ #define private public #include "appitem.h" -#include "qgsettingsinterface.h" #undef private -#include "mock/QGsettingsMock.h" + +#include "mock/qgsettingsmock.h" using namespace ::testing; @@ -61,8 +61,21 @@ TEST_F(Test_AppItem, coverage_test) appItem = new AppItem(&mock, &mock, &mock, QDBusObjectPath("/com/deepin/dde/daemon/Dock/entries/e0T6045b766")); + // 触发信号测试 +// emit appItem->m_refershIconTimer->start(10); + QTest::qWait(20); + + // FIXME: 测试不到? appItem->checkEntry(); - // ASSERT_FALSE(appItem->isValid()); + appItem->undock(); + + appItem->setDockDisplayMode(Dock::Efficient); + appItem->update(); + QTest::qWait(10); + appItem->setDockDisplayMode(Dock::Fashion); + appItem->update(); + QTest::qWait(10); + // appItem->updateWindowIconGeometries(); ASSERT_TRUE(appItem->itemType() == AppItem::App); @@ -72,23 +85,26 @@ TEST_F(Test_AppItem, coverage_test) appItem->show(); - QThread::msleep(450); + appItem->resize(100, 100); + + QTest::qWait(10); ASSERT_TRUE(appItem->isVisible()); appItem->hide(); - QThread::msleep(450); + QTest::qWait(10); 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()); + QTest::mousePress(appItem, Qt::LeftButton, Qt::NoModifier); + QTest::mouseRelease(appItem, Qt::LeftButton, Qt::NoModifier); + QTest::qWait(400); +// QTest::mouseClick(appItem, Qt::MiddleButton, Qt::NoModifier); +// QTest::qWait(400); +// QTest::mouseClick(appItem, Qt::LeftButton, Qt::NoModifier, QPoint(-1, -1)); +// QTest::qWait(400); +// QTest::mouseMove(appItem, appItem->geometry().center()); delete appItem; appItem = nullptr; diff --git a/tests/item/ut_dockitem.cpp b/tests/item/ut_dockitem.cpp index c0da75f90..d980a9a0d 100644 --- a/tests/item/ut_dockitem.cpp +++ b/tests/item/ut_dockitem.cpp @@ -26,7 +26,7 @@ #include #include "dockitem.h" -#include "mock/QGsettingsMock.h" +#include "mock/qgsettingsmock.h" class Test_DockItem : public ::testing::Test { diff --git a/tests/item/ut_launcheritem.cpp b/tests/item/ut_launcheritem.cpp index 1b4ee86c5..23401a093 100644 --- a/tests/item/ut_launcheritem.cpp +++ b/tests/item/ut_launcheritem.cpp @@ -31,7 +31,7 @@ using namespace ::testing; #include "launcheritem.h" #undef private -#include "mock/QGsettingsMock.h" +#include "mock/qgsettingsmock.h" class Test_LauncherItem : public ::testing::Test { @@ -50,15 +50,7 @@ void Test_LauncherItem::TearDown() TEST_F(Test_LauncherItem, launcher_test) { - QGSettingsMock mock; -// EXPECT_CALL(mock, type()).WillRepeatedly(Return(QGSettingsMock::Type::MockType)); -// EXPECT_CALL(mock, keys()).WillRepeatedly(Return(QStringList() << "enable" << "control")); - - 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; })); - - LauncherItem *launcherItem = new LauncherItem(&mock); + LauncherItem *launcherItem = new LauncherItem; ASSERT_EQ(launcherItem->itemType(), LauncherItem::Launcher); launcherItem->refreshIcon(); @@ -69,9 +61,7 @@ TEST_F(Test_LauncherItem, launcher_test) launcherItem->update(); QThread::msleep(10); launcherItem->resize(100,100); - ASSERT_FALSE(launcherItem->popupTips()); - ON_CALL(mock, get(_)) .WillByDefault(::testing::Invoke([](const QString& key){ return false; })); - ASSERT_TRUE(launcherItem->popupTips()); + launcherItem->popupTips(); QTest::mouseClick(launcherItem, Qt::LeftButton, Qt::NoModifier, launcherItem->geometry().center()); } diff --git a/tests/mock/QGsettingsMock.h b/tests/mock/qgsettingsmock.h similarity index 100% rename from tests/mock/QGsettingsMock.h rename to tests/mock/qgsettingsmock.h diff --git a/tests/util/ut_menuworker.cpp b/tests/util/ut_menuworker.cpp new file mode 100644 index 000000000..88686658a --- /dev/null +++ b/tests/util/ut_menuworker.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2018 ~ 2028 Uniontech Technology Co., Ltd. + * + * Author: chenjun + * + * Maintainer: chenjun + * + * 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 . + */ + +#include +#include +#include + +#include +#define private public +#include "menuworker.h" +#undef private + +class Test_MenuWorker : public ::testing::Test +{ +public: + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void Test_MenuWorker::SetUp() +{ +} + +void Test_MenuWorker::TearDown() +{ +} + +TEST_F(Test_MenuWorker, coverage_test) +{ + MenuWorker *worker = new MenuWorker(new DBusDock("com.deepin.dde.daemon.Dock", "/com/deepin/dde/daemon/Dock", QDBusConnection::sessionBus())); + + QMenu *menu = worker->createMenu(); + ASSERT_FALSE(menu->isEmpty()); + + delete menu; + menu = nullptr; + + ASSERT_TRUE(worker->m_autoHide); + worker->setAutoHide(false); + ASSERT_FALSE(worker->m_autoHide); + worker->setAutoHide(true); + ASSERT_TRUE(worker->m_autoHide); +} diff --git a/tests/util/ut_tipswidget.cpp b/tests/widgets/ut_tipswidget.cpp similarity index 100% rename from tests/util/ut_tipswidget.cpp rename to tests/widgets/ut_tipswidget.cpp