stuff-from-scratch/test/web/TestSvgWriter.cpp
2022-12-08 08:48:18 +00:00

38 lines
1.1 KiB
C++

#include "SvgWriter.h"
#include "SvgDocument.h"
#include "SvgShapeElements.h"
#include "File.h"
#include "TestFramework.h"
#include "TestUtils.h"
TEST_CASE(TestSvgWriter, "web")
{
auto document = std::make_unique<SvgDocument>();
document->setViewBox(0, 0, 100, 100);
auto circle = std::make_unique<SvgCircle>();
circle->setRadius(20);
circle->setLocation({10, 30});
circle->setFill({255, 0, 0});
document->getRoot()->addChild(std::move(circle));
auto rectangle = std::make_unique<SvgRectangle>();
rectangle->setLocation({50, 70});
rectangle->setWidth(5);
rectangle->setHeight(10);
rectangle->setFill({0, 0, 255});
document->getRoot()->addChild(std::move(rectangle));
auto triangle = std::make_unique<SvgPolygon>();
triangle->setPoints({{10, 10}, {50, 10}, {30, 20}});
triangle->setFill({0, 255, 0});
document->getRoot()->addChild(std::move(triangle));
SvgWriter writer;
auto content = writer.toString(document.get());
auto outFile = std::make_unique<File>(TestUtils::getTestOutputDir(__FILE__) / "test_out.svg");
outFile->writeText(content);
}