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

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Fri Dec 11 16:41:01 PST 2015


 sw/qa/python/check_styles.py        |   37 +++++++++
 sw/source/core/unocore/unostyle.cxx |  147 ++++++++++--------------------------
 2 files changed, 79 insertions(+), 105 deletions(-)

New commits:
commit 37d735b27477cc1b72063b0ef307a437fa5233a1
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 12 01:23:46 2015 +0100

    replace homegrown map with std::map<>
    
    Change-Id: I5f35e0aeb6cef5920891eaa338c1d9b29e0ce554

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 9a54091..7eb0e94 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -755,114 +755,52 @@ static const std::vector<StyleFamilyEntry>* lcl_GetStyleFamilyEntries()
 class SwStyleProperties_Impl
 {
     const PropertyEntryVector_t aPropertyEntries;
-    uno::Any**                  pAnyArr;
-    sal_uInt32                  nArrLen;
-
+    std::map<OUString, uno::Any> m_vPropertyValues;
 public:
-    explicit SwStyleProperties_Impl(const SfxItemPropertyMap& rMap);
-    ~SwStyleProperties_Impl();
-
-    bool    SetProperty(const OUString& rName, const uno::Any& rVal);
-    bool    GetProperty(const OUString& rName, uno::Any*& rpAny);
-    bool    ClearProperty( const OUString& rPropertyName );
-    void    ClearAllProperties( );
-    static void GetProperty(const OUString &rPropertyName, const uno::Reference < beans::XPropertySet > &rxPropertySet, uno::Any& rAny );
-
-    const PropertyEntryVector_t& GetPropertyVector() const {return aPropertyEntries; }
-
-};
-
-SwStyleProperties_Impl::SwStyleProperties_Impl(const SfxItemPropertyMap& rMap) :
-    aPropertyEntries( rMap.getPropertyEntries() ),
-    nArrLen(0)
-{
-    nArrLen = aPropertyEntries.size();
-
-    pAnyArr = new uno::Any* [nArrLen];
-    for ( sal_uInt32 i =0 ; i < nArrLen; i++ )
-        pAnyArr[i] = nullptr;
-}
-
-SwStyleProperties_Impl::~SwStyleProperties_Impl()
-{
-    for ( sal_uInt32 i =0 ; i < nArrLen; i++ )
-        delete pAnyArr[i];
-    delete[] pAnyArr;
-}
+    explicit SwStyleProperties_Impl(const SfxItemPropertyMap& rMap)
+        : aPropertyEntries(rMap.getPropertyEntries())
+    { }
+    ~SwStyleProperties_Impl()
+    { }
 
-bool SwStyleProperties_Impl::SetProperty(const OUString& rName, const uno::Any& rVal)
-{
-    sal_uInt32 nPos = 0;
-    bool bRet = false;
-    PropertyEntryVector_t::const_iterator aIt = aPropertyEntries.begin();
-    while( aIt != aPropertyEntries.end() )
+    bool AllowsKey(const OUString& rName)
     {
-        if(rName == aIt->sName)
-        {
-            delete pAnyArr[nPos];
-            pAnyArr[nPos] = new uno::Any(rVal);
-            bRet = true;
-            break;
-        }
-        ++nPos;
-        ++aIt;
+        return aPropertyEntries.end() != std::find_if(aPropertyEntries.begin(), aPropertyEntries.end(),
+            [rName] (const SfxItemPropertyNamedEntry& rEntry) {return rName == rEntry.sName;} );
     }
-    return bRet;
-}
-
-bool SwStyleProperties_Impl::ClearProperty( const OUString& rName )
-{
-    bool bRet = false;
-    sal_uInt32 nPos = 0;
-    PropertyEntryVector_t::const_iterator aIt = aPropertyEntries.begin();
-    while( aIt != aPropertyEntries.end() )
+    bool SetProperty(const OUString& rName, const uno::Any& rValue)
     {
-        if( rName == aIt->sName )
+        if(!AllowsKey(rName))
+            return false;
+        m_vPropertyValues[rName] = rValue;
+        return true;
+    }
+    bool GetProperty(const OUString& rName, const uno::Any*& pAny)
+    {
+        if(!AllowsKey(rName))
         {
-            delete pAnyArr[nPos];
-            pAnyArr[ nPos ] = nullptr;
-            bRet = true;
-            break;
+            pAny = nullptr;
+            return false;
         }
-        ++nPos;
-        ++aIt;
+        pAny = &m_vPropertyValues[rName];
+        return true;
     }
-    return bRet;
-}
-
-void SwStyleProperties_Impl::ClearAllProperties( )
-{
-    for ( sal_uInt32 i = 0; i < nArrLen; i++ )
+    bool ClearProperty( const OUString& rName )
     {
-        delete pAnyArr[i];
-        pAnyArr[ i ] = nullptr;
+        if(!AllowsKey(rName))
+            return false;
+        m_vPropertyValues[rName] = uno::Any();
+        return true;
     }
-}
-
-bool SwStyleProperties_Impl::GetProperty(const OUString& rName, uno::Any*& rpAny )
-{
-    bool bRet = false;
-    sal_uInt32 nPos = 0;
-    PropertyEntryVector_t::const_iterator aIt = aPropertyEntries.begin();
-    while( aIt != aPropertyEntries.end() )
+    void ClearAllProperties( )
+            { m_vPropertyValues.clear(); }
+    static void GetProperty(const OUString &rPropertyName, const uno::Reference < beans::XPropertySet > &rxPropertySet, uno::Any& rAny )
     {
-        if( rName == aIt->sName )
-        {
-            rpAny = pAnyArr[nPos];
-            bRet = true;
-            break;
-        }
-        ++nPos;
-        ++aIt;
+        rAny = rxPropertySet->getPropertyValue( rPropertyName );
     }
-
-    return bRet;
-}
-
-void SwStyleProperties_Impl::GetProperty( const OUString &rPropertyName, const uno::Reference < beans::XPropertySet > &rxPropertySet, uno::Any & rAny )
-{
-    rAny = rxPropertySet->getPropertyValue( rPropertyName );
-}
+    const PropertyEntryVector_t& GetPropertyVector() const
+            { return aPropertyEntries; }
+};
 
 static SwGetPoolIdFromName lcl_GetSwEnumFromSfxEnum(SfxStyleFamily eFamily)
 {
@@ -1287,9 +1225,9 @@ void    SwXStyle::ApplyDescriptorProperties()
     PropertyEntryVector_t::const_iterator aIt = rPropertyVector.begin();
     while(aIt != rPropertyVector.end())
     {
-        uno::Any* pAny(nullptr);
+        const uno::Any* pAny(nullptr);
         m_pPropertiesImpl->GetProperty(aIt->sName, pAny);
-        if (pAny)
+        if(pAny->hasValue())
             setPropertyValue(aIt->sName, *pAny);
         ++aIt;
     }
@@ -2423,9 +2361,9 @@ uno::Sequence< uno::Any > SAL_CALL SwXStyle::GetPropertyValues_Impl(
         }
         else if(m_bIsDescriptor)
         {
-            uno::Any *pAny = nullptr;
-            m_pPropertiesImpl->GetProperty ( pNames[nProp], pAny );
-            if( !pAny )
+            const uno::Any* pAny = nullptr;
+            m_pPropertiesImpl->GetProperty(pNames[nProp], pAny);
+            if(!pAny->hasValue())
             {
                 bool bExcept = false;
                 switch( m_eFamily )
@@ -3667,10 +3605,9 @@ uno::Sequence< uno::Any > SAL_CALL SwXPageStyle::GetPropertyValues_Impl(
         }
         else if(IsDescriptor())
         {
-            uno::Any* pAny = nullptr;
+            const uno::Any* pAny = nullptr;
             GetPropImpl()->GetProperty(rPropName, pAny);
-
-            if ( !pAny )
+            if (!pAny->hasValue())
             {
                 SwStyleProperties_Impl::GetProperty(rPropName, mxStyleData, pRet[nProp]);
             }
commit dd58c7892b1b4162662962d27c07b4d3d459939f
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Dec 11 03:19:16 2015 +0100

    use preincrement here for grace
    
    Change-Id: I7141510fbda1158511698f73c48274008f0a41dc

diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index f8fe8d1..9a54091 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -459,7 +459,7 @@ sal_Int32 lcl_GetCountOrName<SFX_STYLE_FAMILY_FRAME>(const SwDoc& rDoc, OUString
             *pString = pFormat->GetName();
             break;
         }
-        nCount++;
+        ++nCount;
     }
     return nCount + nPoolFrameRange;
 }
commit ddb248507f8266acdbd672eb84f51f5658f37410
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Dec 11 03:17:22 2015 +0100

    writer UNO style families: test insert/replace ops
    
    Change-Id: I5a8daa1c0f2b62dbf56fa9fc1d14555f0ff613e2

diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index c790490..d300372 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -12,6 +12,7 @@ import unittest
 from org.libreoffice.unotest import UnoInProcess
 from com.sun.star.container import NoSuchElementException
 from com.sun.star.lang import IndexOutOfBoundsException
+from com.sun.star.lang import IllegalArgumentException
 
 
 class CheckStyle(unittest.TestCase):
@@ -68,12 +69,42 @@ class CheckStyle(unittest.TestCase):
             self.assertEqual(xStyle.ImplementationName, "SwXStyle")
             self.assertIn(xStyle.Name, vExpectedNames)
             self.assertFalse(xStyle.isUserDefined())
+    def __test_StyleFamilyInsert(self, xDoc, xFamily, vExpectedNames, sRightStyle, sWrongStyle):
+        xRightStyle = xDoc.createInstance(sRightStyle)
+        xRightStyle.Name = "RightStyleOld"
+        xWrongStyle = xDoc.createInstance(sWrongStyle)
+        xWrongStyle.Name = "WrongtStyleOld"
+        xFamily.insertByName("RightStyle", xRightStyle)
+        self.assertEqual(xRightStyle.Name, "RightStyle")
+        self.assertTrue(xRightStyle.isUserDefined())
+        self.assertEqual(xFamily[xRightStyle.Name], xRightStyle)
+        self.assertNotEqual(xFamily[xRightStyle.Name], xWrongStyle)
+        self.assertTrue(xFamily[xRightStyle.Name].isUserDefined())
+        xRightStyle2 = xDoc.createInstance(sRightStyle)
+        xRightStyle2.Name = "RightStyle2Old"
+        xFamily.replaceByName("RightStyle", xRightStyle2)
+        self.assertEqual(xRightStyle2.Name, "RightStyle")
+        self.assertEqual(xFamily[xRightStyle2.Name], xRightStyle2)
+        xFamily.removeByName(xRightStyle2.Name)
+        with self.assertRaises(NoSuchElementException):
+            nope = xFamily.getByName("RightStyleOld")
+        with self.assertRaises(NoSuchElementException):
+            nope = xFamily.getByName("RightStyle")
+        with self.assertRaises(NoSuchElementException):
+            nope = xFamily.getByName("RightStyle2Old")
+        with self.assertRaises(NoSuchElementException):
+            nope = xFamily.getByName("RightStyle2")
+        with self.assertRaises(IllegalArgumentException):
+            xFamily.insertByName("WrongStyle", xWrongStyle)
+        with self.assertRaises(NoSuchElementException):
+            nope = xFamily.getByName("WrongStyle")
     def test_CharacterFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xCharStyles = xDoc.StyleFamilies["CharacterStyles"]
         vEmptyDocStyles = ['Default Style', 'Footnote Symbol', 'Page Number', 'Caption characters', 'Drop Caps', 'Numbering Symbols', 'Bullet Symbols', 'Internet link', 'Visited Internet Link', 'Placeholder', 'Index Link', 'Endnote Symbol', 'Line numbering', 'Main index entry', 'Footnote anchor', 'Endnote anchor', 'Rubies', 'Vertical Numbering Symbols', 'Emphasis', 'Citation', 'Strong Emphasis', 'Source Text', 'Example', 'User Entry', 'Variable', 'Definition', 'Teletype']
         self.__test_StyleFamily(xCharStyles, vEmptyDocStyles)
         self.__test_StyleFamilyIndex(xCharStyles, vEmptyDocStyles)
+        self.__test_StyleFamilyInsert(xDoc, xCharStyles, vEmptyDocStyles, "com.sun.star.style.CharacterStyle", "com.sun.star.style.ParagraphStyle")
         xDoc.dispose()
     def test_ParagraphFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
@@ -81,6 +112,7 @@ class CheckStyle(unittest.TestCase):
         vEmptyDocStyles = ['Standard', 'Heading', 'Text body', 'List', 'Caption', 'Index', 'First line indent', 'Hanging indent', 'Text body indent', 'Salutation', 'Signature', 'List Indent', 'Marginalia', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Heading 5', 'Heading 6', 'Heading 7', 'Heading 8', 'Heading 9', 'Heading 10', 'Title', 'Subtitle', 'Numbering 1 Start', 'Numbering 1', 'Numbering 1 End', 'Numbering 1 Cont.', 'Numbering 2 Start', 'Numbering 2', 'Numbering 2 End', 'Numbering 2 Cont.', 'Numbering 3 Start', 'Numbering 3', 'Numbering 3 End', 'Numbering 3 Cont.', 'Numbering 4 Start', 'Numbering 4', 'Numbering 4 End', 'Numbering 4 Cont.', 'Numbering 5 Start', 'Numbering 5', 'Numbering 5 End', 'Numbering 5 Cont.', 'List 1 Start', 'List 1', 'List 1 End', 'List 1 Cont.', 'List 2 Start', 'List 2', 'List 2 End', 'List 2 Cont.', 'List 3 Start', 'List 3', 'List 3 End', 'List 3 Cont.', 'List 4 Start', 'List 4', 'List 4 End', 'List 4 Cont.', 'List 5 Start', 'List 5', 'List 5 E
 nd', 'List 5 Cont.', 'Index Heading', 'Index 1', 'Index 2', 'Index 3', 'Index Separator', 'Contents Heading', 'Contents 1', 'Contents 2', 'Contents 3', 'Contents 4', 'Contents 5', 'User Index Heading', 'User Index 1', 'User Index 2', 'User Index 3', 'User Index 4', 'User Index 5', 'Contents 6', 'Contents 7', 'Contents 8', 'Contents 9', 'Contents 10', 'Illustration Index Heading', 'Illustration Index 1', 'Object index heading', 'Object index 1', 'Table index heading', 'Table index 1', 'Bibliography Heading', 'Bibliography 1', 'User Index 6', 'User Index 7', 'User Index 8', 'User Index 9', 'User Index 10', 'Header', 'Header left', 'Header right', 'Footer', 'Footer left', 'Footer right', 'Table Contents', 'Table Heading', 'Illustration', 'Table', 'Text', 'Frame contents', 'Footnote', 'Addressee', 'Sender', 'Endnote', 'Drawing', 'Quotations', 'Preformatted Text', 'Horizontal Line', 'List Contents', 'List Heading']
         self.__test_StyleFamily(xParaStyles, vEmptyDocStyles)
         self.__test_StyleFamilyIndex(xParaStyles, vEmptyDocStyles)
+        self.__test_StyleFamilyInsert(xDoc, xParaStyles, vEmptyDocStyles, "com.sun.star.style.ParagraphStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
     def test_PageFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
@@ -88,6 +120,7 @@ class CheckStyle(unittest.TestCase):
         vEmptyDocStyles = ['Standard', 'First Page', 'Left Page', 'Right Page', 'Envelope', 'Index', 'HTML', 'Footnote', 'Endnote', 'Landscape']
         self.__test_StyleFamily(xPageStyles, vEmptyDocStyles)
         self.__test_StyleFamilyIndex(xPageStyles, vEmptyDocStyles)
+        self.__test_StyleFamilyInsert(xDoc, xPageStyles, vEmptyDocStyles, "com.sun.star.style.PageStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
     def test_FrameFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
@@ -95,6 +128,7 @@ class CheckStyle(unittest.TestCase):
         vEmptyDocStyles = ['Formula', 'Frame', 'Graphics', 'Labels', 'Marginalia', 'OLE', 'Watermark']
         self.__test_StyleFamily(xFrameStyles, vEmptyDocStyles)
         self.__test_StyleFamilyIndex(xFrameStyles, vEmptyDocStyles)
+        self.__test_StyleFamilyInsert(xDoc, xFrameStyles, vEmptyDocStyles, "com.sun.star.style.FrameStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
     def test_NumberingFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
@@ -102,6 +136,7 @@ class CheckStyle(unittest.TestCase):
         vEmptyDocStyles = ['List 1', 'List 2', 'List 3', 'List 4', 'List 5', 'Numbering 1', 'Numbering 2', 'Numbering 3', 'Numbering 4', 'Numbering 5']
         self.__test_StyleFamily(xNumberingStyles, vEmptyDocStyles)
         self.__test_StyleFamilyIndex(xNumberingStyles, vEmptyDocStyles)
+        self.__test_StyleFamilyInsert(xDoc, xNumberingStyles, vEmptyDocStyles, "com.sun.star.style.NumberingStyle", "com.sun.star.style.CharacterStyle")
         xDoc.dispose()
 if __name__ == '__main__':
     unittest.main()
commit d275f367140aeb8ca9803ef4181fb5f860932ab3
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Dec 11 02:37:19 2015 +0100

    writer UNO style families: also check isUserDefined()
    
    Change-Id: Iada331a12232fd83b6813e6db65bd011d3746142

diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index a9b0c81..c790490 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -56,6 +56,7 @@ class CheckStyle(unittest.TestCase):
         for sStylename in xFamily.ElementNames:
             self.assertTrue(xFamily.hasByName(sStylename))
             self.assertEqual(xFamily[sStylename].ImplementationName, "SwXStyle")
+            self.assertFalse(xFamily[sStylename].isUserDefined())
         vExpectedNames.sort()
         vNames = list(xFamily.ElementNames)
         vNames.sort()
@@ -66,6 +67,7 @@ class CheckStyle(unittest.TestCase):
             xStyle = xFamily.getByIndex(nIndex)
             self.assertEqual(xStyle.ImplementationName, "SwXStyle")
             self.assertIn(xStyle.Name, vExpectedNames)
+            self.assertFalse(xStyle.isUserDefined())
     def test_CharacterFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xCharStyles = xDoc.StyleFamilies["CharacterStyles"]


More information about the Libreoffice-commits mailing list