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

Miklos Vajna vmiklos at collabora.co.uk
Thu Jul 10 08:59:19 PDT 2014


 sw/qa/extras/README                                    |   48 ++++++-----------
 sw/qa/extras/ooxmlexport/data/sdt-date-charformat.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx               |    9 +++
 sw/source/filter/ww8/docxattributeoutput.cxx           |   10 +++
 sw/source/filter/ww8/docxtablestyleexport.cxx          |    5 +
 sw/source/filter/ww8/docxtablestyleexport.hxx          |    7 ++
 writerfilter/source/dmapper/DomainMapper.cxx           |    6 +-
 writerfilter/source/dmapper/SdtHelper.cxx              |    5 +
 writerfilter/source/dmapper/SdtHelper.hxx              |    2 
 9 files changed, 58 insertions(+), 34 deletions(-)

New commits:
commit 3bd2fa9111ac95044240d4fb80fb4f4c1426bb06
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 10 17:52:30 2014 +0200

    Update sw/qa/extras/README
    
    The run() method is gone since 4.2.
    
    Change-Id: Ia7a9932001dff7834e960885096468148d47738a

diff --git a/sw/qa/extras/README b/sw/qa/extras/README
index 01e0976..fbc6aac 100644
--- a/sw/qa/extras/README
+++ b/sw/qa/extras/README
@@ -5,9 +5,9 @@ tests. This file documents how to add new testcases to this framework.
 
 == Import tests
 
-Import tests are the easier ones. First you need to add a new entry to the
-table inside the `run()` method, so the framework will load the specified file
-to `mxComponent`, which represents the UNO model of the document.
+Import tests are the easier ones. First you need to use
+`DECLARE_SW_IMPORT_TEST()`, so the framework will load the specified file to
+`mxComponent`, which represents the UNO model of the document.
 
 The rest of the testcase is about implementing the test method asserting this
 document model: use the UNO API to retrieve properties, then use
@@ -26,6 +26,9 @@ at the `layout.xml` file in the current directory. Once you find the needed
 information in that file, you can write your XPath expression to turn that into
 a testcase.
 
+(Similarly, Shift-F12 produces a `nodes.xml` for the document model dump, but
+it's unlikely that you'll need that in a unit test.)
+
 == Export tests
 
 Export tests are similar. Given that test documents are easier to provide in
@@ -34,14 +37,13 @@ most cases, we will do an import, then do an export (to invoke the code we want
 to test) and then do an import again, so we can do the testing by asserting the
 document model, just like we did for import tests.
 
-Yes, this means that you can test the export code (using this framework) if the
-importer is working correctly. (But that's not so bad, users usually expect a
-feature to work in both the importer and the exporter.)
+Yes, this means that you can only test the export code (using this framework)
+if the importer is working correctly. (But that's not so bad, users usually
+expect a feature to work in both the importer and the exporter.)
 
 The only difference is that in these tests the test method is called twice:
 once after the initial import -- so you can see if the export fails due to an
-import problem in fact -- and once after the export and import.  The test
-method should still assert the document model only, as discussed above.
+import problem in fact -- and once after the export and import.
 
 === Direct XPath assertions
 
@@ -49,14 +51,12 @@ An other alternative is to assert the resulted export document directly.
 Currently this is only implemented for DOCX, which is a zipped XML, so it's
 possible to evaluate XPath checks. A check looks like this:
 
-xmlDocPtr pXmlDoc = parseExport("word/document.xml");
-if (!pXmlDoc)
-    return;
-assertXPath(pXmlDoc, <xpath selecting the node>, <attribute>, <value>);
+if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
+    assertXPath(pXmlDoc, <xpath selecting the node>, <attribute>, <value>);
 
 It's important to check for the NULL pointer here, it's expected that it'll be
 NULL when the test runs first (after the first import), as there is nothing
-exported yet.
+exported yet. For other XPath assert variants, see the `XmlTestTools` class.
 
 == Helper methods
 
@@ -115,7 +115,7 @@ develop quickly.
 With some experimenting, you'll end up with something like this:
 
 ----
-oStyle = ThisComponent.StyleFamilies.PageStyles.Default
+oStyle = ThisComponent.StyleFamilies.PageStyles.getByName("Default Style")
 xray oStyle.IsLandscape
 ----
 
@@ -124,14 +124,8 @@ when later this test fails for some reason. In cpp, you typically need to be
 more verbose, so the code will look like:
 
 ----
-uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, uno::UNO_QUERY);
-uno::Reference<container::XNameAccess> xStyles(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
-uno::Reference<container::XNameAccess> xPageStyles(xStyles->getByName("PageStyles"), uno::UNO_QUERY);
-uno::Reference<beans::XPropertySet> xStyle(xPageStyles->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
-
-sal_Bool bIsLandscape = sal_False;
-xStyle->getPropertyValue("IsLandscape") >>= bIsLandscape;
-CPPUNIT_ASSERT_EQUAL(sal_True, bIsLandscape);
+uno::Reference<beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(true, getProperty<bool>(xStyle, "IsLandscape"));
 ----
 
 == UNO, in more details, various tips:
@@ -253,15 +247,9 @@ page width:
 
 Basic:
 
-ThisComponent.StyleFamilies.PageStyles.Default.Width
+ThisComponent.StyleFamilies.PageStyles.getByName("Default Style").Width
 
 C++:
 
-uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
-uno::Reference<style::XStyleFamiliesSupplier> styleFamiliesSupplier(mxComponent, uno::UNO_QUERY);
-uno::Reference<container::XNameAccess> styleFamilies = styleFamiliesSupplier->getStyleFamilies();
-uno::Reference<container::XNameAccess> pageStyles;
-styleFamilies->getByName("PageStyles") >>= pageStyles;
-uno::Reference<uno::XInterface> defaultStyle;
-pageStyles->getByName(DEFAULT_STYLE) >>= defaultStyle;
+getStyles("PageStyles")->getByName(DEFAULT_STYLE) >>= defaultStyle;
 sal_Int32 width = getProperty< sal_Int32 >( defaultStyle, "Width" );
commit db31cc0eadf22b268300a23343d58a267065687b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 10 17:42:11 2014 +0200

    CppunitTest_sw_ooxmlexport / testSdt2Run: one more assert
    
    Change-Id: Ic5f2f86992c91b054d4db18174396bd2480f639b

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 796439c..4c48e95 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3748,6 +3748,8 @@ DECLARE_OOXMLEXPORT_TEST(testSdt2Run, "sdt-2-run.docx")
     // The problem was that <w:sdt> was closed after "first", not after "second", so the second assert failed.
     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r[1]/w:t", "first");
     assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r[2]/w:t", "second");
+    // Make sure the third portion is still outside <w:sdt>.
+    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/w:t", "third");
 }
 
 DECLARE_OOXMLEXPORT_TEST(testSdtAlias, "sdt-alias.docx")
commit ef01eef6165defc6850fda6a557549e6d34c43f1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 10 15:55:44 2014 +0200

    DOCX export: handle character format of dateTime SDT
    
    The trick is that this logic has been already implemented for table
    styles, so just reuse that.
    
    Change-Id: I5b094fece244da8cf0857ce829a54aa7c124e280

diff --git a/sw/qa/extras/ooxmlexport/data/sdt-date-charformat.docx b/sw/qa/extras/ooxmlexport/data/sdt-date-charformat.docx
new file mode 100644
index 0000000..22c4d4e
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/sdt-date-charformat.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index d156805..796439c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -3760,6 +3760,13 @@ DECLARE_OOXMLEXPORT_TEST(testSdtAlias, "sdt-alias.docx")
     assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:alias", "val", "Subtitle");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testSdtDateCharformat, "sdt-date-charformat.docx")
+{
+    if (xmlDocPtr pXmlDoc = parseExport())
+        // character formatting (bold) was missing, this was 0
+        assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:rPr/w:b", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 2026ddd..ddd2379 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4204,6 +4204,7 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
                 OUString sLocale("en-US");
                 uno::Sequence<beans::PropertyValue> aGrabBag;
                 uno::Reference<beans::XPropertySet> xShapePropertySet(pFormObj->getUnoShape(), uno::UNO_QUERY);
+                uno::Sequence<beans::PropertyValue> aCharFormat;
                 if (xShapePropertySet->getPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG) >>= aGrabBag)
                 {
                     for (sal_Int32 i=0; i < aGrabBag.getLength(); ++i)
@@ -4222,6 +4223,8 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
                             aOriginalDate.SetMonth(aUNODate.Month);
                             aOriginalDate.SetYear(aUNODate.Year);
                         }
+                        else if (aGrabBag[i].Name == "CharFormat")
+                            aGrabBag[i].Value >>= aCharFormat;
                     }
                 }
                 uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
@@ -4282,6 +4285,13 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
 
                 m_pSerializer->startElementNS(XML_w, XML_sdtContent, FSEND);
                 m_pSerializer->startElementNS(XML_w, XML_r, FSEND);
+
+                if (aCharFormat.hasElements())
+                {
+                    m_pTableStyleExport->SetSerializer(m_pSerializer);
+                    m_pTableStyleExport->CharFormat(aCharFormat);
+                }
+
                 RunText(aContentText);
                 m_pSerializer->endElementNS(XML_w, XML_r);
                 m_pSerializer->endElementNS(XML_w, XML_sdtContent);
diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx
index c080ba0..e431da9 100644
--- a/sw/source/filter/ww8/docxtablestyleexport.cxx
+++ b/sw/source/filter/ww8/docxtablestyleexport.cxx
@@ -67,6 +67,11 @@ struct DocxTableStyleExport::Impl
     void tableStyleRColor(uno::Sequence<beans::PropertyValue>& rColor);
 };
 
+void DocxTableStyleExport::CharFormat(css::uno::Sequence<css::beans::PropertyValue>& rRPr)
+{
+    m_pImpl->tableStyleRPr(rRPr);
+}
+
 void DocxTableStyleExport::TableStyles(sal_uInt16 nCountStylesToWrite)
 {
     // Do we have table styles from InteropGrabBag available?
diff --git a/sw/source/filter/ww8/docxtablestyleexport.hxx b/sw/source/filter/ww8/docxtablestyleexport.hxx
index f506ae3..78d5209 100644
--- a/sw/source/filter/ww8/docxtablestyleexport.hxx
+++ b/sw/source/filter/ww8/docxtablestyleexport.hxx
@@ -11,6 +11,9 @@
 #define INCLUDED_SW_SOURCE_FILTER_WW8_DOCXTABLESTYLEEXPORT_HXX
 
 #include <boost/shared_ptr.hpp>
+
+#include <com/sun/star/beans/PropertyValue.hpp>
+
 #include <sax/fshelper.hxx>
 
 class SwDoc;
@@ -22,6 +25,10 @@ class DocxTableStyleExport
     boost::shared_ptr<Impl> m_pImpl;
 public:
     void TableStyles(sal_uInt16 nCountStylesToWrite);
+
+    /// Writes <w:rPr>...</w:rPr> based on grab-bagged character properties.
+    void CharFormat(css::uno::Sequence<css::beans::PropertyValue>& rRPr);
+
     void SetSerializer(sax_fastparser::FSHelperPtr pSerializer);
     DocxTableStyleExport(SwDoc* pDoc, sax_fastparser::FSHelperPtr pSerializer);
     ~DocxTableStyleExport();
commit 06a39e43296d76097ad5288c0e8b9e2869e6644e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 10 15:12:46 2014 +0200

    DOCX import: handle character format of dateTime SDT
    
    Change-Id: Ia8966745b1ed63ae7de2ad0d673faff8b8804d63

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 8f0d765..4804131 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -2673,6 +2673,10 @@ void DomainMapper::lcl_startCharacterGroup()
         m_pImpl->GetTopContext()->Insert(PROP_SDT_END_BEFORE, uno::makeAny(true), true, CHAR_GRAB_BAG);
         m_pImpl->setSdtEndDeferred(false);
     }
+
+    // Remember formatting of the date control as it only supports plain strings natively.
+    if (!m_pImpl->m_pSdtHelper->getDateFormat().isEmpty())
+        enableInteropGrabBag("CharFormat");
 }
 
 void DomainMapper::lcl_endCharacterGroup()
@@ -2785,7 +2789,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len)
          * create the control early, as in Writer, it's part of the cell, but
          * in OOXML, the sdt contains the cell.
          */
-        m_pImpl->m_pSdtHelper->createDateControl(sText);
+        m_pImpl->m_pSdtHelper->createDateControl(sText, getInteropGrabBag());
         return;
     }
     else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty())
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index 84f6090..14ad767 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -92,7 +92,7 @@ void SdtHelper::createDropDownControl()
     m_aDropDownItems.clear();
 }
 
-void SdtHelper::createDateControl(OUString& rContentText)
+void SdtHelper::createDateControl(OUString& rContentText, beans::PropertyValue aCharFormat)
 {
     uno::Reference<awt::XControlModel> xControlModel(m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.form.component.DateField"), uno::UNO_QUERY);
     uno::Reference<beans::XPropertySet> xPropertySet(xControlModel, uno::UNO_QUERY);
@@ -122,7 +122,7 @@ void SdtHelper::createDateControl(OUString& rContentText)
         xPropertySet->setPropertyValue("HelpText", uno::makeAny(rContentText));
 
     // append date format to grab bag
-    uno::Sequence<beans::PropertyValue> aGrabBag(4);
+    uno::Sequence<beans::PropertyValue> aGrabBag(5);
     aGrabBag[0].Name = "OriginalDate";
     aGrabBag[0].Value = uno::makeAny(aDate);
     aGrabBag[1].Name = "OriginalContent";
@@ -131,6 +131,7 @@ void SdtHelper::createDateControl(OUString& rContentText)
     aGrabBag[2].Value = uno::makeAny(sDateFormat);
     aGrabBag[3].Name = "Locale";
     aGrabBag[3].Value = uno::makeAny(m_sLocale.makeStringAndClear());
+    aGrabBag[4] = aCharFormat;
 
     std::vector<OUString> aItems;
     createControlShape(lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), rContentText, aItems), xControlModel, aGrabBag);
diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx
index 5f5f81d..08f87a4 100644
--- a/writerfilter/source/dmapper/SdtHelper.hxx
+++ b/writerfilter/source/dmapper/SdtHelper.hxx
@@ -98,7 +98,7 @@ public:
     /// Create drop-down control from w:sdt's w:dropDownList.
     void createDropDownControl();
     /// Create date control from w:sdt's w:date.
-    void createDateControl(OUString& rContentText);
+    void createDateControl(OUString& rContentText, css::beans::PropertyValue aCharFormat);
 
     void appendToInteropGrabBag(com::sun::star::beans::PropertyValue rValue);
     com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> getInteropGrabBagAndClear();


More information about the Libreoffice-commits mailing list