2023-02-07 20:50:31 +08:00
|
|
|
#include "CppUnitTest.h"
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
#include <FramelessHelper/Core/private/framelessconfig_p.h>
|
2023-02-25 10:47:27 +08:00
|
|
|
#include <util/SvgFileLoader.h>
|
|
|
|
#include "Renderer/Painting/CubicBezier.h"
|
|
|
|
#include <Renderer/Painting/StraightLine.h>
|
2023-02-07 20:50:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
|
|
|
|
|
|
|
namespace UnitTest
|
|
|
|
{
|
2023-02-25 10:47:27 +08:00
|
|
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case QtInfoMsg:
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
|
|
|
|
break;
|
|
|
|
case QtDebugMsg:
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger::WriteMessage(std::format("{}({},{}) {}\n",
|
|
|
|
QString(context.file).splitRef("\\").back().toLocal8Bit().data(),
|
|
|
|
context.line,
|
|
|
|
QString(context.function).splitRef("(").first().split(" ").back().split(":").back().toLocal8Bit().data(),
|
|
|
|
msg.toStdString()).c_str());
|
|
|
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
|
|
|
}
|
2023-02-07 20:50:31 +08:00
|
|
|
TEST_CLASS(UnitTest)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_METHOD(TestMethod1)
|
|
|
|
{
|
|
|
|
FRAMELESSHELPER_USE_NAMESPACE
|
|
|
|
FramelessHelper::Core::initialize();
|
|
|
|
//QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
|
|
char arg[] = "";
|
|
|
|
char* argv[] = { arg };
|
|
|
|
int argc = 1;
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
FramelessHelper::Core::setApplicationOSThemeAware();
|
|
|
|
FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur);
|
|
|
|
FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow);
|
|
|
|
FramelessConfig::instance()->set(Global::Option::CenterWindowBeforeShow);
|
|
|
|
MainWindow w;
|
|
|
|
w.show();
|
|
|
|
a.exec();
|
|
|
|
}
|
|
|
|
};
|
2023-02-25 10:47:27 +08:00
|
|
|
|
|
|
|
TEST_CLASS(SvgLoaderTest)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_METHOD(LoadSvg)
|
|
|
|
{
|
|
|
|
qInstallMessageHandler(messageHandler);
|
|
|
|
QPainterPath painterPath;
|
|
|
|
SvgFileLoader svgloader;
|
|
|
|
svgloader.loadSvgFile("D:\\BigC\\Project\\ArchitectureColoredPainting\\svg\\test.svg", painterPath);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_CLASS(CubicBezierTest)
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_METHOD(CubicIntegral)
|
|
|
|
{
|
|
|
|
qInstallMessageHandler(messageHandler);
|
|
|
|
std::shared_ptr<Renderer::Line> line(new Renderer::CubicBezier());
|
|
|
|
line->push_back({ -1, -1 });
|
|
|
|
line->push_back({ -1, 1 });
|
|
|
|
line->push_back({ 1, 1 });
|
|
|
|
line->push_back({ 1, -1 });
|
|
|
|
vector<std::shared_ptr<Renderer::Line>> outLines;
|
|
|
|
line->monotonization(outLines);
|
|
|
|
for (auto line : outLines) {
|
|
|
|
qDebug() << line->getRate();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-07 20:50:31 +08:00
|
|
|
}
|