diff --git a/frame/controller/dockitemmanager.cpp b/frame/controller/dockitemmanager.cpp index 37e866dbd..26e966776 100644 --- a/frame/controller/dockitemmanager.cpp +++ b/frame/controller/dockitemmanager.cpp @@ -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; diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index d3ff7dbda..14e16a15e 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -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)) diff --git a/frame/item/appitem.h b/frame/item/appitem.h index 5505efcdd..6c4686d99 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -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; diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 346c95f72..270a55464 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -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; diff --git a/tests/item/components/ut_appdragwidget.cpp b/tests/item/components/ut_appdragwidget.cpp index c7aed38b6..56ad21212 100644 --- a/tests/item/components/ut_appdragwidget.cpp +++ b/tests/item/components/ut_appdragwidget.cpp @@ -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); diff --git a/tests/item/components/ut_floatingpreview.cpp b/tests/item/components/ut_floatingpreview.cpp index d1d472b5a..ab3d8b6cf 100644 --- a/tests/item/components/ut_floatingpreview.cpp +++ b/tests/item/components/ut_floatingpreview.cpp @@ -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; } - diff --git a/tests/item/ut_appitem.cpp b/tests/item/ut_appitem.cpp index 42808e88a..60e27eade 100644 --- a/tests/item/ut_appitem.cpp +++ b/tests/item/ut_appitem.cpp @@ -21,6 +21,7 @@ #include #include +#include #include @@ -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; }