summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-12-10 22:15:21 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-12-10 22:15:21 +0100
commitabdc998562acac7174ac8f83935404456109a141 (patch)
tree787f6040863e3b63a0bc48ef16507cf1344dddf7
parent109540e113867fd140838e5be79ca0e41c13d85c (diff)
fdo#86664 VSDX: test metadata import
Only title as a start. Change-Id: I6d5f6e2dc1730ff2b2dfda760d575f605ab034eb
-rw-r--r--.gitignore2
-rw-r--r--configure.ac17
-rw-r--r--src/Makefile.am2
-rw-r--r--src/test/.gitignore12
-rw-r--r--src/test/Makefile.am26
-rw-r--r--src/test/data/fdo86664.vsdxbin0 -> 22330 bytes
-rw-r--r--src/test/importtest.cpp143
-rw-r--r--src/test/test.cpp36
-rw-r--r--src/test/xmldrawinggenerator.cpp386
-rw-r--r--src/test/xmldrawinggenerator.h97
10 files changed, 720 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 3ead918..96ddc28 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,8 @@ missing
mkinstalldirs
stamp-h1
tags
+test-driver
*.pc
*.rc
*~
+*.tar.*
diff --git a/configure.ac b/configure.ac
index d279ec1..41e3d7e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -306,6 +306,21 @@ AS_IF([test "x$enable_debug" = "xyes"], [
])
AC_SUBST(DEBUG_CXXFLAGS)
+# ==========
+# Unit tests
+# ==========
+AC_ARG_ENABLE([tests],
+ [AS_HELP_STRING([--enable-tests], [Build and run unit tests])],
+ [enable_tests="$enableval"],
+ [enable_tests=yes]
+)
+AS_IF([test "x$enable_tests" = "xyes"], [
+ PKG_CHECK_MODULES([CPPUNIT], [cppunit])
+], [])
+AC_SUBST([CPPUNIT_CFLAGS])
+AC_SUBST([CPPUNIT_LIBS])
+AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" = "xyes"])
+
# =============
# Documentation
# =============
@@ -342,6 +357,7 @@ src/conv/text/vsd2text.rc
src/conv/text/vss2text.rc
src/lib/Makefile
src/lib/libvisio.rc
+src/test/Makefile
inc/Makefile
inc/libvisio/Makefile
build/Makefile
@@ -360,6 +376,7 @@ AC_MSG_NOTICE([
Build configuration:
debug: ${enable_debug}
docs: ${build_docs}
+ tests: ${enable_tests}
tools: ${enable_tools}
werror: ${enable_werror}
==============================================================================
diff --git a/src/Makefile.am b/src/Makefile.am
index 64fd45e..2cf2099 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = lib
+SUBDIRS = lib test
if BUILD_TOOLS
SUBDIRS += conv
diff --git a/src/test/.gitignore b/src/test/.gitignore
new file mode 100644
index 0000000..a4ecf9e
--- /dev/null
+++ b/src/test/.gitignore
@@ -0,0 +1,12 @@
+Makefile
+Makefile.in
+test
+testfileinfo
+.libs
+.deps
+*.lo
+*.log
+*.o
+*.trs
+*~
+*.exe
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
new file mode 100644
index 0000000..d136ecf
--- /dev/null
+++ b/src/test/Makefile.am
@@ -0,0 +1,26 @@
+check_PROGRAMS = test
+
+AM_CXXFLAGS = \
+ -I$(top_srcdir)/inc \
+ $(LIBVISIO_CXXFLAGS) \
+ $(REVENGE_STREAM_CFLAGS) \
+ $(CPPUNIT_CFLAGS) \
+ $(DEBUG_CXXFLAGS)
+
+test_CPPFLAGS = -DTDOC=\"$(top_srcdir)/src/test/data\"
+test_LDADD = \
+ ../lib/libvisio-@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.la \
+ $(CPPUNIT_LIBS) \
+ $(LIBVISIO_LIBS) \
+ $(REVENGE_STREAM_LIBS)
+test_SOURCES = \
+ xmldrawinggenerator.cpp \
+ xmldrawinggenerator.h \
+ importtest.cpp \
+ test.cpp
+
+EXTRA_DIST = \
+ data/fdo86664.vsdx \
+ $(test_SOURCES)
+
+TESTS = test
diff --git a/src/test/data/fdo86664.vsdx b/src/test/data/fdo86664.vsdx
new file mode 100644
index 0000000..bad6caa
--- /dev/null
+++ b/src/test/data/fdo86664.vsdx
Binary files differ
diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp
new file mode 100644
index 0000000..1560fef
--- /dev/null
+++ b/src/test/importtest.cpp
@@ -0,0 +1,143 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libvisio 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 <libvisio/libvisio.h>
+#include <libxml/xpath.h>
+#include <iostream>
+#include <cppunit/extensions/HelperMacros.h>
+#include "xmldrawinggenerator.h"
+
+namespace
+{
+
+/// Allows using CPPUNIT_ASSERT_EQUAL() on librevenge::RVNGString instances.
+std::ostream& operator <<(std::ostream& s, const librevenge::RVNGString &string)
+{
+ return s << string.cstr();
+}
+
+/// Caller must call xmlXPathFreeObject.
+xmlXPathObjectPtr getXPathNode(xmlDocPtr doc, const librevenge::RVNGString &xpath)
+{
+ xmlXPathContextPtr xpathContext = xmlXPathNewContext(doc);
+ xmlXPathObjectPtr xpathObject = xmlXPathEvalExpression(BAD_CAST(xpath.cstr()), xpathContext);
+ xmlXPathFreeContext(xpathContext);
+ return xpathObject;
+}
+
+/// Same as the assertXPath(), but don't assert: return the string instead.
+librevenge::RVNGString getXPath(xmlDocPtr doc, const librevenge::RVNGString &xpath, const librevenge::RVNGString &attribute)
+{
+ xmlXPathObjectPtr xpathobject = getXPathNode(doc, xpath);
+ xmlNodeSetPtr nodeset = xpathobject->nodesetval;
+
+ librevenge::RVNGString message("XPath '");
+ message.append(xpath);
+ message.append("': number of nodes is incorrect.");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), 1, xmlXPathNodeSetGetLength(nodeset));
+ if (attribute.empty())
+ return librevenge::RVNGString();
+ xmlNodePtr node = nodeset->nodeTab[0];
+ xmlChar *prop = xmlGetProp(node, BAD_CAST(attribute.cstr()));
+ librevenge::RVNGString s((const char *)prop);
+ xmlFree(prop);
+ xmlXPathFreeObject(xpathobject);
+ return s;
+}
+
+/**
+ * Assert that xpath exists, and xpath returns exactly one node.
+ * xpath's attribute's value must equal to the expectedValue value.
+ */
+void assertXPath(xmlDocPtr doc, const librevenge::RVNGString &xpath, const librevenge::RVNGString &attribute, const librevenge::RVNGString &expectedValue)
+{
+ librevenge::RVNGString actualValue = getXPath(doc, xpath, attribute);
+ librevenge::RVNGString message("Attribute '");
+ message.append(attribute);
+ message.append("' of '");
+ message.append(xpath);
+ message.append("': incorrect value.");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), expectedValue, actualValue);
+}
+
+/// Paints an XML representation of filename into buffer, then returns the parsed buffer content.
+xmlDocPtr parse(const char *filename, xmlBufferPtr buffer)
+{
+ librevenge::RVNGString path(TDOC "/");
+ path.append(filename);
+ librevenge::RVNGFileStream input(path.cstr());
+ CPPUNIT_ASSERT(libvisio::VisioDocument::isSupported(&input));
+
+ xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
+ CPPUNIT_ASSERT(writer);
+ xmlTextWriterStartDocument(writer, 0, 0, 0);
+ libvisio::XmlDrawingGenerator painter(writer);
+
+ CPPUNIT_ASSERT(libvisio::VisioDocument::parse(&input, &painter));
+
+ xmlTextWriterEndDocument(writer);
+ xmlFreeTextWriter(writer);
+
+ //std::cerr << "XML is '" << (const char *)xmlBufferContent(buffer) << "'" << std::endl;
+ return xmlParseMemory((const char *)xmlBufferContent(buffer), xmlBufferLength(buffer));
+}
+
+}
+
+class ImportTest : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ImportTest);
+ CPPUNIT_TEST(testVsdxMetadataTitle);
+ CPPUNIT_TEST_SUITE_END();
+
+ void testVsdxMetadataTitle();
+
+ xmlBufferPtr m_buffer;
+ xmlDocPtr m_doc;
+
+public:
+ ImportTest();
+ virtual void setUp();
+ virtual void tearDown();
+};
+
+ImportTest::ImportTest()
+ : m_buffer(0),
+ m_doc(0)
+{
+}
+
+void ImportTest::setUp()
+{
+ CPPUNIT_ASSERT(!m_buffer);
+ m_buffer = xmlBufferCreate();
+ CPPUNIT_ASSERT(m_buffer);
+
+ CPPUNIT_ASSERT(!m_doc);
+}
+
+void ImportTest::tearDown()
+{
+ xmlFreeDoc(m_doc);
+ m_doc = 0;
+
+ xmlBufferFree(m_buffer);
+ m_buffer = 0;
+}
+
+void ImportTest::testVsdxMetadataTitle()
+{
+ m_doc = parse("fdo86664.vsdx", m_buffer);
+ // The setDocumentMetaData() call was missing, so the node did not exist.
+ assertXPath(m_doc, "/document/setDocumentMetaData", "title", "mytitle");
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest);
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/test/test.cpp b/src/test/test.cpp
new file mode 100644
index 0000000..c10a2be
--- /dev/null
+++ b/src/test/test.cpp
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libvisio 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 <iostream>
+#include <cppunit/TestRunner.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/CompilerOutputter.h>
+
+int main()
+{
+ CPPUNIT_NS::TestResult controller;
+ CPPUNIT_NS::TestResultCollector result;
+ controller.addListener(&result);
+ CPPUNIT_NS::BriefTestProgressListener progress;
+ controller.addListener(&progress);
+
+ CPPUNIT_NS::TestRunner runner;
+ runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
+ runner.run(controller);
+
+ CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr);
+ outputter.write();
+
+ return result.wasSuccessful() ? 0 : 1;
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/test/xmldrawinggenerator.cpp b/src/test/xmldrawinggenerator.cpp
new file mode 100644
index 0000000..b64c564
--- /dev/null
+++ b/src/test/xmldrawinggenerator.cpp
@@ -0,0 +1,386 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libvisio 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 "xmldrawinggenerator.h"
+
+namespace libvisio
+{
+
+XmlDrawingGenerator::XmlDrawingGenerator(xmlTextWriterPtr writer)
+ : RVNGDrawingInterface(),
+ m_writer(writer)
+{
+}
+
+XmlDrawingGenerator::~XmlDrawingGenerator()
+{
+}
+
+void XmlDrawingGenerator::startDocument(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("document"));
+
+ xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:dc"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:meta:1.0"));
+ xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:draw"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"));
+ xmlTextWriterWriteAttribute(m_writer, BAD_CAST("xmlns:svg"), BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"));
+
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::endDocument()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::setDocumentMetaData(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("setDocumentMetaData"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::defineEmbeddedFont(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("defineEmbeddedFont"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::startPage(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("page"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::endPage()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::startMasterPage(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("masterPage"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::endMasterPage()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::startLayer(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("layer"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::endLayer()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::startEmbeddedGraphics(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("embeddedGraphics"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::endEmbeddedGraphics()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openGroup(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("group"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeGroup()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::setStyle(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("setStyle"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawRectangle(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawRectangle"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawEllipse(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawEllipse"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawPolyline(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawPolyline"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawPolygon(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawPolygon"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawPath(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawPath"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawGraphicObject(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawGraphicObject"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::drawConnector(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("drawConnector"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::startTextObject(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("textObject"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::endTextObject()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openOrderedListLevel(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("orderedListLevel"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeOrderedListLevel()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openUnorderedListLevel(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("unorderedListLevel"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeUnorderedListLevel()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openListElement(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("listElement"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeListElement()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::defineParagraphStyle(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("defineParagraphStyle"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openParagraph(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("paragraph"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeParagraph()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::defineCharacterStyle(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("defineCharacterStyle"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openSpan(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("span"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeSpan()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openLink(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("link"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeLink()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::insertTab()
+{
+ xmlTextWriterWriteElement(m_writer, BAD_CAST("insertTab"), 0);
+}
+
+void XmlDrawingGenerator::insertSpace()
+{
+ xmlTextWriterWriteElement(m_writer, BAD_CAST("insertSpace"), 0);
+}
+
+void XmlDrawingGenerator::insertText(const librevenge::RVNGString &str)
+{
+ xmlTextWriterWriteElement(m_writer, BAD_CAST("insertText"), BAD_CAST(str.cstr()));
+}
+
+void XmlDrawingGenerator::insertLineBreak()
+{
+ xmlTextWriterWriteElement(m_writer, BAD_CAST("insertLineBreak"), 0);
+}
+
+void XmlDrawingGenerator::insertField(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("insertField"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::startTableObject(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("tableObject"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::openTableRow(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("tableRow"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeTableRow()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::openTableCell(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("tableCell"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+}
+
+void XmlDrawingGenerator::closeTableCell()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::insertCoveredTableCell(const librevenge::RVNGPropertyList &propList)
+{
+ xmlTextWriterStartElement(m_writer, BAD_CAST("insertCoveredTableCell"));
+ librevenge::RVNGPropertyList::Iter i(propList);
+ for (i.rewind(); i.next();)
+ xmlTextWriterWriteFormatAttribute(m_writer, BAD_CAST(i.key()), "%s", i()->getStr().cstr());
+ xmlTextWriterEndElement(m_writer);
+}
+
+void XmlDrawingGenerator::endTableObject()
+{
+ xmlTextWriterEndElement(m_writer);
+}
+
+} // namespace libvisio
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/test/xmldrawinggenerator.h b/src/test/xmldrawinggenerator.h
new file mode 100644
index 0000000..a3c062c
--- /dev/null
+++ b/src/test/xmldrawinggenerator.h
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libvisio 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 __XMLDRAWINGGENERATOR_H__
+#define __XMLDRAWINGGENERATOR_H__
+
+#include <librevenge/librevenge.h>
+#include <libxml/xmlwriter.h>
+
+namespace libvisio
+{
+
+class XmlDrawingGenerator : public librevenge::RVNGDrawingInterface
+{
+ // disable copying
+ XmlDrawingGenerator(const XmlDrawingGenerator &other);
+ XmlDrawingGenerator &operator=(const XmlDrawingGenerator &other);
+
+ xmlTextWriterPtr m_writer;
+
+public:
+ XmlDrawingGenerator(xmlTextWriterPtr writer);
+
+ ~XmlDrawingGenerator();
+
+ void startDocument(const librevenge::RVNGPropertyList &propList);
+ void endDocument();
+ void setDocumentMetaData(const librevenge::RVNGPropertyList &propList);
+ void defineEmbeddedFont(const librevenge::RVNGPropertyList &propList);
+ void startPage(const librevenge::RVNGPropertyList &propList);
+ void endPage();
+ void startMasterPage(const librevenge::RVNGPropertyList &propList);
+ void endMasterPage();
+ void startLayer(const librevenge::RVNGPropertyList &propList);
+ void endLayer();
+ void startEmbeddedGraphics(const librevenge::RVNGPropertyList &propList);
+ void endEmbeddedGraphics();
+
+ void openGroup(const librevenge::RVNGPropertyList &propList);
+ void closeGroup();
+
+ void setStyle(const librevenge::RVNGPropertyList &propList);
+
+ void drawRectangle(const librevenge::RVNGPropertyList &propList);
+ void drawEllipse(const librevenge::RVNGPropertyList &propList);
+ void drawPolyline(const librevenge::RVNGPropertyList &propList);
+ void drawPolygon(const librevenge::RVNGPropertyList &propList);
+ void drawPath(const librevenge::RVNGPropertyList &propList);
+ void drawGraphicObject(const librevenge::RVNGPropertyList &propList);
+ void drawConnector(const librevenge::RVNGPropertyList &propList);
+ void startTextObject(const librevenge::RVNGPropertyList &propList);
+ void endTextObject();
+
+ void startTableObject(const librevenge::RVNGPropertyList &propList);
+ void openTableRow(const librevenge::RVNGPropertyList &propList);
+ void closeTableRow();
+ void openTableCell(const librevenge::RVNGPropertyList &propList);
+ void closeTableCell();
+ void insertCoveredTableCell(const librevenge::RVNGPropertyList &propList);
+ void endTableObject();
+
+ void openOrderedListLevel(const librevenge::RVNGPropertyList &propList);
+ void closeOrderedListLevel();
+ void openUnorderedListLevel(const librevenge::RVNGPropertyList &propList);
+ void closeUnorderedListLevel();
+ void openListElement(const librevenge::RVNGPropertyList &propList);
+ void closeListElement();
+
+ void defineParagraphStyle(const librevenge::RVNGPropertyList &propList);
+ void openParagraph(const librevenge::RVNGPropertyList &propList);
+ void closeParagraph();
+
+ void defineCharacterStyle(const librevenge::RVNGPropertyList &propList);
+ void openSpan(const librevenge::RVNGPropertyList &propList);
+ void closeSpan();
+
+ void openLink(const librevenge::RVNGPropertyList &propList);
+ void closeLink();
+
+ void insertTab();
+ void insertSpace();
+ void insertText(const librevenge::RVNGString &text);
+ void insertLineBreak();
+ void insertField(const librevenge::RVNGPropertyList &propList);
+};
+
+} // namespace libvisio
+
+#endif // __XMLDRAWINGGENERATOR_H__
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */