#include "CppUnitTest.h" #include #include #include "ElementRendererTest.h" #include "Renderer/Painting/ElementStyle.h" #include "Renderer/Painting/MaterialStyleFill.h" using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Renderer; namespace UnitTest { 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 toBaseStyles() const override { return { BaseStyle(std::make_shared(), std::make_shared( std::make_shared(Material(QColor(255,255,0))))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } }; TEST_CLASS(ElementRendererStokeTypeTest) { private: char* argv[1]; int argc; QPainterPath path; 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); } TEST_METHOD_INITIALIZE(initialize) { qInstallMessageHandler(messageHandler); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); } TEST_METHOD(TestBothSidesRound) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map 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(), std::make_shared(30, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } TEST_METHOD(TestBothSidesFlat) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map 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(), std::make_shared(30, StrokeType::kBothSides, StrokeEndType::kFlat, std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } TEST_METHOD(TestLeftSideRound) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map 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(), std::make_shared(30, StrokeType::kLeftSide, StrokeEndType::kRound, std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } TEST_METHOD(TestLeftSideFlat) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map 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(), std::make_shared(30, StrokeType::kLeftSide, StrokeEndType::kFlat, std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } TEST_METHOD(TestRightSideFlatRound) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map 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(), std::make_shared(80, StrokeType::kRightSide, StrokeEndType::kFlatRound, std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } }; TEST_CLASS(ElementRendererStokeMaterialTest) { private: char* argv[1]; int argc; QPainterPath path; 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); } TEST_METHOD(TestStrokePlain) { QApplication a(argc, argv); class StyleStrokePlain : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { return { BaseStyle(std::make_shared(), std::make_shared(30, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared(QColor(255,255,255),1,1))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } TEST_METHOD(TestStrokeRadialGradient1) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map 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(), std::make_shared(30, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared(materialMap, false))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } TEST_METHOD(TestStrokeRadialGradient2) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle { virtual std::vector toBaseStyles() const override { std::map materialMap = { {0.00, Material{QColor(255,255,255)}}, {0.50, Material{QColor(165,176,207)}}, {1.00, Material{QColor(58,64,151)}} }; return { BaseStyle(std::make_shared(), std::make_shared(30, StrokeType::kBothSides, StrokeEndType::kRound, std::make_shared(materialMap, true))) }; } } style; TestGLWidget w(style, path); w.show(); a.exec(); } }; }