Skip to content

Commit

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

Log: unit test plugin
  • Loading branch information
Kakueeen authored Jan 16, 2025
1 parent 4b5fd4a commit c666401
Show file tree
Hide file tree
Showing 66 changed files with 4,437 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/base/ai/abstractllm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "abstractllm.h"

AbstractLLM::AbstractLLM(QObject *parent)
: QObject(parent)
: QObject(parent)
{
qRegisterMetaType<ResponseState>("ResponseState");
}
Expand Down
85 changes: 85 additions & 0 deletions src/common/util/spinnerpainter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "spinnerpainter.h"

#include <QtMath>
#include <QPainterPath>

SpinnerPainter::SpinnerPainter()
{
refreshTimer.setInterval(30);
QObject::connect(&refreshTimer, &QTimer::timeout, &refreshTimer,
[=]() {
currentDegree += 14;
callback();
});
}

void SpinnerPainter::paint(QPainter &painter, const QColor &color, const QRect &rect)
{
painter.save();
if (currentColor != color) {
currentColor = color;
indicatorColors.clear();
}

if (indicatorColors.isEmpty()) {
for (int i = 0; i < 3; ++i)
indicatorColors << createDefaultIndicatorColorList(color);
}

painter.setRenderHints(QPainter::Antialiasing);
auto center = QRectF(rect).center();
auto radius = qMin(rect.width(), rect.height()) / 2.0;
auto indicatorRadius = radius / 2 / 2 * 1.1;
auto indicatorDegreeDelta = 360 / indicatorColors.count();

for (int i = 0; i < indicatorColors.count(); ++i) {
auto colors = indicatorColors.value(i);
for (int j = 0; j < colors.count(); ++j) {
double degreeCurrent = currentDegree - j * indicatorShadowOffset + indicatorDegreeDelta * i;
auto x = (radius - indicatorRadius) * qCos(qDegreesToRadians(degreeCurrent));
auto y = (radius - indicatorRadius) * qSin(qDegreesToRadians(degreeCurrent));

x = center.x() + x;
y = center.y() + y;
auto tl = QPointF(x - 1 * indicatorRadius, y - 1 * indicatorRadius);
QRectF rf(tl.x(), tl.y(), indicatorRadius * 2, indicatorRadius * 2);

QPainterPath path;
path.addEllipse(rf);

painter.fillPath(path, colors.value(j));
}
}
painter.restore();
}

void SpinnerPainter::setUpdateCallback(const UpdateCallback &cb)
{
callback = cb;
}

void SpinnerPainter::startAnimation()
{
refreshTimer.start();
}

void SpinnerPainter::stopAnimation()
{
refreshTimer.stop();
}

QList<QColor> SpinnerPainter::createDefaultIndicatorColorList(QColor color)
{
QList<QColor> colors;
QList<int> opacitys;
opacitys << 100 << 30 << 15 << 10 << 5 << 4 << 3 << 2 << 1;
for (int i = 0; i < opacitys.count(); ++i) {
color.setAlpha(255 * opacitys.value(i) / 100);
colors << color;
}
return colors;
}
40 changes: 40 additions & 0 deletions src/common/util/spinnerpainter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef SPINNERPAINTER_H
#define SPINNERPAINTER_H

#include <QPainter>
#include <QTimer>

#include <functional>

class SpinnerPainter
{
public:
SpinnerPainter();

void paint(QPainter &painter, const QColor &color, const QRect &rect);

using UpdateCallback = std::function<void()>;
void setUpdateCallback(const UpdateCallback &cb);

void startAnimation();
void stopAnimation();

protected:
QList<QColor> createDefaultIndicatorColorList(QColor color);

private:
QTimer refreshTimer;

double indicatorShadowOffset = 10;
double currentDegree = 0.0;

QList<QList<QColor>> indicatorColors;
QColor currentColor;
UpdateCallback callback;
};

#endif // SPINNERPAINTER_H
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)
8 changes: 4 additions & 4 deletions src/plugins/aimanager/openai/openaicompatiblellm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class OpenAiCompatibleLLMPrivate
QString modelPath { "" };
QString apiKey { "" };
double temprature { 1.0 };
int maxTokens = 0; // default not set
int maxTokens = 0; // default not set
bool stream { true };

QByteArray httpResult {};
Expand All @@ -70,7 +70,7 @@ class OpenAiCompatibleLLMPrivate
};

OpenAiCompatibleLLMPrivate::OpenAiCompatibleLLMPrivate(OpenAiCompatibleLLM *qq)
: q(qq)
: q(qq)
{
manager = new QNetworkAccessManager(qq);
currentConversation = new OpenAiCompatibleConversation();
Expand All @@ -90,7 +90,7 @@ QNetworkReply *OpenAiCompatibleLLMPrivate::postMessage(const QString &url, const
request.setRawHeader("Authorization", "Bearer " + apiKey.toUtf8());

if (QThread::currentThread() != qApp->thread()) {
QNetworkAccessManager* threadManager(new QNetworkAccessManager);
QNetworkAccessManager *threadManager(new QNetworkAccessManager);
OpenAiCompatibleLLM::connect(QThread::currentThread(), &QThread::finished, threadManager, &QNetworkAccessManager::deleteLater);
return threadManager->post(request, body);
}
Expand All @@ -105,7 +105,7 @@ QNetworkReply *OpenAiCompatibleLLMPrivate::getMessage(const QString &url, const
request.setRawHeader("Authorization", "Bearer " + apiKey.toUtf8());

if (QThread::currentThread() != qApp->thread()) {
QNetworkAccessManager* threadManager(new QNetworkAccessManager);
QNetworkAccessManager *threadManager(new QNetworkAccessManager);
OpenAiCompatibleLLM::connect(QThread::currentThread(), &QThread::finished, threadManager, &QNetworkAccessManager::deleteLater);
return threadManager->get(request);
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/aimanager/openai/openaicompatiblellm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OpenAiCompatibleLLM : public AbstractLLM
explicit OpenAiCompatibleLLM(QObject *parent = nullptr);
~OpenAiCompatibleLLM() override;

Conversation* getCurrentConversation() override;
Conversation *getCurrentConversation() override;
void setModelName(const QString &modelName);
void setModelPath(const QString &path);
void setApiKey(const QString &apiKey);
Expand All @@ -24,9 +24,9 @@ class OpenAiCompatibleLLM : public AbstractLLM
QString modelPath() const override;
bool checkValid(QString *errStr) override;
QJsonObject create(const Conversation &conversation) override;
void request(const QJsonObject &data) override; // chat/compltions
void request(const QJsonObject &data) override; // chat/compltions
void request(const QString &prompt, ResponseHandler handler = nullptr) override;
void generate(const QString &prefix, const QString &suffix) override; // api/generate
void generate(const QString &prefix, const QString &suffix) override; // api/generate
void setTemperature(double temperature) override;
void setStream(bool isStream) override;
void setLocale(Locale lc) override;
Expand All @@ -40,4 +40,4 @@ class OpenAiCompatibleLLM : public AbstractLLM
OpenAiCompatibleLLMPrivate *d;
};

#endif // OPENAICOMPATIBLELLM_H
#endif // OPENAICOMPATIBLELLM_H
44 changes: 10 additions & 34 deletions src/plugins/builder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,19 @@ cmake_minimum_required(VERSION 3.0.2)

project(buildercore)

set(CXX_CPP
tasks/taskmodel.cpp
tasks/taskmanager.cpp
tasks/taskdelegate.cpp
tasks/taskview.cpp
tasks/taskfilterproxymodel.cpp
transceiver/builderreceiver.cpp
transceiver/buildersender.cpp
mainframe/buildmanager.cpp
mainframe/compileoutputpane.cpp
mainframe/problemoutputpane.cpp
mainframe/commonparser.cpp
buildercore.cpp
buildercore.json
)

set(CXX_H
tasks/taskmodel.h
tasks/taskmanager.h
tasks/taskdelegate.h
tasks/taskview.h
tasks/taskfilterproxymodel.h
transceiver/builderreceiver.h
transceiver/buildersender.h
mainframe/buildmanager.h
mainframe/compileoutputpane.h
mainframe/problemoutputpane.h
mainframe/commonparser.h
buildercore.h
)
FILE(GLOB SRC_FILES
"${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
${CXX_H}
${CXX_CPP}
${SRC_FILES}
builder.qrc
)
)

target_link_libraries(${PROJECT_NAME}
duc-framework
Expand All @@ -47,7 +23,7 @@ target_link_libraries(${PROJECT_NAME}
duc-common
${QtUseModules}
${PkgUserModules}
)
)

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

1 change: 0 additions & 1 deletion src/plugins/builder/buildercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ dpf::Plugin::ShutdownFlag BuilderCore::stop()
{
return Sync;
}

16 changes: 16 additions & 0 deletions src/plugins/builder/mainframe/buildmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "compileoutputpane.h"
#include "tasks/taskmodel.h"
#include "common/util/utils.h"
#include "settingdialog.h"

#include "services/builder/builderservice.h"
#include "services/editor/editorservice.h"
Expand Down Expand Up @@ -179,12 +180,20 @@ void BuildManager::initIssueList()
filterButton->setContentsMargins(0, 0, 0, 0);
filterButton->setToolTip(tr("Filter"));

DToolButton *settingButton = new DToolButton(d->compileWidget);
settingButton->setFixedSize(26, 26);
settingButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
settingButton->setIcon(QIcon::fromTheme("settings"));
settingButton->setContentsMargins(0, 0, 0, 0);
settingButton->setToolTip(tr("Settings"));

DFrame *issueTopWidget = new DFrame(d->compileWidget);
DStyle::setFrameRadius(issueTopWidget, 0);
issueTopWidget->setLineWidth(0);
issueTopWidget->setFixedHeight(36);
QHBoxLayout *hIssueTopLayout = new QHBoxLayout(issueTopWidget);
hIssueTopLayout->addWidget(issusListText);
hIssueTopLayout->addWidget(settingButton);
hIssueTopLayout->addWidget(filterButton);
hIssueTopLayout->setSpacing(0);
hIssueTopLayout->setContentsMargins(0, 0, 5, 0);
Expand Down Expand Up @@ -236,6 +245,7 @@ void BuildManager::initIssueList()
QPoint menuPos = buttonPos + QPoint(0, 5);
filterMenu->popup(menuPos);
});
connect(settingButton, &DToolButton::clicked, this, &BuildManager::showSettingDialog);
}

void BuildManager::initCompileOutput()
Expand Down Expand Up @@ -408,6 +418,12 @@ void BuildManager::slotResetBuildUI()
uiController.switchContext(tr("&Build"));
}

void BuildManager::showSettingDialog()
{
SettingDialog dlg;
dlg.exec();
}

void BuildManager::setActivatedProjectInfo(const QString &kitName, const QString &workingDir)
{
d->activedKitName = kitName;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/builder/mainframe/buildmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public slots:
void slotBuildState(const BuildState &buildstate);
void slotOutputNotify(const BuildState &state, const BuildCommandInfo &commandInfo);
void slotResetBuildUI();
void showSettingDialog();

private:
explicit BuildManager(QObject *parent = nullptr);
Expand Down
27 changes: 1 addition & 26 deletions src/plugins/builder/mainframe/problemoutputpane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <QVBoxLayout>

ProblemOutputPane::ProblemOutputPane(QWidget *parent)
: DWidget (parent)
: DWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
Expand All @@ -20,7 +20,6 @@ ProblemOutputPane::ProblemOutputPane(QWidget *parent)

ProblemOutputPane::~ProblemOutputPane()
{

}

void ProblemOutputPane::clearContents()
Expand All @@ -37,27 +36,3 @@ void ProblemOutputPane::showSpecificTasks(ShowType type)
{
TaskManager::instance()->showSpecificTasks(type);
}

void ProblemOutputPane::contextMenuEvent(QContextMenuEvent * event)
{
if (nullptr == menu) {
menu = new DMenu(this);
menu->setParent(this);
menu->addActions(actionFactory());
}

menu->move(event->globalX(), event->globalY());
menu->exec();
}

QList<QAction*> ProblemOutputPane::actionFactory()
{
QList<QAction*> list;
auto action = new QAction(this);
action->setText(tr("Clear"));
connect(action, &QAction::triggered, [this](){
clearContents();
});
list.append(action);
return list;
}
10 changes: 1 addition & 9 deletions src/plugins/builder/mainframe/problemoutputpane.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "tasks/taskmodel.h"

#include <DWidget>
#include <DMenu>

DWIDGET_USE_NAMESPACE

Expand All @@ -23,13 +22,6 @@ class ProblemOutputPane : public DWidget
void clearContents();
void addTask(const Task &task, int linkedOutputLines, int skipLines);
void showSpecificTasks(ShowType type);

protected:
void contextMenuEvent(QContextMenuEvent * event) override;

private:
QList<QAction*> actionFactory();
DMenu *menu = nullptr;
};

#endif // PROBLEMOUTPUTPANE_H
#endif // PROBLEMOUTPUTPANE_H
Loading

0 comments on commit c666401

Please sign in to comment.