[Libreoffice-commits] core.git: 4 commits - sw/qa sw/source

Jan Holesovsky kendy at collabora.com
Wed Sep 18 10:12:17 PDT 2013


 sw/qa/extras/ooxmlexport/data/style-inheritance.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx             |   66 ++++++++++++++++---
 sw/source/filter/ww8/docxattributeoutput.cxx         |    9 +-
 sw/source/filter/ww8/wrtw8sty.cxx                    |    2 
 4 files changed, 63 insertions(+), 14 deletions(-)

New commits:
commit 83ea6bf0deb8c2450e5e8fbdac0194c30ba5ff85
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Sep 18 19:06:10 2013 +0200

    DOCX export: XPath should allow checking for the number of returned nodes.
    
    This is to implement a test that <w:next> style is not exported for styles
    where the next style equals to the style itself [which comes with this commit
    too].
    
    Change-Id: I5fa9999cf7e741dc96f3538b7c1106e1add6b61e

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index f103cda..47b6318 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -134,7 +134,24 @@ private:
      * xml stream, so that you can do the asserting.
      */
     xmlDocPtr parseExport(const OUString& rStreamName = OUString("word/document.xml"));
-    void assertXPath(xmlDocPtr pXmlDoc, OString aXPath, OString aAttribute = OString(), OUString aExpectedValue = OUString());
+
+    /**
+     * Helper method to return nodes represented by rXPath.
+     */
+    xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath);
+
+    /**
+     * 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());
+
+    /**
+     * 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);
 };
 
 void Test::run()
@@ -258,19 +275,30 @@ xmlDocPtr Test::parseExport(const OUString& rStreamName)
     return xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
 }
 
-void Test::assertXPath(xmlDocPtr pXmlDoc, OString aXPath, OString aAttribute, OUString aExpectedValue)
+xmlNodeSetPtr Test::getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
 {
     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"));
-    xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathCtx);
-    xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
+    xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
+    return pXmlXpathObj->nodesetval;
+}
+
+void Test::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
     CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
-    if (aAttribute.isEmpty())
+    if (rAttribute.isEmpty())
         return;
     xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
-    OUString aValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr())));
-    CPPUNIT_ASSERT_EQUAL(aExpectedValue, aValue);
+    OUString aValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
+    CPPUNIT_ASSERT_EQUAL(rExpectedValue, aValue);
+}
+
+void Test::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
+{
+    xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
+    CPPUNIT_ASSERT_EQUAL(nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
 }
 
 void Test::testZoom()
@@ -1336,6 +1364,9 @@ void Test::testStyleInheritance()
     assertXPath(pXmlStyles, "/w:styles/w:style[1]", "styleId", "Normal");
     // some random style later
     assertXPath(pXmlStyles, "/w:styles/w:style[4]", "styleId", "Heading3");
+
+    // Check that we do _not_ export w:next for styles that point to themselves.
+    assertXPath(pXmlStyles, "/w:styles/w:style[1]/w:next", 0);
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
commit c5c17b6a5f9d756ece6757159ee3be4494e9aca7
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Sep 18 19:03:17 2013 +0200

    DOCX styles: Don't export <w:next> for styles that point to themselves.
    
    Change-Id: I3f877f9dc836686e91df70ff1e02e67ca25b4a84

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index dc317ca..7d060ea 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3265,9 +3265,12 @@ void DocxAttributeOutput::StartStyle( const String& rName, bool bPapFmt,
                 FSEND );
     }
 
-    m_pSerializer->singleElementNS( XML_w, XML_next,
-            FSNS( XML_w, XML_val ), m_rExport.pStyles->GetStyleId(nNext).getStr(),
-            FSEND );
+    if ( nNext != nId )
+    {
+        m_pSerializer->singleElementNS( XML_w, XML_next,
+                FSNS( XML_w, XML_val ), m_rExport.pStyles->GetStyleId(nNext).getStr(),
+                FSEND );
+    }
 
     if ( bAutoUpdate )
         m_pSerializer->singleElementNS( XML_w, XML_autoRedefine, FSEND );
commit a19bcc4c876b1f94c27e55c3813cfc878df3e377
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Sep 18 18:30:47 2013 +0200

    DOCX styles: Unit test for the styleId's.
    
    Change-Id: I309a9c7ed0ad633ca58dce542d5fa2db883a17ec

diff --git a/sw/qa/extras/ooxmlexport/data/style-inheritance.docx b/sw/qa/extras/ooxmlexport/data/style-inheritance.docx
new file mode 100644
index 0000000..65ca38a
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/style-inheritance.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 66b3935..f103cda 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -117,6 +117,7 @@ public:
     void testA4AndBorders();
     void testFdo68787();
     void testCharacterBorder();
+    void testStyleInheritance();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -132,7 +133,7 @@ private:
      * xml stream, and asserting an XPath expression. This method returns the
      * xml stream, so that you can do the asserting.
      */
-    xmlDocPtr parseExport();
+    xmlDocPtr parseExport(const OUString& rStreamName = OUString("word/document.xml"));
     void assertXPath(xmlDocPtr pXmlDoc, OString aXPath, OString aAttribute = OString(), OUString aExpectedValue = OUString());
 };
 
@@ -210,6 +211,7 @@ void Test::run()
         {"a4andborders.docx", &Test::testA4AndBorders},
         {"fdo68787.docx", &Test::testFdo68787},
         {"charborder.odt", &Test::testCharacterBorder},
+        {"style-inheritance.docx", &Test::testStyleInheritance},
     };
     // Don't test the first import of these, for some reason those tests fail
     const char* aBlacklist[] = {
@@ -231,7 +233,7 @@ void Test::run()
     }
 }
 
-xmlDocPtr Test::parseExport()
+xmlDocPtr Test::parseExport(const OUString& rStreamName)
 {
     // Create the zip file.
     utl::TempFile aTempFile;
@@ -239,7 +241,7 @@ xmlDocPtr Test::parseExport()
 
     // Read the XML stream we're interested in.
     uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), aTempFile.GetURL());
-    uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("word/document.xml"), uno::UNO_QUERY);
+    uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(rStreamName), uno::UNO_QUERY);
     boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
     pStream->Seek(STREAM_SEEK_TO_END);
     sal_Size nSize = pStream->Tell();
@@ -1323,6 +1325,19 @@ void Test::testCharacterBorder()
     }
 }
 
+void Test::testStyleInheritance()
+{
+    // This document has several issues to fix, more checks will be here to
+    // test its various aspects
+
+    // Check that now styleId's are more like what MSO produces
+    xmlDocPtr pXmlStyles = parseExport("word/styles.xml");
+    // the 1st style always must be Normal
+    assertXPath(pXmlStyles, "/w:styles/w:style[1]", "styleId", "Normal");
+    // some random style later
+    assertXPath(pXmlStyles, "/w:styles/w:style[4]", "styleId", "Heading3");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit e7f9230b6f841c6c366779f6d33686cfee78f6b9
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Sep 18 15:23:21 2013 +0200

    DOCX styles: Uppercase styleId's starting with 'a' too ;-)
    
    Change-Id: I6249cd121b74caed1b20046049765b4a62d6c854

diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 67ff6cc..969b2b3 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -315,7 +315,7 @@ void MSWordStyles::BuildStyleIds()
                 ('A' <= nChar && nChar <= 'Z'))
             {
                 // first letter should be uppercase
-                if (aStyleIdBuf.isEmpty() && ('a' < nChar && nChar <= 'z'))
+                if (aStyleIdBuf.isEmpty() && 'a' <= nChar && nChar <= 'z')
                     aStyleIdBuf.append(char(nChar - ('a' - 'A')));
                 else
                     aStyleIdBuf.append(char(nChar));


More information about the Libreoffice-commits mailing list