Remove XmlWriter in test module and use tools::XmlWriter
Change-Id: I0a0e07a6a71ed95d783d35b7d94b857074ec3450 Reviewed-on: https://gerrit.libreoffice.org/47523 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
committed by
Tomaž Vajngerl
parent
27da558d7c
commit
e1fb3d95ac
@@ -12,20 +12,20 @@
|
|||||||
|
|
||||||
#include <sal/config.h>
|
#include <sal/config.h>
|
||||||
#include <test/testdllapi.hxx>
|
#include <test/testdllapi.hxx>
|
||||||
|
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <vcl/gdimtf.hxx>
|
#include <vcl/gdimtf.hxx>
|
||||||
#include <vcl/metaactiontypes.hxx>
|
#include <vcl/metaactiontypes.hxx>
|
||||||
#include <o3tl/enumarray.hxx>
|
#include <o3tl/enumarray.hxx>
|
||||||
|
|
||||||
class XmlWriter;
|
namespace tools { class XmlWriter; }
|
||||||
|
|
||||||
enum class MetaActionType;
|
enum class MetaActionType;
|
||||||
|
|
||||||
class OOO_DLLPUBLIC_TEST MetafileXmlDump final
|
class OOO_DLLPUBLIC_TEST MetafileXmlDump final
|
||||||
{
|
{
|
||||||
o3tl::enumarray<MetaActionType, bool> maFilter;
|
o3tl::enumarray<MetaActionType, bool> maFilter;
|
||||||
|
|
||||||
void writeXml(const GDIMetaFile& rMetaFile, XmlWriter& rWriter);
|
void writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& rWriter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MetafileXmlDump();
|
MetafileXmlDump();
|
||||||
|
@@ -12,18 +12,17 @@
|
|||||||
|
|
||||||
#include <sal/config.h>
|
#include <sal/config.h>
|
||||||
#include <test/testdllapi.hxx>
|
#include <test/testdllapi.hxx>
|
||||||
#include <test/xmlwriter.hxx>
|
|
||||||
|
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
|
#include <drawinglayer/primitive2d/baseprimitive2d.hxx>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace tools { class XmlWriter; }
|
||||||
|
|
||||||
class OOO_DLLPUBLIC_TEST Primitive2dXmlDump final
|
class OOO_DLLPUBLIC_TEST Primitive2dXmlDump final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<bool> maFilter;
|
std::vector<bool> maFilter;
|
||||||
void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, XmlWriter& rWriter);
|
void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, tools::XmlWriter& rWriter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Primitive2dXmlDump();
|
Primitive2dXmlDump();
|
||||||
|
@@ -1,49 +0,0 @@
|
|||||||
/* -*- 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/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef INCLUDED_TEST_XMLWRITER_HXX
|
|
||||||
#define INCLUDED_TEST_XMLWRITER_HXX
|
|
||||||
|
|
||||||
#include <test/testdllapi.hxx>
|
|
||||||
|
|
||||||
#include <libxml/xmlwriter.h>
|
|
||||||
#include <rtl/ustring.hxx>
|
|
||||||
#include <rtl/string.hxx>
|
|
||||||
|
|
||||||
class SvStream;
|
|
||||||
|
|
||||||
class OOO_DLLPUBLIC_TEST XmlWriter final
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
SvStream* mpStream;
|
|
||||||
xmlTextWriterPtr mpWriter;
|
|
||||||
|
|
||||||
public:
|
|
||||||
XmlWriter(SvStream* pStream);
|
|
||||||
~XmlWriter();
|
|
||||||
|
|
||||||
void startDocument();
|
|
||||||
void endDocument();
|
|
||||||
|
|
||||||
void element(const OString& sTagName);
|
|
||||||
|
|
||||||
void startElement(const OString& sTagName);
|
|
||||||
void endElement();
|
|
||||||
|
|
||||||
void attribute(const OString& sTagName, const OString& aValue);
|
|
||||||
void attribute(const OString& sTagName, const OUString& aValue);
|
|
||||||
void attribute(const OString& sTagName, sal_Int32 aNumber);
|
|
||||||
|
|
||||||
void content(const OString& aValue);
|
|
||||||
void content(const OUString& aValue);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // INCLUDED_TEST_XMLWRITER_HXX
|
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
|
@@ -49,6 +49,8 @@ public:
|
|||||||
|
|
||||||
void content(const OString& sValue);
|
void content(const OString& sValue);
|
||||||
void content(const OUString& sValue);
|
void content(const OUString& sValue);
|
||||||
|
|
||||||
|
void element(const OString& sName);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end tools namespace
|
} // end tools namespace
|
||||||
|
@@ -45,7 +45,6 @@ $(eval $(call gb_Library_add_exception_objects,test,\
|
|||||||
test/source/xmltesttools \
|
test/source/xmltesttools \
|
||||||
test/source/htmltesttools \
|
test/source/htmltesttools \
|
||||||
test/source/mtfxmldump \
|
test/source/mtfxmldump \
|
||||||
test/source/xmlwriter \
|
|
||||||
test/source/primitive2dxmldump \
|
test/source/primitive2dxmldump \
|
||||||
test/source/screenshot_test \
|
test/source/screenshot_test \
|
||||||
))
|
))
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include <test/mtfxmldump.hxx>
|
#include <test/mtfxmldump.hxx>
|
||||||
#include <test/xmltesttools.hxx>
|
#include <test/xmltesttools.hxx>
|
||||||
#include <test/xmlwriter.hxx>
|
#include <tools/XmlWriter.hxx>
|
||||||
|
|
||||||
#include <vcl/metaact.hxx>
|
#include <vcl/metaact.hxx>
|
||||||
#include <rtl/string.hxx>
|
#include <rtl/string.hxx>
|
||||||
@@ -350,31 +350,31 @@ OUString hex32(sal_uInt32 nNumber)
|
|||||||
return OUString::createFromAscii(ss.str().c_str());
|
return OUString::createFromAscii(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writePoint(XmlWriter& rWriter, Point const& rPoint)
|
void writePoint(tools::XmlWriter& rWriter, Point const& rPoint)
|
||||||
{
|
{
|
||||||
rWriter.attribute("x", rPoint.X());
|
rWriter.attribute("x", rPoint.X());
|
||||||
rWriter.attribute("y", rPoint.Y());
|
rWriter.attribute("y", rPoint.Y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeStartPoint(XmlWriter& rWriter, Point const& rPoint)
|
void writeStartPoint(tools::XmlWriter& rWriter, Point const& rPoint)
|
||||||
{
|
{
|
||||||
rWriter.attribute("startx", rPoint.X());
|
rWriter.attribute("startx", rPoint.X());
|
||||||
rWriter.attribute("starty", rPoint.Y());
|
rWriter.attribute("starty", rPoint.Y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeEndPoint(XmlWriter& rWriter, Point const& rPoint)
|
void writeEndPoint(tools::XmlWriter& rWriter, Point const& rPoint)
|
||||||
{
|
{
|
||||||
rWriter.attribute("endx", rPoint.X());
|
rWriter.attribute("endx", rPoint.X());
|
||||||
rWriter.attribute("endy", rPoint.Y());
|
rWriter.attribute("endy", rPoint.Y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeSize(XmlWriter& rWriter, Size const& rSize)
|
void writeSize(tools::XmlWriter& rWriter, Size const& rSize)
|
||||||
{
|
{
|
||||||
rWriter.attribute("width", rSize.Width());
|
rWriter.attribute("width", rSize.Width());
|
||||||
rWriter.attribute("height", rSize.Height());
|
rWriter.attribute("height", rSize.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRectangle(XmlWriter& rWriter, tools::Rectangle const& rRectangle)
|
void writeRectangle(tools::XmlWriter& rWriter, tools::Rectangle const& rRectangle)
|
||||||
{
|
{
|
||||||
rWriter.attribute("left", rRectangle.Left());
|
rWriter.attribute("left", rRectangle.Left());
|
||||||
rWriter.attribute("top", rRectangle.Top());
|
rWriter.attribute("top", rRectangle.Top());
|
||||||
@@ -382,7 +382,7 @@ void writeRectangle(XmlWriter& rWriter, tools::Rectangle const& rRectangle)
|
|||||||
rWriter.attribute("bottom", rRectangle.Bottom());
|
rWriter.attribute("bottom", rRectangle.Bottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeLineInfo(XmlWriter& rWriter, LineInfo const& rLineInfo)
|
void writeLineInfo(tools::XmlWriter& rWriter, LineInfo const& rLineInfo)
|
||||||
{
|
{
|
||||||
rWriter.attribute("style", convertLineStyleToString(rLineInfo.GetStyle()));
|
rWriter.attribute("style", convertLineStyleToString(rLineInfo.GetStyle()));
|
||||||
rWriter.attribute("width", rLineInfo.GetWidth());
|
rWriter.attribute("width", rLineInfo.GetWidth());
|
||||||
@@ -424,7 +424,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(const GDIMetaFile& rMetaFile, const OUSt
|
|||||||
else
|
else
|
||||||
pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
|
pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
|
||||||
|
|
||||||
XmlWriter aWriter(pStream.get());
|
tools::XmlWriter aWriter(pStream.get());
|
||||||
aWriter.startDocument();
|
aWriter.startDocument();
|
||||||
aWriter.startElement("metafile");
|
aWriter.startElement("metafile");
|
||||||
|
|
||||||
@@ -440,7 +440,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(const GDIMetaFile& rMetaFile, const OUSt
|
|||||||
return pDoc;
|
return pDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, XmlWriter& rWriter)
|
void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& rWriter)
|
||||||
{
|
{
|
||||||
for(size_t nAction = 0; nAction < rMetaFile.GetActionSize(); ++nAction)
|
for(size_t nAction = 0; nAction < rMetaFile.GetActionSize(); ++nAction)
|
||||||
{
|
{
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <test/primitive2dxmldump.hxx>
|
#include <test/primitive2dxmldump.hxx>
|
||||||
#include <test/xmltesttools.hxx>
|
#include <test/xmltesttools.hxx>
|
||||||
|
#include <tools/XmlWriter.hxx>
|
||||||
|
|
||||||
#include <vcl/metaact.hxx>
|
#include <vcl/metaact.hxx>
|
||||||
#include <rtl/string.hxx>
|
#include <rtl/string.hxx>
|
||||||
@@ -28,8 +29,6 @@
|
|||||||
#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
|
#include <drawinglayer/primitive2d/svggradientprimitive2d.hxx>
|
||||||
#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
|
#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
|
||||||
#include <drawinglayer/geometry/viewinformation2d.hxx>
|
#include <drawinglayer/geometry/viewinformation2d.hxx>
|
||||||
|
|
||||||
|
|
||||||
#include <drawinglayer/attribute/lineattribute.hxx>
|
#include <drawinglayer/attribute/lineattribute.hxx>
|
||||||
#include <drawinglayer/attribute/fontattribute.hxx>
|
#include <drawinglayer/attribute/fontattribute.hxx>
|
||||||
|
|
||||||
@@ -70,7 +69,7 @@ xmlDocPtr Primitive2dXmlDump::dumpAndParse(
|
|||||||
else
|
else
|
||||||
pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
|
pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC));
|
||||||
|
|
||||||
XmlWriter aWriter(pStream.get());
|
tools::XmlWriter aWriter(pStream.get());
|
||||||
aWriter.startDocument();
|
aWriter.startDocument();
|
||||||
aWriter.startElement("primitive2D");
|
aWriter.startElement("primitive2D");
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ xmlDocPtr Primitive2dXmlDump::dumpAndParse(
|
|||||||
|
|
||||||
void Primitive2dXmlDump::decomposeAndWrite(
|
void Primitive2dXmlDump::decomposeAndWrite(
|
||||||
const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence,
|
const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence,
|
||||||
XmlWriter& rWriter)
|
tools::XmlWriter& rWriter)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < rPrimitive2DSequence.size(); i++)
|
for (size_t i = 0; i < rPrimitive2DSequence.size(); i++)
|
||||||
{
|
{
|
||||||
|
@@ -1,117 +0,0 @@
|
|||||||
/* -*- 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/.
|
|
||||||
*
|
|
||||||
* This file incorporates work covered by the following license notice:
|
|
||||||
*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed
|
|
||||||
* with this work for additional information regarding copyright
|
|
||||||
* ownership. The ASF licenses this file to you under the Apache
|
|
||||||
* License, Version 2.0 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <libxml/xmlstring.h>
|
|
||||||
#include <tools/stream.hxx>
|
|
||||||
#include <test/xmlwriter.hxx>
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
|
|
||||||
int lclWriteCallback(void* pContext, const char* sBuffer, int nLen)
|
|
||||||
{
|
|
||||||
SvStream* pStream = static_cast<SvStream*>(pContext);
|
|
||||||
return static_cast<int>(pStream->WriteBytes(sBuffer, nLen));
|
|
||||||
}
|
|
||||||
|
|
||||||
int lclCloseCallback(void* pContext)
|
|
||||||
{
|
|
||||||
SvStream* pStream = static_cast<SvStream*>(pContext);
|
|
||||||
pStream->Flush();
|
|
||||||
return 0; // 0 or -1 in case of error
|
|
||||||
}
|
|
||||||
|
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
XmlWriter::XmlWriter(SvStream* pStream) :
|
|
||||||
mpStream(pStream),
|
|
||||||
mpWriter(nullptr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
XmlWriter::~XmlWriter()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void XmlWriter::startDocument()
|
|
||||||
{
|
|
||||||
if (mpWriter == nullptr && mpStream != nullptr)
|
|
||||||
{
|
|
||||||
xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, mpStream, nullptr);
|
|
||||||
mpWriter = xmlNewTextWriter(xmlOutBuffer);
|
|
||||||
xmlTextWriterSetIndent(mpWriter, 1);
|
|
||||||
xmlTextWriterStartDocument(mpWriter, nullptr, "UTF-8", nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::endDocument()
|
|
||||||
{
|
|
||||||
xmlTextWriterEndDocument(mpWriter);
|
|
||||||
xmlFreeTextWriter(mpWriter);
|
|
||||||
mpWriter = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::element(const OString& name)
|
|
||||||
{
|
|
||||||
startElement(name);
|
|
||||||
endElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::startElement(const OString& name)
|
|
||||||
{
|
|
||||||
xmlChar* xmlName = xmlCharStrdup(name.getStr());
|
|
||||||
xmlTextWriterStartElement(mpWriter, xmlName);
|
|
||||||
xmlFree(xmlName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::attribute(const OString& name, const OString & value)
|
|
||||||
{
|
|
||||||
xmlChar* xmlName = xmlCharStrdup(name.getStr());
|
|
||||||
xmlChar* xmlValue = xmlCharStrdup(value.getStr());
|
|
||||||
xmlTextWriterWriteAttribute(mpWriter, xmlName, xmlValue);
|
|
||||||
xmlFree(xmlValue);
|
|
||||||
xmlFree(xmlName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::attribute(const OString& name, const OUString& value)
|
|
||||||
{
|
|
||||||
attribute(name, OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr());
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber)
|
|
||||||
{
|
|
||||||
attribute(name, OUString::number(aNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::content(const OUString& aValue)
|
|
||||||
{
|
|
||||||
content(OUStringToOString(aValue, RTL_TEXTENCODING_UTF8));
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::content(const OString& aValue)
|
|
||||||
{
|
|
||||||
xmlChar* xmlValue = xmlCharStrdup(aValue.getStr());
|
|
||||||
xmlTextWriterWriteString(mpWriter, xmlValue);
|
|
||||||
xmlFree(xmlValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void XmlWriter::endElement()
|
|
||||||
{
|
|
||||||
xmlTextWriterEndElement(mpWriter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
|
@@ -113,6 +113,12 @@ void XmlWriter::content(const OUString& sValue)
|
|||||||
content(OUStringToOString(sValue, RTL_TEXTENCODING_UTF8));
|
content(OUStringToOString(sValue, RTL_TEXTENCODING_UTF8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XmlWriter::element(const OString& sName)
|
||||||
|
{
|
||||||
|
startElement(sName);
|
||||||
|
endElement();
|
||||||
|
}
|
||||||
|
|
||||||
} // end tools namespace
|
} // end tools namespace
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
Reference in New Issue
Block a user