summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/PythonTest_sw_python.mk1
-rw-r--r--sw/qa/python/check_styles.py107
-rw-r--r--sw/source/core/unocore/unostyle.cxx15
3 files changed, 115 insertions, 8 deletions
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 52907c1f0041..695bbf9dd5ce 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -16,6 +16,7 @@ $(eval $(call gb_PythonTest_set_defs,sw_python,\
$(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_index \
check_fields \
+ check_styles \
check_table \
get_expression \
set_expression \
diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
new file mode 100644
index 000000000000..a9b0c8159e33
--- /dev/null
+++ b/sw/qa/python/check_styles.py
@@ -0,0 +1,107 @@
+#! /usr/bin/env python
+# -*- Mode: python; 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/.
+#
+import math
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.container import NoSuchElementException
+from com.sun.star.lang import IndexOutOfBoundsException
+
+
+class CheckStyle(unittest.TestCase):
+ _uno = None
+ @classmethod
+ def setUpClass(cls):
+ cls._uno = UnoInProcess()
+ cls._uno.setUp()
+ @classmethod
+ def tearDownClass(cls):
+ cls._uno.tearDown()
+ def test_StyleFamilies(self):
+ xDoc = CheckStyle._uno.openEmptyWriterDoc()
+ xStyleFamilies = xDoc.StyleFamilies
+ self.assertEqual(xStyleFamilies.ImplementationName, "SwXStyleFamilies")
+ self.assertEqual(len(xStyleFamilies.SupportedServiceNames), 1)
+ for servicename in xStyleFamilies.SupportedServiceNames:
+ self.assertIn(servicename, ["com.sun.star.style.StyleFamilies"] )
+ self.assertTrue(xStyleFamilies.supportsService(servicename))
+ self.assertFalse(xStyleFamilies.supportsService("foobarbaz"))
+ self.assertTrue(xStyleFamilies.hasElements())
+ self.assertRegex(str(xStyleFamilies.ElementType), "com\.sun\.star\.container\.XNameContainer")
+ self.assertEqual(len(xStyleFamilies.ElementNames), 5)
+ for sFamilyname in xStyleFamilies.ElementNames:
+ self.assertIn(sFamilyname, ["CharacterStyles", "ParagraphStyles", "PageStyles", "FrameStyles", "NumberingStyles"])
+ with self.assertRaises(NoSuchElementException):
+ xStyleFamilies.getByName("foobarbaz")
+ xDoc.dispose()
+ def __test_StyleFamily(self, xFamily, vExpectedNames):
+ self.assertEqual(xFamily.ImplementationName, "XStyleFamily")
+ self.assertEqual(len(xFamily.SupportedServiceNames), 1)
+ for sServicename in xFamily.SupportedServiceNames:
+ self.assertIn(sServicename, ["com.sun.star.style.StyleFamily"] )
+ self.assertTrue(xFamily.supportsService(sServicename))
+ self.assertFalse(xFamily.supportsService("foobarbaz"))
+ self.assertTrue(xFamily.hasElements())
+ self.assertRegex(str(xFamily.ElementType), "com\.sun\.star\.style\.XStyle")
+ with self.assertRaises(NoSuchElementException):
+ xFamily.getByName("foobarbaz")
+ with self.assertRaises(IndexOutOfBoundsException):
+ xFamily.getByIndex(-1)
+ for sStylename in xFamily.ElementNames:
+ self.assertTrue(xFamily.hasByName(sStylename))
+ self.assertEqual(xFamily[sStylename].ImplementationName, "SwXStyle")
+ vExpectedNames.sort()
+ vNames = list(xFamily.ElementNames)
+ vNames.sort()
+ self.assertListEqual(vNames, vExpectedNames)
+ def __test_StyleFamilyIndex(self, xFamily, vExpectedNames):
+ self.assertEqual(xFamily.Count, len(vExpectedNames))
+ for nIndex in range(xFamily.Count):
+ xStyle = xFamily.getByIndex(nIndex)
+ self.assertEqual(xStyle.ImplementationName, "SwXStyle")
+ self.assertIn(xStyle.Name, vExpectedNames)
+ 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)
+ xDoc.dispose()
+ def test_ParagraphFamily(self):
+ xDoc = CheckStyle._uno.openEmptyWriterDoc()
+ xParaStyles = xDoc.StyleFamilies["ParagraphStyles"]
+ 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 End', '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)
+ xDoc.dispose()
+ def test_PageFamily(self):
+ xDoc = CheckStyle._uno.openEmptyWriterDoc()
+ xPageStyles = xDoc.StyleFamilies["PageStyles"]
+ vEmptyDocStyles = ['Standard', 'First Page', 'Left Page', 'Right Page', 'Envelope', 'Index', 'HTML', 'Footnote', 'Endnote', 'Landscape']
+ self.__test_StyleFamily(xPageStyles, vEmptyDocStyles)
+ self.__test_StyleFamilyIndex(xPageStyles, vEmptyDocStyles)
+ xDoc.dispose()
+ def test_FrameFamily(self):
+ xDoc = CheckStyle._uno.openEmptyWriterDoc()
+ xFrameStyles = xDoc.StyleFamilies["FrameStyles"]
+ vEmptyDocStyles = ['Formula', 'Frame', 'Graphics', 'Labels', 'Marginalia', 'OLE', 'Watermark']
+ self.__test_StyleFamily(xFrameStyles, vEmptyDocStyles)
+ self.__test_StyleFamilyIndex(xFrameStyles, vEmptyDocStyles)
+ xDoc.dispose()
+ def test_NumberingFamily(self):
+ xDoc = CheckStyle._uno.openEmptyWriterDoc()
+ xNumberingStyles = xDoc.StyleFamilies["NumberingStyles"]
+ 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)
+ xDoc.dispose()
+if __name__ == '__main__':
+ unittest.main()
+
+# /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index d789611f3c21..f8fe8d1905be 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -398,7 +398,7 @@ static sal_Int32 lcl_GetCountOrName(const SwDoc&, OUString*, sal_Int32);
template<>
sal_Int32 lcl_GetCountOrName<SFX_STYLE_FAMILY_CHAR>(const SwDoc& rDoc, OUString* pString, sal_Int32 nIndex)
{
- const sal_uInt16 nBaseCount = nPoolChrHtmlRange + nPoolCollTextRange;
+ const sal_uInt16 nBaseCount = nPoolChrHtmlRange + nPoolChrNormalRange;
nIndex -= nBaseCount;
sal_Int32 nCount = 0;
for(auto pFormat : *rDoc.GetCharFormats())
@@ -529,7 +529,7 @@ sal_uInt16 lcl_TranslateIndex<SFX_STYLE_FAMILY_CHAR>(const sal_uInt16 nIndex)
if(nIndex < nPoolChrNormalRange)
return nIndex + RES_POOLCHR_NORMAL_BEGIN;
else if(nIndex < (nPoolChrHtmlRange+nPoolChrNormalRange))
- return nIndex + RES_POOLCHR_HTML_BEGIN + nPoolChrNormalRange;
+ return nIndex + RES_POOLCHR_HTML_BEGIN - nPoolChrNormalRange;
throw lang::IndexOutOfBoundsException();
}
@@ -540,15 +540,15 @@ sal_uInt16 lcl_TranslateIndex<SFX_STYLE_FAMILY_PARA>(const sal_uInt16 nIndex)
if(nIndex < nPoolCollListsStackedStart)
return nIndex + RES_POOLCOLL_TEXT_BEGIN;
else if(nIndex < nPoolCollExtraStackedStart)
- return nIndex + RES_POOLCOLL_LISTS_BEGIN + nPoolCollListsStackedStart;
+ return nIndex + RES_POOLCOLL_LISTS_BEGIN - nPoolCollListsStackedStart;
else if(nIndex < nPoolCollRegisterStackedStart)
- return nIndex + RES_POOLCOLL_EXTRA_BEGIN + nPoolCollExtraStackedStart;
+ return nIndex + RES_POOLCOLL_EXTRA_BEGIN - nPoolCollExtraStackedStart;
else if(nIndex < nPoolCollDocStackedStart)
- return nIndex + RES_POOLCOLL_REGISTER_BEGIN + nPoolCollRegisterStackedStart;
+ return nIndex + RES_POOLCOLL_REGISTER_BEGIN - nPoolCollRegisterStackedStart;
else if(nIndex < nPoolCollHtmlStackedStart)
- return nIndex + RES_POOLCOLL_DOC_BEGIN + nPoolCollDocStackedStart;
+ return nIndex + RES_POOLCOLL_DOC_BEGIN - nPoolCollDocStackedStart;
else if(nIndex < nPoolCollHtmlStackedStart + nPoolCollTextRange)
- return nIndex + RES_POOLCOLL_HTML_BEGIN + nPoolCollHtmlStackedStart;
+ return nIndex + RES_POOLCOLL_HTML_BEGIN - nPoolCollHtmlStackedStart;
throw lang::IndexOutOfBoundsException();
}
@@ -575,7 +575,6 @@ uno::Any XStyleFamily::getByIndex(sal_Int32 nIndex)
} catch(...) {}
if (sStyleName.isEmpty())
GetCountOrName(&sStyleName, nIndex);
-
if(sStyleName.isEmpty())
throw lang::IndexOutOfBoundsException();
return getByName(sStyleName);