2023-02-07 20:50:31 +08:00
|
|
|
#include "CppUnitTest.h"
|
2023-03-07 16:24:38 +08:00
|
|
|
//#include "MainWindow.h"
|
2023-02-07 20:50:31 +08:00
|
|
|
#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-03-07 16:24:38 +08:00
|
|
|
#include <ElementPoolWidget.h>
|
2023-03-15 11:23:26 +08:00
|
|
|
#include <util/PaintingUtil.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:
|
2023-03-07 16:24:38 +08:00
|
|
|
//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-07 20:50:31 +08:00
|
|
|
};
|
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-03-07 16:24:38 +08:00
|
|
|
TEST_CLASS(ElementPoolTest)
|
|
|
|
{
|
2023-03-07 16:53:03 +08:00
|
|
|
private:
|
|
|
|
char* argv[1];
|
|
|
|
int argc;
|
2023-03-07 16:24:38 +08:00
|
|
|
public:
|
2023-03-07 16:53:03 +08:00
|
|
|
ElementPoolTest() :argv{ (char*)"" }, argc(1) {}
|
|
|
|
|
|
|
|
TEST_METHOD_INITIALIZE(initialize)
|
|
|
|
{
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
|
|
}
|
2023-03-07 16:24:38 +08:00
|
|
|
TEST_METHOD(ElementPool) {
|
2023-03-07 16:53:03 +08:00
|
|
|
QApplication a(argc, argv);
|
2023-03-07 16:24:38 +08:00
|
|
|
qInstallMessageHandler(messageHandler);
|
|
|
|
ElementPoolWidget wi;
|
2023-03-07 16:54:19 +08:00
|
|
|
//wi.setElementList({"1", "2", "3"});
|
2023-03-07 16:53:03 +08:00
|
|
|
wi.setFixedSize(QSize(600, 800));
|
2023-03-07 16:24:38 +08:00
|
|
|
wi.show();
|
2023-03-07 16:53:03 +08:00
|
|
|
a.exec();
|
2023-03-07 16:24:38 +08:00
|
|
|
}
|
|
|
|
};
|
2023-03-15 11:23:26 +08:00
|
|
|
TEST_CLASS(PaintingUtilTest)
|
|
|
|
{
|
2023-03-20 17:48:18 +08:00
|
|
|
|
2023-03-15 11:23:26 +08:00
|
|
|
};
|
2023-02-07 20:50:31 +08:00
|
|
|
}
|