Skip to content

Commit

Permalink
feat: [ut] New plugin for unit test
Browse files Browse the repository at this point in the history
as title

Log: unit test plugin
  • Loading branch information
Kakueeen committed Dec 30, 2024
1 parent 983b499 commit 4432189
Show file tree
Hide file tree
Showing 45 changed files with 3,624 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ add_subdirectory(codegeex)
add_subdirectory(git)
add_subdirectory(linglong)
add_subdirectory(aimanager)
add_subdirectory(smartut)
16 changes: 10 additions & 6 deletions src/plugins/core/gui/workspacewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ void WorkspaceWidget::registerToolBtnToWidget(DToolButton *btn, const QString &t
if (!btn)
return;

if (!btn->parent())
btn->setParent(this);

if (btn->isHidden())
toolBtnState[btn] = false;
else
toolBtnState[btn] = true;

toolBtnOfWidget.insert(title, btn);
}

Expand All @@ -68,18 +76,14 @@ void WorkspaceWidget::switchWidgetWorkspace(const QString &title)

emit expandStateChange(widget->property("canExpand").toBool());

if (!addedToController || (lastTitle == title))
return;

//update toolbtn`s state at header
for (auto btn : getToolBtnByTitle(lastTitle)) {
toolBtnState[btn] = btn->isVisible();
toolBtnState[btn] = !btn->isHidden();
btn->setVisible(false);
}

for (auto btn : getToolBtnByTitle(title)) {
if (toolBtnState.contains(btn))
btn->setVisible(toolBtnState[btn]);
btn->setVisible(toolBtnState[btn]);
}

emit workSpaceWidgeSwitched(title);
Expand Down
30 changes: 30 additions & 0 deletions src/plugins/smartut/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.0.2)

project(smartut)

FILE(GLOB_RECURSE PROJECT_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/*.json"
)

add_library(${PROJECT_NAME}
SHARED
${PROJECT_SOURCES}
smartut.qrc
)

target_link_libraries(${PROJECT_NAME}
duc-framework
duc-base
duc-services
duc-common
${QtUseModules}
${PkgUserModules}
${DtkWidget_LIBRARIES}
)

install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})

199 changes: 199 additions & 0 deletions src/plugins/smartut/common/itemnode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "itemnode.h"
#include "utils/utils.h"

Check warning on line 6 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "utils/utils.h" not found.

Check warning on line 6 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "utils/utils.h" not found.

#include "common/util/qtcassert.h"

Check warning on line 8 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "common/util/qtcassert.h" not found.

Check warning on line 8 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "common/util/qtcassert.h" not found.
#include "services/project/projectservice.h"

Check warning on line 9 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "services/project/projectservice.h" not found.

Check warning on line 9 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "services/project/projectservice.h" not found.

#include <DFileIconProvider>

Check warning on line 11 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DFileIconProvider> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DFileIconProvider> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QFileInfo>

Check warning on line 13 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DWIDGET_USE_NAMESPACE
using namespace dpfservice;

ProjectNode *Node::parentProjectNode() const
{
if (!nodeParentFolderNode)
return nullptr;
auto pn = nodeParentFolderNode->asProjectNode();
if (pn)
return pn;
return nodeParentFolderNode->parentProjectNode();
}

FolderNode *Node::parentFolderNode() const
{
return nodeParentFolderNode;
}

dpfservice::ProjectInfo Node::projectInfo() const

Check warning on line 33 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'projectInfo' is never used.

Check warning on line 33 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'projectInfo' is never used.
{
auto prjSrv = dpfGetService(ProjectService);
Q_ASSERT(prjSrv);

const auto &allInfos = prjSrv->getAllProjectInfo();
auto iter = std::find_if(allInfos.cbegin(), allInfos.cend(),
[this](const ProjectInfo &info) {
return nodeFilePath.startsWith(info.workspaceFolder());
});

return iter == allInfos.cend() ? ProjectInfo() : *iter;
}

QString Node::filePath() const
{
return nodeFilePath;
}

QString Node::displayName() const
{
return QFileInfo(nodeFilePath).fileName();
}

QString Node::tooltip() const
{
return nodeFilePath;
}

QIcon Node::icon() const
{
return DFileIconProvider::globalProvider()->icon(QFileInfo(nodeFilePath));
}

bool Node::sortByPath(const Node *a, const Node *b)

Check warning on line 67 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'sortByPath' is never used.

Check warning on line 67 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'sortByPath' is never used.
{
return a->filePath() < b->filePath();
}

void Node::setParentFolderNode(FolderNode *parentFolder)
{
nodeParentFolderNode = parentFolder;
}

void Node::setFilePath(const QString &filePath)
{
nodeFilePath = filePath;
}

FileNode::FileNode(const QString &filePath)
{
setFilePath(filePath);
}

void FileNode::setSourceFiles(const QStringList &files)

Check warning on line 87 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setSourceFiles' is never used.

Check warning on line 87 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'setSourceFiles' is never used.
{
sourceList = files;
}

QStringList FileNode::sourceFiles() const
{
return sourceList;
}

FolderNode::FolderNode(const QString &folderPath)
{
setFilePath(folderPath);
nodeDisplayName = Node::displayName();
}

void FolderNode::setDisplayName(const QString &name)
{
nodeDisplayName = name;
}

QString FolderNode::displayName() const
{
return nodeDisplayName;
}

void FolderNode::addNode(std::unique_ptr<Node> &&node)
{
QTC_ASSERT(node, return );
QTC_ASSERT(!node->parentFolderNode(), qDebug("Node has already a parent folder"));
node->setParentFolderNode(this);
children.emplace_back(std::move(node));
}

const QList<Node *> FolderNode::nodes() const

Check warning on line 121 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'nodes' is never used.

Check warning on line 121 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'nodes' is never used.
{
QList<Node *> nodeList;
std::transform(children.begin(), children.end(), std::back_inserter(nodeList),
[](const auto &pointer) {
return pointer.get();
});
return nodeList;
}

FolderNode *FolderNode::folderNode(const QString &directory) const
{
auto iter = std::find_if(children.cbegin(), children.cend(),
[directory](const std::unique_ptr<Node> &n) {
FolderNode *fn = n->asFolderNode();

Check warning on line 135 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'fn' can be declared as pointer to const

Check warning on line 135 in src/plugins/smartut/common/itemnode.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Variable 'fn' can be declared as pointer to const
return fn && fn->filePath() == directory;
});

return iter == children.cend() ? nullptr : static_cast<FolderNode *>(iter->get());
}

FolderNode *FolderNode::findChildFolderNode(const std::function<bool(FolderNode *)> &predicate) const
{
for (const std::unique_ptr<Node> &n : children) {
if (FolderNode *fn = n->asFolderNode())
if (predicate(fn))
return fn;
}
return nullptr;
}

void FolderNode::addNestedNodes(std::vector<std::unique_ptr<FileNode>> &&files,
const QString &overrideBaseDir,
const FolderNodeFactory &factory)
{
using DirWithNodes = std::pair<QString, std::vector<std::unique_ptr<FileNode>>>;
std::vector<DirWithNodes> fileNodesPerDir;
for (auto &f : files) {
QFileInfo fileInfo(f->filePath());
const QString parentDir = fileInfo.absolutePath();
const auto it = std::lower_bound(fileNodesPerDir.begin(), fileNodesPerDir.end(), parentDir,
[](const DirWithNodes &nad, const QString &dir) { return nad.first < dir; });
if (it != fileNodesPerDir.end() && it->first == parentDir) {
it->second.emplace_back(std::move(f));
} else {
DirWithNodes dirWithNodes;
dirWithNodes.first = parentDir;
dirWithNodes.second.emplace_back(std::move(f));
fileNodesPerDir.insert(it, std::move(dirWithNodes));
}
}

for (DirWithNodes &dirWithNodes : fileNodesPerDir) {
FolderNode *const folderNode = Utils::recursiveFindOrCreateFolderNode(this, dirWithNodes.first,
overrideBaseDir, factory);
for (auto &f : dirWithNodes.second)
folderNode->addNode(std::move(f));
}
}

QIcon FolderNode::icon() const
{
if (!QFile::exists(filePath()))
return QIcon::fromTheme("folder");

return Node::icon();
}

VirtualFolderNode::VirtualFolderNode(const QString &folderPath)
: FolderNode(folderPath)
{
setFilePath(folderPath);
}

ProjectNode::ProjectNode(const QString &projectFilePath)
: FolderNode(projectFilePath)
{
setFilePath(projectFilePath);
}
Loading

0 comments on commit 4432189

Please sign in to comment.