/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { using namespace css; class Test : public test::BootstrapFixture { void test(); uno::Reference parseSvg(const OUString& aSource); public: CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST(test); CPPUNIT_TEST_SUITE_END(); }; uno::Reference Test::parseSvg(const OUString& aSource) { SvFileStream aFileStream(aSource, StreamMode::READ); std::size_t nSize = aFileStream.remainingSize(); std::unique_ptr pBuffer(new sal_Int8[nSize + 1]); aFileStream.ReadBytes(pBuffer.get(), nSize); pBuffer[nSize] = 0; uno::Sequence aData(pBuffer.get(), nSize + 1); uno::Reference aInputStream(new comphelper::SequenceInputStream(aData)); return aInputStream; } void Test::test() { OUString aSvgFile = "/svgio/qa/cppunit/data/Rect.svg"; OUString aUrl = m_directories.getURLFromSrc(aSvgFile); OUString aPath = m_directories.getPathFromSrc(aSvgFile); uno::Reference xStream = parseSvg(aUrl); CPPUNIT_ASSERT(xStream.is()); uno::Reference xContext(comphelper::getProcessComponentContext()); const uno::Reference xSvgParser = graphic::SvgTools::create(xContext); uno::Any aAny = xSvgParser->getDrawCommands(xStream, aPath); CPPUNIT_ASSERT(aAny.has()); DrawRoot* pDrawRoot = reinterpret_cast(aAny.get()); CPPUNIT_ASSERT_EQUAL(size_t(1), pDrawRoot->maChildren.size()); CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(0, 0, 120, 120), pDrawRoot->maRectangle); CPPUNIT_ASSERT_EQUAL(DrawCommandType::Rectangle, pDrawRoot->maChildren[0]->getType()); CPPUNIT_ASSERT_EQUAL(basegfx::B2DRange(10, 10, 110, 110), static_cast(pDrawRoot->maChildren[0].get())->maRectangle); } CPPUNIT_TEST_SUITE_REGISTRATION(Test); } CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */