stuff-from-scratch/test/web/TestSvgWriter.cpp

34 lines
934 B
C++
Raw Normal View History

2022-12-07 20:58:45 +00:00
#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));
SvgWriter writer;
auto content = writer.toString(document.get());
auto outFile = std::make_unique<File>(TestUtils::getTestOutputDir(__FILE__) / "test_out.svg");
outFile->writeText(content);
}