ArchitectureColoredPainting/UnitTest/ElementRendererTest.cpp

283 lines
9.4 KiB
C++
Raw Permalink Normal View History

2023-02-08 16:34:16 +08:00
#include "CppUnitTest.h"
#include <QGuiApplication>
#include <QtWidgets/QApplication>
#include "ElementRendererTest.h"
2023-02-10 13:48:30 +08:00
#include "Renderer/Painting/ElementStyle.h"
#include "Renderer/Painting/MaterialStyleFill.h"
2023-02-08 16:34:16 +08:00
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
2023-02-10 13:48:30 +08:00
using namespace Renderer;
2023-02-08 16:34:16 +08:00
namespace UnitTest
{
2023-03-14 23:39:56 +08:00
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);
TEST_CLASS(ElementRendererFillTest)
{
private:
char* argv[1];
int argc;
QPainterPath path;
public:
ElementRendererFillTest() :argv{ (char*)"" }, argc(1)
{
QQuickSvgParser::parsePathDataFast("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z",
path);
QTransform transform;
//transform.scale(10, 10);
path = transform.map(path);
}
TEST_METHOD_INITIALIZE(initialize)
{
qInstallMessageHandler(messageHandler);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
}
TEST_METHOD(TestFillPlain)
{
QApplication a(argc, argv);
class Style : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
2023-03-20 17:48:18 +08:00
return { BaseStyle(std::make_shared<TransformStyle>(),
std::make_shared<MaterialStyleFill>(std::make_shared<FillPlain>(Material(QColor(255,255,0))))) };
}
} style;
TestGLWidget w(style, path);
w.show();
a.exec();
}
TEST_METHOD(TestFillPlainAndStrokeRadialGradient)
{
QApplication a(argc, argv);
class Style : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
std::make_shared<MaterialStyleFill>(
2023-03-20 17:48:18 +08:00
std::make_shared<FillPlain>(Material(QColor(255,255,0))))),
BaseStyle(std::make_shared<TransformStyle>(),
std::make_shared<MaterialStyleStroke>(10, StrokeType::kBothSides, StrokeEndType::kRound,
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
w.show();
a.exec();
}
};
2023-02-15 15:37:30 +08:00
TEST_CLASS(ElementRendererStokeTypeTest)
{
2023-03-07 16:22:44 +08:00
private:
char* argv[1];
int argc;
QPainterPath path;
2023-02-15 15:37:30 +08:00
public:
ElementRendererStokeTypeTest() :argv{ (char*)"" }, argc(1)
{
QQuickSvgParser::parsePathDataFast("M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15", path);
QTransform transform;
transform.scale(10, 10);
path = transform.map(path);
}
2023-03-07 16:22:44 +08:00
TEST_METHOD_INITIALIZE(initialize)
2023-02-15 15:37:30 +08:00
{
2023-03-14 23:39:56 +08:00
qInstallMessageHandler(messageHandler);
2023-02-15 15:37:30 +08:00
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
2023-03-07 16:22:44 +08:00
}
TEST_METHOD(TestBothSidesRound)
{
2023-02-15 15:37:30 +08:00
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kBothSides, StrokeEndType::kRound,
2023-02-15 15:37:30 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
2023-02-15 15:37:30 +08:00
w.show();
a.exec();
}
TEST_METHOD(TestBothSidesFlat)
{
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kBothSides, StrokeEndType::kFlat,
2023-02-15 15:37:30 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
2023-02-15 15:37:30 +08:00
w.show();
a.exec();
}
TEST_METHOD(TestLeftSideRound)
{
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kLeftSide, StrokeEndType::kRound,
2023-02-15 15:37:30 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
2023-02-15 15:37:30 +08:00
w.show();
a.exec();
}
TEST_METHOD(TestLeftSideFlat)
{
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kLeftSide, StrokeEndType::kFlat,
2023-02-15 15:37:30 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
2023-02-15 15:37:30 +08:00
w.show();
a.exec();
}
2023-03-15 00:09:30 +08:00
TEST_METHOD(TestRightSideFlatRound)
2023-03-14 22:44:23 +08:00
{
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(80, StrokeType::kRightSide, StrokeEndType::kFlatRound,
2023-03-14 22:44:23 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
2023-03-14 22:44:23 +08:00
w.show();
a.exec();
}
2023-02-15 15:37:30 +08:00
};
TEST_CLASS(ElementRendererStokeMaterialTest)
2023-02-10 13:48:30 +08:00
{
2023-03-07 16:22:44 +08:00
private:
char* argv[1];
int argc;
QPainterPath path;
2023-02-10 13:48:30 +08:00
public:
ElementRendererStokeMaterialTest() :argv{ (char*)"" }, argc(1)
{
QQuickSvgParser::parsePathDataFast("M292.82,107.78s0,0,0,0,0,3.59,0,7.62c0,3.85,0,5.78.06,6.43a19.94,19.94,0,0,0,2.87,7.58,15.85,15.85,0,0,0,6.61,6.23A14.75,14.75,0,0,0,310,137a11.69,11.69,0,0,0,7.59-2.92,11,11,0,0,0,3.2-6.84c.15-1.27.58-4.84-1.79-7.64a8.54,8.54,0,0,0-3.56-2.44c-1.32-.52-3.32-1.31-5.06-.33a5.41,5.41,0,0,0-2.14,3,3.48,3.48,0,0,0-.16,2.71c.78,1.86,3.36,2.14,3.47,2.15", path);
QTransform transform;
transform.scale(10, 10);
path = transform.map(path);
}
2023-02-10 13:48:30 +08:00
TEST_METHOD(TestStrokePlain)
{
QApplication a(argc, argv);
2023-02-15 15:37:30 +08:00
class StyleStrokePlain : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kBothSides, StrokeEndType::kRound,
2023-02-15 15:37:30 +08:00
std::make_shared<StrokePlain>(QColor(255,255,255),1,1))) };
}
} style;
TestGLWidget w(style, path);
2023-02-10 13:48:30 +08:00
w.show();
a.exec();
}
TEST_METHOD(TestStrokeRadialGradient1)
{
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
2023-02-15 15:37:30 +08:00
std::map<float, Material> materialMap = {
{0.20, Material{QColor(255,255,255)}},
{0.60, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
2023-02-10 13:48:30 +08:00
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-03-16 14:48:28 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kBothSides, StrokeEndType::kRound,
2023-02-10 13:48:30 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, false))) };
}
} style;
TestGLWidget w(style, path);
2023-02-10 13:48:30 +08:00
w.show();
a.exec();
}
TEST_METHOD(TestStrokeRadialGradient2)
{
QApplication a(argc, argv);
class StyleStrokeRadialGradient : public Renderer::ElementStyle
{
virtual std::vector<Renderer::BaseStyle> toBaseStyles() const override
{
std::map<float, Material> materialMap = {
2023-02-15 15:37:30 +08:00
{0.00, Material{QColor(255,255,255)}},
{0.50, Material{QColor(165,176,207)}},
{1.00, Material{QColor(58,64,151)}}
2023-02-10 13:48:30 +08:00
};
return { BaseStyle(std::make_shared<TransformStyle>(),
2023-02-15 15:37:30 +08:00
std::make_shared<MaterialStyleStroke>(30, StrokeType::kBothSides, StrokeEndType::kRound,
2023-02-10 13:48:30 +08:00
std::make_shared<StrokeRadialGradient>(materialMap, true))) };
}
} style;
TestGLWidget w(style, path);
2023-02-10 13:48:30 +08:00
w.show();
a.exec();
}
};
2023-02-08 16:34:16 +08:00
}