[Libreoffice-commits] core.git: 3 commits - include/test sc/CppunitTest_sc_html_export_test.mk sc/Module_sc.mk sc/qa sd/qa sd/source sw/qa test/Library_test.mk test/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Tue Apr 29 14:58:17 PDT 2014


 include/test/htmltesttools.hxx                   |   29 +++++
 include/test/xmltesttools.hxx                    |   48 ++++++++
 sc/CppunitTest_sc_html_export_test.mk            |  114 +++++++++++++++++++++
 sc/Module_sc.mk                                  |    1 
 sc/qa/extras/htmlexporttest.cxx                  |  100 ++++++++++++++++++
 sc/qa/extras/testdocuments/BaseForHTMLExport.ods |binary
 sd/qa/unit/HtmlExportTest.cxx                    |   42 -------
 sd/source/filter/html/htmlex.cxx                 |   61 ++++++-----
 sd/source/filter/html/htmlex.hxx                 |    8 +
 sw/qa/extras/htmlexport/htmlexport.cxx           |   22 ----
 sw/qa/extras/inc/swmodeltestbase.hxx             |  107 -------------------
 test/Library_test.mk                             |    2 
 test/source/htmltesttools.cxx                    |   26 ++++
 test/source/xmltesttools.cxx                     |  124 +++++++++++++++++++++++
 14 files changed, 496 insertions(+), 188 deletions(-)

New commits:
commit fa8d10adbf12bef19cfe6dd39d2667944a2fb7d6
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Tue Apr 29 23:54:32 2014 +0200

    sc html export: HTML export test fixture & "SkipImages" test
    
    Change-Id: I8a419f535570924d508e1ce5f0c6bb1fbdd829a7

diff --git a/sc/CppunitTest_sc_html_export_test.mk b/sc/CppunitTest_sc_html_export_test.mk
new file mode 100644
index 0000000..15b42d1
--- /dev/null
+++ b/sc/CppunitTest_sc_html_export_test.mk
@@ -0,0 +1,114 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,sc_html_export_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sc_html_export_test, \
+    sc/qa/extras/htmlexporttest \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sc_html_export_test, \
+	boost_headers \
+	libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sc_html_export_test, \
+    basegfx \
+    comphelper \
+    cppu \
+    cppuhelper \
+    drawinglayer \
+    editeng \
+    for \
+    forui \
+    i18nlangtag \
+    msfilter \
+    oox \
+    sal \
+    salhelper \
+    sax \
+    sc \
+    scqahelper \
+    sfx \
+    sot \
+    svl \
+    svt \
+    svx \
+    svxcore \
+	test \
+    tl \
+    tk \
+    ucbhelper \
+	unotest \
+    utl \
+    vcl \
+    xo \
+	$(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sc_html_export_test,\
+    -I$(SRCDIR)/sc/source/ui/inc \
+    -I$(SRCDIR)/sc/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sc_html_export_test,\
+    offapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sc_html_export_test))
+
+$(eval $(call gb_CppunitTest_use_components,sc_html_export_test,\
+    basic/util/sb \
+    comphelper/util/comphelp \
+    configmgr/source/configmgr \
+    dbaccess/util/dba \
+    filter/source/config/cache/filterconfig1 \
+    forms/util/frm \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    linguistic/source/lng \
+    oox/util/oox \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    sax/source/expatwrap/expwrap \
+    sc/util/sc \
+    sc/util/scd \
+    sc/util/scfilt \
+    $(if $(filter TRUE,$(DISABLE_SCRIPTING)),, \
+	    sc/util/vbaobj) \
+    scripting/source/basprov/basprov \
+    scripting/util/scriptframe \
+    scripting/source/vbaevents/vbaevents \
+    scripting/source/dlgprov/dlgprov \
+    sfx2/util/sfx \
+    sot/util/sot \
+    svl/source/fsstor/fsstorage \
+    svtools/util/svt \
+    svx/util/svx \
+    svx/util/svxcore \
+    toolkit/util/tk \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    ucb/source/ucp/tdoc/ucptdoc1 \
+    unotools/util/utl \
+    unoxml/source/rdf/unordf \
+    unoxml/source/service/unoxml \
+    xmloff/util/xo \
+    eventattacher/source/evtatt \
+    i18npool/source/search/i18nsearch \
+    vbahelper/util/msforms \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sc_html_export_test))
+
+$(eval $(call gb_CppunitTest_use_unittest_configuration,sc_html_export_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index fae40f5..41804b2 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -54,6 +54,7 @@ $(eval $(call gb_Module_add_check_targets,sc,\
     CppunitTest_sc_ucalc \
     CppunitTest_sc_filters_test \
     CppunitTest_sc_rangelst_test \
+    CppunitTest_sc_html_export_test \
 ))
 
 $(eval $(call gb_Module_add_slowcheck_targets,sc, \
diff --git a/sc/qa/extras/htmlexporttest.cxx b/sc/qa/extras/htmlexporttest.cxx
new file mode 100644
index 0000000..e065251
--- /dev/null
+++ b/sc/qa/extras/htmlexporttest.cxx
@@ -0,0 +1,100 @@
+/* -*- 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 <sal/config.h>
+
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+
+#include <test/bootstrapfixture.hxx>
+#include <test/htmltesttools.hxx>
+#include <test/xmltesttools.hxx>
+#include <comphelper/processfactory.hxx>
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotest/macros_test.hxx>
+#include <sfx2/docfilt.hxx>
+#include <sfx2/docfile.hxx>
+
+#include "docsh.hxx"
+
+using namespace css::uno;
+using namespace css::lang;
+using namespace css::frame;
+using namespace utl;
+
+class ScHTMLExportTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools, public HtmlTestTools
+{
+    Reference<XComponent> mxComponent;
+    TempFile              maTempFile;
+    OUString              maFilterOptions;
+
+    void load(const char* pDir, const char* pName)
+    {
+        if (mxComponent.is())
+            mxComponent->dispose();
+        mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Calc.SpreadsheetDocument");
+    }
+
+    void save(const OUString& aFilterName, TempFile& rTempFile)
+    {
+        rTempFile.EnableKillingFile();
+
+        Reference<XStorable> xStorable(mxComponent, UNO_QUERY);
+        MediaDescriptor aMediaDescriptor;
+        aMediaDescriptor["FilterName"] <<= aFilterName;
+        if (!maFilterOptions.isEmpty())
+            aMediaDescriptor["FilterOptions"] <<= maFilterOptions;
+        xStorable->storeToURL(rTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+    }
+
+public:
+    ScHTMLExportTest()
+    {}
+
+    virtual void setUp() SAL_OVERRIDE
+    {
+        test::BootstrapFixture::setUp();
+        mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
+    }
+
+    void testHtmlSkipImage()
+    {
+        htmlDocPtr pDoc;
+
+        load("/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods");
+        save("HTML (StarCalc)", maTempFile);
+        pDoc = parseHtml(maTempFile);
+        CPPUNIT_ASSERT (pDoc);
+
+        assertXPath(pDoc, "/html/body", 1);
+        assertXPath(pDoc, "/html/body/table/tr/td/img", 1);
+
+        load("/sc/qa/extras/testdocuments/", "BaseForHTMLExport.ods");
+        maFilterOptions = OUString("SkipImages");
+        save("HTML (StarCalc)", maTempFile);
+
+        pDoc = parseHtml(maTempFile);
+        CPPUNIT_ASSERT (pDoc);
+        assertXPath(pDoc, "/html/body", 1);
+        assertXPath(pDoc, "/html/body/table/tr/td/img", 0);
+    }
+
+    CPPUNIT_TEST_SUITE(ScHTMLExportTest);
+    CPPUNIT_TEST(testHtmlSkipImage);
+    CPPUNIT_TEST_SUITE_END();
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ScHTMLExportTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/extras/testdocuments/BaseForHTMLExport.ods b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods
new file mode 100644
index 0000000..025b1e4
Binary files /dev/null and b/sc/qa/extras/testdocuments/BaseForHTMLExport.ods differ
commit dde833575e29afecb6b053d3be28d9d028a72bef
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Tue Apr 29 15:07:54 2014 +0200

    tests: add XML and HTML test tools to test module
    
    XML and HTML parsing and XPath asserts are used by many test in
    sw, sc and sd modules. This commit moves this functionallity to
    test module, where it is available to all modules.
    
    Change-Id: I53ad9c45b24f4c9bf106cb58ea619002968bfeda

diff --git a/include/test/htmltesttools.hxx b/include/test/htmltesttools.hxx
new file mode 100644
index 0000000..99d6bcf
--- /dev/null
+++ b/include/test/htmltesttools.hxx
@@ -0,0 +1,29 @@
+/* -*- 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 HTML_TEST_TOOLS_H
+#define HTML_TEST_TOOLS_H
+
+#include <sal/config.h>
+#include <test/testdllapi.hxx>
+
+#include <libxml/HTMLparser.h>
+#include <libxml/HTMLtree.h>
+
+#include <unotools/tempfile.hxx>
+#include <boost/scoped_array.hpp>
+
+class OOO_DLLPUBLIC_TEST HtmlTestTools
+{
+protected:
+    htmlDocPtr parseHtml(utl::TempFile& aTempFile);
+};
+
+#endif
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/test/xmltesttools.hxx b/include/test/xmltesttools.hxx
new file mode 100644
index 0000000..a12d780
--- /dev/null
+++ b/include/test/xmltesttools.hxx
@@ -0,0 +1,48 @@
+/* -*- 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 XML_TEST_TOOLS_H
+#define XML_TEST_TOOLS_H
+
+#include <sal/config.h>
+#include <test/testdllapi.hxx>
+
+#include <libxml/xmlwriter.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+#include <libxml/parserInternals.h>
+
+#include <rtl/string.hxx>
+#include <rtl/ustring.hxx>
+#include <cppunit/TestAssert.h>
+
+class OOO_DLLPUBLIC_TEST XmlTestTools
+{
+protected:
+    XmlTestTools();
+    virtual ~XmlTestTools();
+
+    virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx);
+
+    xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath);
+    OUString      getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute);
+    OUString      getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath);
+    int           getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rChildName);
+    void          assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath,
+                              const OString& rAttribute = OString(),
+                              const OUString& rExpectedValue = OUString());
+    void          assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes);
+    void          assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent);
+    void          assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes);
+
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/qa/unit/HtmlExportTest.cxx b/sd/qa/unit/HtmlExportTest.cxx
index a8aab8c..4ce0a5d 100644
--- a/sd/qa/unit/HtmlExportTest.cxx
+++ b/sd/qa/unit/HtmlExportTest.cxx
@@ -9,49 +9,15 @@
 
 #include "sdmodeltestbase.hxx"
 
-#include <libxml/xmlwriter.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-#include <libxml/parserInternals.h>
-#include <libxml/HTMLparser.h>
-#include <libxml/HTMLtree.h>
-
-#include <rtl/byteseq.hxx>
-#include <boost/scoped_array.hpp>
+#include <test/htmltesttools.hxx>
+#include <test/xmltesttools.hxx>
 
 using namespace css;
 using namespace rtl;
 
-class SdHTMLFilterTest : public SdModelTestBase
+class SdHTMLFilterTest : public SdModelTestBase, public XmlTestTools, public HtmlTestTools
 {
-    htmlDocPtr parseHtml(utl::TempFile& aTempFile)
-    {
-        SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ);
-        sal_Size nSize = aFileStream.remainingSize();
-
-        boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]);
-
-        aFileStream.Read(pBuffer.get(), nSize);
-
-        pBuffer[nSize] = 0;
-        printf("Content: %s\n", reinterpret_cast<char*>(pBuffer.get()));
-        return htmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()), NULL);
-    }
-
-    xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
-    {
-        xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
-        xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
-        return pXmlXpathObj->nodesetval;
-    }
-
-    void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
-    {
-        xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
-                                     nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
-    }
-
+private:
     htmlDocPtr exportAndparseHtml(sd::DrawDocShellRef& xDocShRef)
     {
         FileFormat* pFormat = getFormat(HTML);
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 4e42cb4..8d73286 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -18,12 +18,11 @@
 #include <swmodule.hxx>
 #include <usrpref.hxx>
 
-#include <libxml/HTMLparser.h>
-#include <libxml/HTMLtree.h>
+#include <test/htmltesttools.hxx>
 
 using namespace rtl;
 
-class Test : public SwModelTestBase
+class Test : public SwModelTestBase, public HtmlTestTools
 {
 private:
     FieldUnit m_eUnit;
@@ -34,19 +33,6 @@ public:
         m_eUnit(FUNIT_NONE)
     {}
 
-protected:
-    htmlDocPtr parseHtml()
-    {
-        SvFileStream aFileStream(m_aTempFile.GetURL(), STREAM_READ);
-        sal_Size nSize = aFileStream.remainingSize();
-
-        ByteSequence aBuffer(nSize + 1);
-        aFileStream.Read(aBuffer.getArray(), nSize);
-
-        aBuffer[nSize] = 0;
-        return htmlParseDoc(reinterpret_cast<xmlChar*>(aBuffer.getArray()), NULL);
-    }
-
 private:
     bool mustCalcLayoutOf(const char* filename) SAL_OVERRIDE
     {
@@ -119,7 +105,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testCharacterBorder, "charborder.odt")
 
 DECLARE_HTMLEXPORT_TEST(testExportOfImages, "textAndImage.docx")
 {
-    htmlDocPtr pDoc = parseHtml();
+    htmlDocPtr pDoc = parseHtml(m_aTempFile);
     if (pDoc)
     {
         assertXPath(pDoc, "/html/body", 1);
@@ -129,7 +115,7 @@ DECLARE_HTMLEXPORT_TEST(testExportOfImages, "textAndImage.docx")
 
 DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.docx")
 {
-    htmlDocPtr pDoc = parseHtml();
+    htmlDocPtr pDoc = parseHtml(m_aTempFile);
     if (pDoc)
     {
         assertXPath(pDoc, "/html/body", 1);
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 7a2cf9a..6c5236a 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/table/BorderLine2.hpp>
 
 #include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
 #include <unotest/macros_test.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <rtl/strbuf.hxx>
@@ -36,11 +37,6 @@
 #include <doc.hxx>
 #include <rootfrm.hxx>
 
-#include <libxml/xmlwriter.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-#include <libxml/parserInternals.h>
-
 using namespace css;
 
 #define DEFAULT_STYLE "Default Style"
@@ -114,7 +110,7 @@ using namespace css;
     void TestName::verify()
 
 /// Base class for filter tests loading or roundtriping a document, then asserting the document model.
-class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
+class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
 {
     OUString maFilterOptions;
 protected:
@@ -586,9 +582,8 @@ protected:
     /**
      * Helper method to return nodes represented by rXPath.
      */
-    xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
+    virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
     {
-        xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml"));
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("mc"), BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006"));
@@ -604,102 +599,6 @@ protected:
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ContentType"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types"));
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"));
         xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("extended-properties"), BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
-        xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
-        return pXmlXpathObj->nodesetval;
-    }
-
-    /**
-     * Same as the assertXPath(), but don't assert: return the string instead.
-     */
-    OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute)
-    {
-        xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
-                                     1, xmlXPathNodeSetGetLength(pXmlNodes));
-        if (rAttribute.isEmpty())
-            return OUString();
-        xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-        return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
-    }
-
-    /**
-     * Same as the assertXPathContent(), but don't assert: return the string instead.
-     */
-    OUString getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath)
-    {
-        xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-
-        CPPUNIT_ASSERT_MESSAGE(OString("XPath '" + rXPath + "' not found").getStr(),
-                xmlXPathNodeSetGetLength(pXmlNodes) > 0);
-
-        xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-        return OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
-    }
-
-    /**
-     * Assert that rXPath exists, and returns exactly one node.
-     * In case rAttribute is provided, the rXPath's attribute's value must
-     * equal to the rExpected value.
-     */
-    void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute = OString(), const OUString& rExpectedValue = OUString())
-    {
-        OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(),
-                                     rExpectedValue, aValue);
-    }
-
-    /**
-     * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes.
-     * Useful for checking that we do _not_ export some node (nNumberOfNodes == 0).
-     */
-    void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
-    {
-        xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
-                                     nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
-    }
-
-    /**
-     * Assert that rXPath exists, and its content equals rContent.
-     */
-    void assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent)
-    {
-        CPPUNIT_ASSERT_EQUAL_MESSAGE("XPath contents of child does not match", rContent, getXPathContent(pXmlDoc, rXPath));
-    }
-
-    /**
-     * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
-     * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0).
-     */
-    void assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes)
-    {
-        xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
-                                     1, xmlXPathNodeSetGetLength(pXmlNodes));
-        xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of child-nodes is incorrect").getStr(),
-                                     nNumberOfChildNodes, (int)xmlChildElementCount(pXmlNode));
-    }
-
-    /**
-     * Get the position of the child named rName of the parent node specified by rXPath.
-     * Useful for checking relative order of elements.
-     */
-    int getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rChildName)
-    {
-        xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
-                                     1,
-                                     xmlXPathNodeSetGetLength(pXmlNodes));
-        xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-        int nRet = 0;
-        for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
-        {
-            if (OUString::createFromAscii((const char*)pChild->name) == rChildName)
-                break;
-            ++nRet;
-        }
-        return nRet;
     }
 
     uno::Reference<lang::XComponent> mxComponent;
diff --git a/test/Library_test.mk b/test/Library_test.mk
index ba304a5..ec46f2c 100644
--- a/test/Library_test.mk
+++ b/test/Library_test.mk
@@ -45,6 +45,8 @@ endif
 $(eval $(call gb_Library_add_exception_objects,test,\
     test/source/bootstrapfixture \
     test/source/diff/diff \
+    test/source/xmltesttools \
+    test/source/htmltesttools \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/test/source/htmltesttools.cxx b/test/source/htmltesttools.cxx
new file mode 100644
index 0000000..9b264bb
--- /dev/null
+++ b/test/source/htmltesttools.cxx
@@ -0,0 +1,26 @@
+/* -*- 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 <test/htmltesttools.hxx>
+
+htmlDocPtr HtmlTestTools::parseHtml(utl::TempFile& aTempFile)
+{
+    SvFileStream aFileStream(aTempFile.GetURL(), STREAM_READ);
+    sal_Size nSize = aFileStream.remainingSize();
+
+    boost::scoped_array<sal_uInt8> pBuffer(new sal_uInt8[nSize + 1]);
+
+    aFileStream.Read(pBuffer.get(), nSize);
+
+    pBuffer[nSize] = 0;
+
+    return htmlParseDoc(reinterpret_cast<xmlChar*>(pBuffer.get()), NULL);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx
new file mode 100644
index 0000000..9815351
--- /dev/null
+++ b/test/source/xmltesttools.cxx
@@ -0,0 +1,124 @@
+/* -*- 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 <test/xmltesttools.hxx>
+
+XmlTestTools::XmlTestTools()
+{}
+
+XmlTestTools::~XmlTestTools()
+{}
+
+xmlNodeSetPtr XmlTestTools::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
+{
+    xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
+    registerNamespaces(pXmlXpathCtx);
+    xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
+    return pXmlXpathObj->nodesetval;
+}
+
+void XmlTestTools::registerNamespaces(xmlXPathContextPtr& /*pXmlXpathCtx*/)
+{
+}
+
+/**
+ * Same as the assertXPath(), but don't assert: return the string instead.
+ */
+OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+                                 1, xmlXPathNodeSetGetLength(pXmlNodes));
+    if (rAttribute.isEmpty())
+        return OUString();
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
+}
+
+/**
+ * Same as the assertXPathContent(), but don't assert: return the string instead.
+ */
+OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+
+    CPPUNIT_ASSERT_MESSAGE(OString("XPath '" + rXPath + "' not found").getStr(),
+            xmlXPathNodeSetGetLength(pXmlNodes) > 0);
+
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    return OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
+}
+
+/**
+ * Assert that rXPath exists, and returns exactly one node.
+ * In case rAttribute is provided, the rXPath's attribute's value must
+ * equal to the rExpected value.
+ */
+void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue)
+{
+    OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(),
+                                 rExpectedValue, aValue);
+}
+
+/**
+ * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes.
+ * Useful for checking that we do _not_ export some node (nNumberOfNodes == 0).
+ */
+void XmlTestTools::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+                                 nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
+}
+
+/**
+ * Assert that rXPath exists, and its content equals rContent.
+ */
+void XmlTestTools::assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent)
+{
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("XPath contents of child does not match", rContent, getXPathContent(pXmlDoc, rXPath));
+}
+
+/**
+ * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
+ * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0).
+ */
+void XmlTestTools::assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+                                 1, xmlXPathNodeSetGetLength(pXmlNodes));
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of child-nodes is incorrect").getStr(),
+                                 nNumberOfChildNodes, (int)xmlChildElementCount(pXmlNode));
+}
+
+/**
+ * Get the position of the child named rName of the parent node specified by rXPath.
+ * Useful for checking relative order of elements.
+ */
+int XmlTestTools::getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rChildName)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
+                                 1,
+                                 xmlXPathNodeSetGetLength(pXmlNodes));
+    xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+    int nRet = 0;
+    for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
+    {
+        if (OUString::createFromAscii((const char*)pChild->name) == rChildName)
+            break;
+        ++nRet;
+    }
+    return nRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit de9ebbaddcb9633380e6614d7e70c1007d3be1c1
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Tue Apr 29 12:22:38 2014 +0200

    sd html: support export of tables for Draw documents
    
    Change-Id: I32fe35c90c08d7c87b27ad4a5c10f91c6284c4a3

diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx
index e6f163d..cdb18b2 100644
--- a/sd/source/filter/html/htmlex.cxx
+++ b/sd/source/filter/html/htmlex.cxx
@@ -63,6 +63,7 @@
 #include <editeng/frmdiritem.hxx>
 #include <svx/svdoutl.hxx>
 #include <svx/svdogrp.hxx>
+#include <svx/svdotable.hxx>
 #include <tools/urlobj.hxx>
 #include <vcl/bmpacc.hxx>
 #include <svtools/sfxecode.hxx>
@@ -71,7 +72,6 @@
 #include <comphelper/anytostring.hxx>
 #include <cppuhelper/exc_hlp.hxx>
 #include <basegfx/polygon/b2dpolygon.hxx>
-#include <svx/svdotable.hxx>
 
 #include "drawdoc.hxx"
 #include "htmlpublishmode.hxx"
@@ -1225,6 +1225,11 @@ OUString HtmlExport::CreateTextForPage(SdrOutliner* pOutliner, SdPage* pPage,
                     SdrObjGroup* pObjectGroup = (SdrObjGroup*) pObject;
                     WriteObjectGroup(aStr, pObjectGroup, pOutliner, rBackgroundColor, false);
                 }
+                else if (pObject->GetObjIdentifier() == OBJ_TABLE)
+                {
+                    SdrTableObj* pTableObject = (SdrTableObj*) pObject;
+                    WriteTable(aStr, pTableObject, pOutliner, rBackgroundColor);
+                }
                 else
                 {
                     if (pObject->GetOutlinerParaObject())
@@ -1238,31 +1243,7 @@ OUString HtmlExport::CreateTextForPage(SdrOutliner* pOutliner, SdPage* pPage,
             case PRESOBJ_TABLE:
             {
                 SdrTableObj* pTableObject = (SdrTableObj*) pObject;
-
-                CellPos aStart, aEnd;
-
-                aStart = pTableObject->getFirstCell();
-                aEnd = pTableObject->getLastCell();
-
-                sal_Int32 nColCount = pTableObject->getColumnCount();
-                aStr.append("<table>\r\n");
-                for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++)
-                {
-                    aStr.append("  <tr>\r\n");
-                    for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++)
-                    {
-                        aStr.append("    <td>\r\n");
-                        sal_Int32 nCellIndex = nRow * nColCount + nCol;
-                        SdrText* pText = pTableObject->getText(nCellIndex);
-
-                        if (pText == NULL)
-                            continue;
-                        WriteOutlinerParagraph(aStr, pOutliner, pText->GetOutlinerParaObject(), rBackgroundColor, false);
-                        aStr.append("    </td>\r\n");
-                    }
-                    aStr.append("  </tr>\r\n");
-                }
-                aStr.append("</table>\r\n");
+                WriteTable(aStr, pTableObject, pOutliner, rBackgroundColor);
             }
             break;
 
@@ -1283,6 +1264,34 @@ OUString HtmlExport::CreateTextForPage(SdrOutliner* pOutliner, SdPage* pPage,
     return aStr.makeStringAndClear();
 }
 
+void HtmlExport::WriteTable(OUStringBuffer& aStr, SdrTableObj* pTableObject, SdrOutliner* pOutliner, const Color& rBackgroundColor)
+{
+    CellPos aStart, aEnd;
+
+    aStart = pTableObject->getFirstCell();
+    aEnd = pTableObject->getLastCell();
+
+    sal_Int32 nColCount = pTableObject->getColumnCount();
+    aStr.append("<table>\r\n");
+    for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++)
+    {
+        aStr.append("  <tr>\r\n");
+        for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++)
+        {
+            aStr.append("    <td>\r\n");
+            sal_Int32 nCellIndex = nRow * nColCount + nCol;
+            SdrText* pText = pTableObject->getText(nCellIndex);
+
+            if (pText == NULL)
+                continue;
+            WriteOutlinerParagraph(aStr, pOutliner, pText->GetOutlinerParaObject(), rBackgroundColor, false);
+            aStr.append("    </td>\r\n");
+        }
+        aStr.append("  </tr>\r\n");
+    }
+    aStr.append("</table>\r\n");
+}
+
 void HtmlExport::WriteObjectGroup(OUStringBuffer& aStr, SdrObjGroup* pObjectGroup, SdrOutliner* pOutliner,
                                   const Color& rBackgroundColor, bool bHeadLine)
 {
diff --git a/sd/source/filter/html/htmlex.hxx b/sd/source/filter/html/htmlex.hxx
index 51d3359..cdf84cc 100644
--- a/sd/source/filter/html/htmlex.hxx
+++ b/sd/source/filter/html/htmlex.hxx
@@ -56,6 +56,7 @@ class SdPage;
 class HtmlState;
 class SdrTextObj;
 class SdrObjGroup;
+namespace sdr { namespace table { class SdrTableObj; } }
 class SdrPage;
 class SdDrawDocument;
 class ButtonSet;
@@ -216,8 +217,11 @@ class HtmlExport
                                 OutlinerParaObject* pOutlinerParagraphObject,
                                 const Color& rBackgroundColor, bool bHeadLine);
 
-    void WriteObjectGroup(OUStringBuffer& aStr, SdrObjGroup* pObjectGroup, SdrOutliner* pOutliner,
-                          const Color& rBackgroundColor, bool bHeadLine);
+    void WriteObjectGroup(OUStringBuffer& aStr, SdrObjGroup* pObjectGroup,
+                          SdrOutliner* pOutliner, const Color& rBackgroundColor, bool bHeadLine);
+
+    void WriteTable(OUStringBuffer& aStr, sdr::table::SdrTableObj* pTableObject,
+                    SdrOutliner* pOutliner, const Color& rBackgroundColor);
 
  public:
     HtmlExport(const OUString& aPath,


More information about the Libreoffice-commits mailing list