ArchitectureColoredPainting/UnitTest/StyleTest.cpp

54 lines
2.0 KiB
C++
Raw Permalink Normal View History

2023-03-16 14:48:28 +08:00
#include "CppUnitTest.h"
#include <QGuiApplication>
#include <QtWidgets/QApplication>
#include "Renderer/Painting/ElementStyle.h"
#include <Renderer/Painting/MaterialStyleStroke.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace Renderer;
namespace UnitTest
{
TEST_CLASS(StyleTest)
{
public:
TEST_METHOD(TestEncodeDecode)
{
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)}}
};
auto style = std::make_unique<MaterialStyleStroke>(
30, StrokeType::kBothSides, StrokeEndType::kRound,
std::make_shared<StrokeRadialGradient>(materialMap, false)
);
/* auto style = std::make_shared<MaterialStyleStroke>(
30, StrokeType::kBothSides, StrokeEndType::kRound,
std::make_shared<StrokePlain>(Material(QColor(255, 255, 255)))
);*/
std::shared_ptr<MaterialStyle> decoded = MaterialStyle::decoded(style->encoded());
/* Assert::IsTrue(decoded->type() == MaterialStyleType::kStroke);
Assert::IsTrue(std::static_pointer_cast<MaterialStyleStroke>(decoded)->halfWidth == 30);
Assert::IsTrue(std::static_pointer_cast<MaterialStyleStroke>(decoded)->strokeType == StrokeType::kBothSides);
Assert::IsTrue(std::static_pointer_cast<MaterialStyleStroke>(decoded)->endType == StrokeEndType::kRound);
std::shared_ptr<MaterialStroke> materialStroke = std::static_pointer_cast<MaterialStyleStroke>(decoded)->materialStroke;
Assert::IsTrue(materialStroke->type() == MaterialStrokeType::kPlain);
Material material = std::static_pointer_cast<StrokePlain>(materialStroke)->material;
Assert::IsTrue(material == Material(QColor(255, 255, 255)));
Logger::WriteMessage(std::format("({} {} {} {}), ({} {})\n",
material.color.red(),
material.color.green(),
material.color.blue(),
material.color.alpha(),
material.metallic,
material.roughness
).c_str());*/
Assert::IsTrue(*style == *decoded);
}
};
}