Skip to content

Commit

Permalink
feat: [test] add tag ut
Browse files Browse the repository at this point in the history
  • Loading branch information
pppanghu77 authored and deepin-bot[bot] committed Jul 24, 2023
1 parent c88beac commit 5a4a888
Show file tree
Hide file tree
Showing 19 changed files with 1,087 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void TagEventReceiver::handleFileCutResult(const QList<QUrl> &srcUrls, const QLi
{
Q_UNUSED(errMsg)

if (!ok)
if (!ok || destUrls.isEmpty())
return;

for (const QUrl &url : srcUrls) {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/common/dfmplugin-tag/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Tag : public dpf::Plugin
DPF_EVENT_REG_SIGNAL(signal_ReportLog_MenuData)

// hook events
DPF_EVENT_REG_HOOK(hook_CanTag) // Warning: The event is abandoned, please do not use it.
DPF_EVENT_REG_HOOK(hook_CanTaged)

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void AnythingMonitorFilter::reserveDir(QStringList *list)
for (const QString &path : *list) {
auto fileInfo { InfoFactory::create<FileInfo>(QUrl::fromLocalFile(path)) };

if (!fileInfo->isAttributes(OptInfoType::kIsDir))
if (fileInfo && !fileInfo->isAttributes(OptInfoType::kIsDir))
pathInvalid.push_back(path);
}

Expand Down
7 changes: 0 additions & 7 deletions src/plugins/common/dfmplugin-tag/utils/tagmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ bool TagManager::canTagFile(const QUrl &url) const
return localFileCanTagFilter(info);
}

if (dpfHookSequence->run("dfmplugin_tag", "hook_CanTag", url))
return true;

return false;
}

Expand All @@ -121,10 +118,6 @@ bool TagManager::canTagFile(const FileInfoPointer &info) const
}

bool canTag = localFileCanTagFilter(info);
if (!canTag) {
if (dpfHookSequence->run("dfmplugin_tag", "hook_CanTag", url))
return true;
}

return canTag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void RecentFileWatcherPrivate::initConnect()

auto onParentDeleted = [=](const QString &, const QString &deletedPath) {
if (path.startsWith(deletedPath) && !deletedPath.isEmpty()) {
qDebug() << "recent: watched: " << path << ", deleted: " << deletedPath;
qInfo() << "recent: watched: " << path << ", deleted: " << deletedPath;
Q_EMIT q->fileDeleted(QUrl::fromLocalFile(path));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool RecentMenuScene::initialize(const QVariantHash &params)
QString errString;
d->focusFileInfo = DFMBASE_NAMESPACE::InfoFactory::create<FileInfo>(d->focusFile, Global::CreateFileInfoType::kCreateFileInfoAuto, &errString);
if (d->focusFileInfo.isNull()) {
qDebug() << errString;
qWarning() << "focusFileInfo isNull :" << errString;
return false;
}
if (auto workspaceScene = dfmplugin_menu_util::menuSceneCreateScene(kWorkspaceMenuSceneName))
Expand Down
128 changes: 128 additions & 0 deletions tests/plugins/common/dfmplugin-tag/data/ut_tagproxyhandle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "stubext.h"
#include "data/tagproxyhandle.h"
#include "tagmanager_interface.h"

#include <dfm-base/dfm_event_defines.h>
#include <dfm-framework/event/event.h>

#include <gtest/gtest.h>
#include <QRect>
DFMBASE_USE_NAMESPACE
DPF_USE_NAMESPACE
using namespace dfmplugin_tag;

TEST(UT_TagProxyHandle, deleteFileTags)
{
bool isRun { false };
stub_ext::StubExt stub;
stub.set_lamda(&OrgDeepinFilemanagerServerTagManagerInterface::Delete, [&isRun]() {
isRun = true;
return QDBusPendingReply<bool>();
});
QMap<QString, QVariant> fileWithTag;
fileWithTag["1"] = QVariant(QStringList() << "red");

TagProxyHandle::instance()->deleteFileTags(fileWithTag);

EXPECT_TRUE(isRun);
}

TEST(UT_TagProxyHandle, deleteFiles)
{
bool isRun { false };
stub_ext::StubExt stub;
stub.set_lamda(&OrgDeepinFilemanagerServerTagManagerInterface::Delete, [&isRun]() {
isRun = true;
return QDBusPendingReply<bool>();
});
QMap<QString, QVariant> fileWithTag;
fileWithTag["1"] = QVariant(QStringList() << "red");

TagProxyHandle::instance()->deleteFiles(fileWithTag);

EXPECT_TRUE(isRun);
}

TEST(UT_TagProxyHandle, deleteTags)
{
bool isRun { false };
stub_ext::StubExt stub;
stub.set_lamda(&OrgDeepinFilemanagerServerTagManagerInterface::Delete, [&isRun]() {
isRun = true;
return QDBusPendingReply<bool>();
});
QMap<QString, QVariant> fileWithTag;
fileWithTag["1"] = QVariant(QStringList() << "red");

TagProxyHandle::instance()->deleteTags(fileWithTag);

EXPECT_TRUE(isRun);
}

TEST(UT_TagProxyHandle, update)
{
int isRun = 0;
stub_ext::StubExt stub;
stub.set_lamda(&OrgDeepinFilemanagerServerTagManagerInterface::Update, [&isRun]() {
isRun++;
return QDBusPendingReply<bool>();
});
QMap<QString, QVariant> fileWithTag;
fileWithTag["1"] = QVariant(QStringList() << "red");

TagProxyHandle::instance()->changeFilePaths(fileWithTag);
TagProxyHandle::instance()->changeTagNamesWithFiles(fileWithTag);
TagProxyHandle::instance()->changeTagsColor(fileWithTag);
EXPECT_TRUE(isRun == 3);
}

TEST(UT_TagProxyHandle, Insert)
{
int isRun = 0;
stub_ext::StubExt stub;
stub.set_lamda(&OrgDeepinFilemanagerServerTagManagerInterface::Insert, [&isRun]() {
isRun++;
return QDBusPendingReply<bool>();
});
QMap<QString, QVariant> fileWithTag;
fileWithTag["1"] = QVariant(QStringList() << "red");

TagProxyHandle::instance()->addTags(fileWithTag);
TagProxyHandle::instance()->addTagsForFiles(fileWithTag);
EXPECT_TRUE(isRun == 2);
}

TEST(UT_TagProxyHandle, Query)
{
int isRun = 0;
stub_ext::StubExt stub;
auto func = static_cast<QDBusPendingReply<QDBusVariant> (OrgDeepinFilemanagerServerTagManagerInterface::*)(int opt, const QStringList &)>(&OrgDeepinFilemanagerServerTagManagerInterface::Query);
stub.set_lamda(func, [&isRun]() {
isRun++;
return QDBusPendingReply<QDBusVariant>();
});

TagProxyHandle::instance()->getTagsColor(QStringList());
TagProxyHandle::instance()->getFilesThroughTag(QStringList());
TagProxyHandle::instance()->getSameTagsOfDiffFiles(QStringList());
TagProxyHandle::instance()->getTagsThroughFile(QStringList());
EXPECT_TRUE(isRun == 4);
}

TEST(UT_TagProxyHandle, Query2)
{
int isRun = 0;
stub_ext::StubExt stub;
auto func = static_cast<QDBusPendingReply<QDBusVariant> (OrgDeepinFilemanagerServerTagManagerInterface::*)(int opt)>(&OrgDeepinFilemanagerServerTagManagerInterface::Query);
stub.set_lamda(func, [&isRun]() {
isRun++;
return QDBusPendingReply<QDBusVariant>();
});

TagProxyHandle::instance()->getAllFileWithTags();
EXPECT_TRUE(isRun == 1);
}
128 changes: 128 additions & 0 deletions tests/plugins/common/dfmplugin-tag/event/ut_tageventcaller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "stubext.h"
#include "events/tageventcaller.h"

#include <dfm-base/dfm_event_defines.h>

#include <dfm-framework/event/event.h>

#include <gtest/gtest.h>
#include <QRect>
DFMBASE_USE_NAMESPACE
DPF_USE_NAMESPACE
using namespace dfmplugin_tag;

Q_DECLARE_METATYPE(QRectF *)
Q_DECLARE_METATYPE(QPoint *)

TEST(UT_TagEventCaller, sendOpenWindow)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef bool (EventDispatcherManager::*FuncType)(EventType, QUrl);
stub.set_lamda(static_cast<FuncType>(&EventDispatcherManager::publish), [&isCall] {
isCall = true;
return true;
});

TagEventCaller::sendOpenWindow(QUrl());

EXPECT_TRUE(isCall);
}

TEST(UT_TagEventCaller, sendOpenTab)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef bool (EventDispatcherManager::*FuncType)(EventType, quint64, const QUrl &);
stub.set_lamda(static_cast<FuncType>(&EventDispatcherManager::publish), [&isCall] {
isCall = true;
return true;
});

TagEventCaller::sendOpenTab(0, QUrl());

EXPECT_TRUE(isCall);
}

TEST(UT_TagEventCaller, sendCheckTabAddable)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef QVariant (EventChannelManager::*FuncType)(const QString &, const QString &, quint64);
stub.set_lamda(static_cast<FuncType>(&EventChannelManager::push), [&isCall] {
isCall = true;
return true;
});
TagEventCaller::sendCheckTabAddable(0);

EXPECT_TRUE(isCall);
}

TEST(UT_TagEventCaller, getCollectionView)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef QVariant (EventChannelManager::*FuncType)(const QString &, const QString &, QString);
stub.set_lamda(static_cast<FuncType>(&EventChannelManager::push), [&isCall] {
isCall = true;
return QVariant();
});

TagEventCaller::getCollectionView("");

EXPECT_TRUE(isCall);
}

TEST(UT_TagEventCaller, sendOpenFiles)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef bool (EventDispatcherManager::*FuncType)(EventType, quint64, const QList<QUrl> &);
stub.set_lamda(static_cast<FuncType>(&EventDispatcherManager::publish), [&isCall] {
isCall = true;
return true;
});

TagEventCaller::sendOpenFiles(0, QList<QUrl>() << QUrl());

EXPECT_TRUE(isCall);
}

TEST(UT_TagEventCaller, getCollectionVisualRect)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef QVariant (EventChannelManager::*FuncType)(const QString &, const QString &, QString, const QUrl &);
stub.set_lamda(static_cast<FuncType>(&EventChannelManager::push), [&isCall] {
isCall = true;
return QVariant();
});
TagEventCaller::getCollectionVisualRect("", QUrl());

EXPECT_TRUE(isCall);
}

TEST(UT_TagEventCaller, getCollectionIconRect)
{
bool isCall { false };

stub_ext::StubExt stub;
typedef QVariant (EventChannelManager::*FuncType)(const QString &, const QString &, QString, QRect &);
stub.set_lamda(static_cast<FuncType>(&EventChannelManager::push), [&isCall] {
isCall = true;
return QVariant();
});
TagEventCaller::getCollectionIconRect("", QRect());

EXPECT_TRUE(isCall);
}
Loading

0 comments on commit 5a4a888

Please sign in to comment.