summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-03-03 14:05:35 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-03-11 12:12:58 +0100
commit435a48fbb40cb01c1cdb1dfe88be96118e3ef4cd (patch)
tree8a1e75cedebd3ee9e0a77984b82b5af64acffb91
parent131c25cd08290a5cd6f20fdcbe67652bca58cfc5 (diff)
Update SvgRead test - add new parameters and path parsing
Change-Id: Ic19bd2167cc359eef02648fa0ebd1d858fdeaec5 Reviewed-on: https://gerrit.libreoffice.org/68827 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 208a6896958b5281c11875b5c57806ca2daa9118)
-rw-r--r--svgio/qa/cppunit/SvgRead.cxx65
-rw-r--r--svgio/qa/cppunit/data/path.svg3
2 files changed, 56 insertions, 12 deletions
diff --git a/svgio/qa/cppunit/SvgRead.cxx b/svgio/qa/cppunit/SvgRead.cxx
index 3c7974794e1b..996be9d21f08 100644
--- a/svgio/qa/cppunit/SvgRead.cxx
+++ b/svgio/qa/cppunit/SvgRead.cxx
@@ -40,23 +40,26 @@
#include <svggnode.hxx>
#include <basegfx/DrawCommands.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
namespace
{
using namespace css;
-class Test : public test::BootstrapFixture
+class TestParsing : public test::BootstrapFixture
{
- void test();
+ void testSimpleRectangle();
+ void testPath();
uno::Reference<io::XInputStream> parseSvg(const OUString& aSource);
public:
- CPPUNIT_TEST_SUITE(Test);
- CPPUNIT_TEST(test);
+ CPPUNIT_TEST_SUITE(TestParsing);
+ CPPUNIT_TEST(testSimpleRectangle);
+ CPPUNIT_TEST(testPath);
CPPUNIT_TEST_SUITE_END();
};
-uno::Reference<io::XInputStream> Test::parseSvg(const OUString& aSource)
+uno::Reference<io::XInputStream> TestParsing::parseSvg(const OUString& aSource)
{
SvFileStream aFileStream(aSource, StreamMode::READ);
std::size_t nSize = aFileStream.remainingSize();
@@ -70,7 +73,7 @@ uno::Reference<io::XInputStream> Test::parseSvg(const OUString& aSource)
return aInputStream;
}
-void Test::test()
+void TestParsing::testSimpleRectangle()
{
OUString aSvgFile = "/svgio/qa/cppunit/data/Rect.svg";
OUString aUrl = m_directories.getURLFromSrc(aSvgFile);
@@ -84,18 +87,56 @@ void Test::test()
uno::Any aAny = xSvgParser->getDrawCommands(xStream, aPath);
CPPUNIT_ASSERT(aAny.has<sal_uInt64>());
- gfx::DrawRoot* pDrawRoot = reinterpret_cast<gfx::DrawRoot*>(aAny.get<sal_uInt64>());
+ auto* pDrawRoot = reinterpret_cast<gfx::DrawRoot*>(aAny.get<sal_uInt64>());
+
+ basegfx::B2DRange aSurfaceRectangle(0, 0, 120, 120);
CPPUNIT_ASSERT_EQUAL(size_t(1), pDrawRoot->maChildren.size());
- CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(0, 0, 120, 120), pDrawRoot->maRectangle);
+ CPPUNIT_ASSERT_EQUAL(aSurfaceRectangle, pDrawRoot->maRectangle);
+ auto* pDrawBase = pDrawRoot->maChildren[0].get();
CPPUNIT_ASSERT_EQUAL(gfx::DrawCommandType::Rectangle, pDrawRoot->maChildren[0]->getType());
- CPPUNIT_ASSERT_EQUAL(
- basegfx::B2DRange(10, 10, 110, 110),
- static_cast<gfx::DrawRectangle*>(pDrawRoot->maChildren[0].get())->maRectangle);
+ auto* pDrawRect = static_cast<gfx::DrawRectangle*>(pDrawBase);
+ CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(10, 10, 110, 110), pDrawRect->maRectangle);
+ CPPUNIT_ASSERT_EQUAL(3.0, pDrawRect->mnStrokeWidth);
+ CPPUNIT_ASSERT(bool(pDrawRect->mpStrokeColor));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0xff0000), sal_Int32(Color(*pDrawRect->mpStrokeColor)));
+ CPPUNIT_ASSERT(bool(pDrawRect->mpFillColor));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00cc00), sal_Int32(Color(*pDrawRect->mpFillColor)));
+}
+
+void TestParsing::testPath()
+{
+ OUString aSvgFile = "/svgio/qa/cppunit/data/path.svg";
+ OUString aUrl = m_directories.getURLFromSrc(aSvgFile);
+ OUString aPath = m_directories.getPathFromSrc(aSvgFile);
+
+ uno::Reference<io::XInputStream> xStream = parseSvg(aUrl);
+ CPPUNIT_ASSERT(xStream.is());
+
+ uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
+ const uno::Reference<graphic::XSvgParser> xSvgParser = graphic::SvgTools::create(xContext);
+
+ uno::Any aAny = xSvgParser->getDrawCommands(xStream, aPath);
+ CPPUNIT_ASSERT(aAny.has<sal_uInt64>());
+ auto* pDrawRoot = reinterpret_cast<gfx::DrawRoot*>(aAny.get<sal_uInt64>());
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), pDrawRoot->maChildren.size());
+
+ auto* pDrawBase = pDrawRoot->maChildren[0].get();
+ CPPUNIT_ASSERT_EQUAL(gfx::DrawCommandType::Path, pDrawBase->getType());
+ auto* pDrawPath = static_cast<gfx::DrawPath*>(pDrawBase);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("m1 1h42v24h-42v-24z"),
+ basegfx::utils::exportToSvgD(pDrawPath->maPolyPolygon, true, true, false));
+ CPPUNIT_ASSERT_EQUAL(0.0, pDrawPath->mnStrokeWidth);
+ CPPUNIT_ASSERT(bool(pDrawPath->mpStrokeColor));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0xffffff), sal_Int32(Color(*pDrawPath->mpStrokeColor)));
+ CPPUNIT_ASSERT(bool(pDrawPath->mpFillColor));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0x007aff), sal_Int32(Color(*pDrawPath->mpFillColor)));
}
-CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+CPPUNIT_TEST_SUITE_REGISTRATION(TestParsing);
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svgio/qa/cppunit/data/path.svg b/svgio/qa/cppunit/data/path.svg
new file mode 100644
index 000000000000..1722181c872e
--- /dev/null
+++ b/svgio/qa/cppunit/data/path.svg
@@ -0,0 +1,3 @@
+<svg width="44" height="26" xmlns="http://www.w3.org/2000/svg">
+ <path d="M1 1 H 43 V 25 H 1 L 1 1 Z" fill="#007aff" stroke="#fff" stroke-width="0"/>
+</svg>