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

2020-09-03 Thread Samuel Mehrbrodt (via logerrit)
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/check_drawpage.py |   44 +
 sw/source/core/unocore/unodraw.cxx |2 -
 3 files changed, 46 insertions(+), 1 deletion(-)

New commits:
commit 3eb5318ed9ae8cf02804fbdc584a5f4b046db0ae
Author: Samuel Mehrbrodt 
AuthorDate: Tue Sep 1 12:51:09 2020 +0200
Commit: Samuel Mehrbrodt 
CommitDate: Thu Sep 3 10:45:25 2020 +0200

tdf#136423 make SwXDrawPage::group work with a single shape

No reason this should not work (and the implementation in Draw/Impress/Calc
also works this way)

Change-Id: Ic5bc7420e9025b45ed848dccf68b112c0c6c2cd5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101842
Tested-by: Samuel Mehrbrodt 
Reviewed-by: Samuel Mehrbrodt 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index b1c96a5c26ab..d64a8b516563 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_bookmarks \
check_change_color \
+   check_drawpage \
check_index \
check_flies \
check_fields \
diff --git a/sw/qa/python/check_drawpage.py b/sw/qa/python/check_drawpage.py
new file mode 100644
index ..ef28490ce224
--- /dev/null
+++ b/sw/qa/python/check_drawpage.py
@@ -0,0 +1,44 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+
+from com.sun.star.text.TextContentAnchorType import AT_PARAGRAPH
+
+class CheckDrawPage(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+"""
+Test that grouping shapes also works with a single shape.
+"""
+def test_group_single_shape(self):
+xDoc = self.__class__._uno.openEmptyWriterDoc()
+page = xDoc.DrawPage
+collection = 
self.__class__._uno.xContext.ServiceManager.createInstance( 
'com.sun.star.drawing.ShapeCollection' )
+shape = xDoc.createInstance('com.sun.star.drawing.TextShape')
+shape.AnchorType = AT_PARAGRAPH
+page.add(shape)
+collection.add(shape)
+shapegroup = page.group(collection)
+
+self.assertEqual(shapegroup.Count, 1)
+
+xDoc.close(True)
+
+if __name__ == '__main__':
+unittest.main()
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index 7c7f84f4399b..8e280ea7179a 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -753,7 +753,7 @@ uno::Reference< drawing::XShapeGroup >  
SwXDrawPage::group(const uno::Reference<
 {
 // mark and return MarkList
 const SdrMarkList& rMarkList = pPage->PreGroup(xShapes);
-if ( rMarkList.GetMarkCount() > 1 )
+if ( rMarkList.GetMarkCount() > 0 )
 {
 for (size_t i = 0; i < rMarkList.GetMarkCount(); ++i)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2019-09-19 Thread Bjoern Michaelsen (via logerrit)
 sw/PythonTest_sw_python.mk |5 ++-
 sw/qa/python/check_range_properties.py |   44 +
 sw/qa/python/check_styles.py   |   10 ---
 3 files changed, 47 insertions(+), 12 deletions(-)

New commits:
commit 1cd495900883d1677670787669908535cd33babe
Author: Bjoern Michaelsen 
AuthorDate: Thu Sep 19 13:21:39 2019 +0200
Commit: Björn Michaelsen 
CommitDate: Thu Sep 19 19:59:37 2019 +0200

tdf#125307: move range properties check to own test

- the document styles tests seems mostly unrelated
- also: add bug reference in commit message subject, so that the
  bugzilla bot can do its shtick
- all the real work done already by Thomas Viehmann on commit
  2f679fd3e6f46df7cda77eb70a014bcfcac7df52

Change-Id: Ice5860c15c05fae37f0ba337d804de70acf3d936
Reviewed-on: https://gerrit.libreoffice.org/79132
Tested-by: Jenkins
Reviewed-by: Björn Michaelsen 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 8250da21dc6d..6e699f5caa1d 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -23,16 +23,17 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_cross_references \
check_named_property_values \
check_indexed_property_values \
+   check_range_properties \
check_styles \
-   check_xtexttable \
check_table \
check_xautotextcontainer \
check_xautotextgroup \
-   check_xmodifiable2 \
check_xmodel \
+   check_xmodifiable2 \
check_xnamedgraph \
check_xrefreshable \
check_xtextrangecompare \
+   check_xtexttable \
get_expression \
set_expression \
text_portion_enumeration_test \
diff --git a/sw/qa/python/check_range_properties.py 
b/sw/qa/python/check_range_properties.py
new file mode 100644
index ..1cac64028438
--- /dev/null
+++ b/sw/qa/python/check_range_properties.py
@@ -0,0 +1,44 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import math
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.container import NoSuchElementException
+from com.sun.star.beans import UnknownPropertyException
+from com.sun.star.lang import IndexOutOfBoundsException
+from com.sun.star.lang import IllegalArgumentException
+
+
+class CheckRangeProperties(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+# see tdf#125307
+def test_TextRangeProperties(self):
+xDoc = CheckRangeProperties._uno.openEmptyWriterDoc()
+xBodyText = xDoc.getText()
+xCursor = xBodyText.createTextCursor()
+xBodyText.insertString(xCursor, "Hello world", 0)
+xTextRange = list(xBodyText)[0]
+pnames = [p.Name for p in xTextRange.PropertySetInfo.Properties]
+xTextRange.getPropertyValues(pnames)
+xDoc.dispose()
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index cfd8a9e1bec1..8746c479fbbe 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -27,16 +27,6 @@ class CheckStyle(unittest.TestCase):
 def tearDownClass(cls):
 cls._uno.tearDown()
 
-def test_TextRangeProperties(self):
-xDoc = CheckStyle._uno.openEmptyWriterDoc()
-xBodyText = xDoc.getText()
-xCursor = xBodyText.createTextCursor()
-xBodyText.insertString(xCursor, "Hello world", 0)
-xTextRange = list(xBodyText)[0]
-pnames = [p.Name for p in xTextRange.PropertySetInfo.Properties]
-xTextRange.getPropertyValues(pnames)
-xDoc.dispose()
-
 def test_StyleFamilies(self):
 xDoc = CheckStyle._uno.openEmptyWriterDoc()
 xStyleFamilies = xDoc.StyleFamilies
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-11-22 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/testdocuments/xtextcursor.odt |binary
 sw/qa/python/xtextcursor.py|  107 +
 3 files changed, 108 insertions(+)

New commits:
commit 19923ea1d1608044e101b1875b47f6d4fbccf2d7
Author: Vasily Melenchuk 
AuthorDate: Fri Sep 28 13:53:46 2018 +0300
Commit: Thorsten Behrens 
CommitDate: Fri Nov 23 00:09:57 2018 +0100

sw: new unit test for XTextCursor

Change-Id: I5b70f6dc8f7399be78daefa95d6d98687d99ec18
Reviewed-on: https://gerrit.libreoffice.org/61098
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index ad479f527504..4f97724d835c 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -42,6 +42,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
xtextcontent \
xtextrange \
xtext \
+   xtextcursor \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextcursor.odt 
b/sw/qa/python/testdocuments/xtextcursor.odt
new file mode 100644
index ..1fdcfb9b77f9
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextcursor.odt differ
diff --git a/sw/qa/python/xtextcursor.py b/sw/qa/python/xtextcursor.py
new file mode 100644
index ..30d0518690a7
--- /dev/null
+++ b/sw/qa/python/xtextcursor.py
@@ -0,0 +1,107 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+import uno
+import time
+
+
+class TestXTextCursor(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+cls._uno.openDocFromTDOC("xtextcursor.odt")
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def createTextCursorInFrame(self, frameName):
+xTextFrames = self._uno.getDoc().getTextFrames()
+self.assertIsNotNone(xTextFrames)
+xTextFrame = xTextFrames[frameName]
+self.assertIsNotNone(xTextFrame)
+xCursor = xTextFrame.getText().createTextCursor()
+self.assertIsNotNone(xCursor)
+return xCursor
+
+def test_cursorMoveInText(self):
+# Create cursor in frame with simple text (to avoid moving beyond)
+xCursor = self.createTextCursorInFrame("FrameSimple")
+
+xCursor.collapseToStart()
+self.assertTrue(xCursor.isCollapsed())
+self.assertTrue(xCursor.goRight(1, True))
+self.assertFalse(xCursor.isCollapsed())
+# Try to move right 10 characters, but we really can just 3, so 
partial move
+self.assertFalse(xCursor.goRight(10, True))
+self.assertFalse(xCursor.isCollapsed())
+# Ensure that all line text is selected
+self.assertEqual(xCursor.getString(), "1234")
+
+self.assertFalse(xCursor.goRight(-10, True))
+self.assertEqual(xCursor.getString(), "1234")
+
+xCursor.collapseToEnd()
+self.assertTrue(xCursor.isCollapsed())
+self.assertTrue(xCursor.goLeft(2, True))
+self.assertFalse(xCursor.isCollapsed())
+self.assertEqual(xCursor.getString(), "34")
+
+# Move to start without selection
+self.assertTrue(xCursor.goLeft(2, False))
+self.assertEqual(xCursor.getString(), "")
+
+self.assertTrue(xCursor.isCollapsed())
+
+# Select all text
+xCursor.gotoStart(False)
+self.assertTrue(xCursor.isCollapsed())
+xCursor.gotoEnd(True)
+self.assertFalse(xCursor.isCollapsed())
+self.assertEqual(xCursor.getString(), "1234")
+
+# Select all text from behind
+xCursor.gotoEnd(False)
+self.assertTrue(xCursor.isCollapsed())
+xCursor.gotoStart(True)
+self.assertFalse(xCursor.isCollapsed())
+self.assertEqual(xCursor.getString(), "1234")
+
+# Select all text, alternative way via gotoRange
+xCursor2 = self.createTextCursorInFrame("FrameSimple")
+xCursor2.gotoEnd(False)
+xCursor2.gotoStart(True)
+xCursor.gotoEnd(False)
+self.assertTrue(xCursor.isCollapsed())
+xCursor.gotoRange(xCursor2, True)
+self.assertFalse(xCursor.isCollapsed())
+self.assertEqual(xCursor.getString(), "1234")
+
+def test_cursorMoveInTable(self):
+# Create cursor in frame with table
+xCursor = self.createTextCursorInFrame("FrameTable")
+
+# Nothing is selected
+xCursor.collapseToEnd()
+self.assertTrue(xCursor.isCollapsed())
+self.assertEqual(xCursor.getString(), "")

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-11-22 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/xtext.py  |   89 +
 2 files changed, 90 insertions(+)

New commits:
commit ba85d48c0384610829f6b0cfddd944da3cffeed7
Author: Vasily Melenchuk 
AuthorDate: Wed Oct 3 09:39:50 2018 +0300
Commit: Thorsten Behrens 
CommitDate: Fri Nov 23 00:09:17 2018 +0100

sw: new testcase for XText

Change-Id: I8c4b89e1e0851e808daa0902f970f967c6d057a9
Reviewed-on: https://gerrit.libreoffice.org/61348
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index cd73e90f199a..ad479f527504 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -41,6 +41,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
xcontrolshape \
xtextcontent \
xtextrange \
+   xtext \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/xtext.py b/sw/qa/python/xtext.py
new file mode 100644
index ..5ee5986a5454
--- /dev/null
+++ b/sw/qa/python/xtext.py
@@ -0,0 +1,89 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.lang import IllegalArgumentException
+from com.sun.star.container import NoSuchElementException
+import uno
+import time
+
+
+class TestXText(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+cls._uno.openEmptyWriterDoc()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_insertAndRemoveAnnotations(self):
+xText = self._uno.getDoc().getText()
+self.assertIsNotNone(xText)
+
+# Insert annotation field
+xAnnotation = self.createAnnotation("John Doe")
+xCursor = xText.createTextCursor()
+xText.insertTextContent(xCursor, xAnnotation, False)
+
+# And the same once again, actually not inserted
+xText.insertTextContent(xCursor, xAnnotation, False)
+
+# Exception if we try to replace object by itself
+with self.assertRaises(IllegalArgumentException):
+xText.insertTextContent(xCursor, xAnnotation, True)
+# We expect just one annotation actually
+self.checkAnnotations(["John Doe"])
+
+xAnnotation2 = self.createAnnotation("Richard Roe")
+xText.insertTextContent(xCursor, xAnnotation2, True)
+self.checkAnnotations(["Richard Roe"])
+
+xAnnotation3 = self.createAnnotation("Jane Roe")
+xText.insertTextContent(xCursor, xAnnotation3, True)
+self.checkAnnotations(["Jane Roe", "Richard Roe"])
+
+# Remove annotations
+xText.removeTextContent(xAnnotation3)
+self.checkAnnotations(["Richard Roe"])
+xText.removeTextContent(xAnnotation2)
+self.checkAnnotations([])
+
+# Remove _already removed_ ones again
+# TODO: unexpected behaviour, it should throw an exception,
+# but let's nail down current behaviour
+xText.removeTextContent(xAnnotation2)
+xText.removeTextContent(xAnnotation)
+
+self.checkAnnotations([])
+
+def createAnnotation(self, author):
+xAnnotation = 
self._uno.getDoc().createInstance("com.sun.star.text.TextField.Annotation")
+self.assertIsNotNone(xAnnotation)
+xAnnotation.setPropertyValue("Author", author)
+return xAnnotation
+
+def checkAnnotations(self, authors):
+xFieldsEnum = self._uno.getDoc().getTextFields().createEnumeration()
+annotationsFound = 0
+for xField, author in zip(xFieldsEnum, authors):
+
self.assertTrue(xField.supportsService("com.sun.star.text.TextField.Annotation"))
+self.assertEqual(xField.getPropertyValue("Author"), author)
+annotationsFound += 1
+self.assertEqual(annotationsFound, len(authors))
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-11-22 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk|1 
 sw/qa/python/testdocuments/xtextrange.odt |binary
 sw/qa/python/xtextrange.py|   97 ++
 3 files changed, 98 insertions(+)

New commits:
commit 284dd58e326e61a5d84bde367e1e4873dd738c76
Author: Vasily Melenchuk 
AuthorDate: Mon Oct 1 09:43:59 2018 +0300
Commit: Thorsten Behrens 
CommitDate: Fri Nov 23 00:08:38 2018 +0100

sw: new testcase for XTextRange

Change-Id: Ia476f4f001851d0f8b51fca62b5c041b1d866cc3
Reviewed-on: https://gerrit.libreoffice.org/61174
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 0dc15f929de0..cd73e90f199a 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -40,6 +40,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
xtextfieldssupplier \
xcontrolshape \
xtextcontent \
+   xtextrange \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextrange.odt 
b/sw/qa/python/testdocuments/xtextrange.odt
new file mode 100644
index ..5881ea44a447
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextrange.odt differ
diff --git a/sw/qa/python/xtextrange.py b/sw/qa/python/xtextrange.py
new file mode 100644
index ..e6875fadc097
--- /dev/null
+++ b/sw/qa/python/xtextrange.py
@@ -0,0 +1,97 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+import uno
+import time
+
+
+class TestXTextRange(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+cls._uno.openDocFromTDOC("xtextrange.odt")
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_textRangesInPlainText(self):
+xCursor = self._uno.getDoc().getText().createTextCursor()
+xCursor.goRight(10, True)
+xTextRange = xCursor
+self.assertEqual(xTextRange.getString(), "0123456789")
+
+# getStart
+xTextRangeStart = xTextRange.getStart()
+self.assertIsNotNone(xTextRangeStart)
+self.assertEqual(xTextRangeStart.getString(), "")
+xTextRangeStart.setString("before")
+self.assertEqual(xTextRangeStart.getString(), "before")
+
+# Owerwrite strings
+xTextRangeStart.setString("beforebeforebeforebefore")
+xTextRangeStart.setString("before2")
+xTextRangeStart.setString("before3")
+xTextRangeStart.setString("before")
+self.assertEqual(xTextRangeStart.getString(), "before")
+xCursor = self._uno.getDoc().getText().createTextCursor()
+xCursor.goRight(16, True)
+self.assertEqual(xCursor.getString(), "before0123456789")
+
+# getEnd
+xTextRangeEnd = xTextRange.getEnd()
+self.assertIsNotNone(xTextRangeEnd)
+self.assertEqual(xTextRangeEnd.getString(), "")
+xTextRangeEnd.setString("after")
+self.assertEqual(xTextRangeEnd.getString(), "after")
+
+# getText
+xText = xTextRange.getText()
+self.assertIsNotNone(xText)
+
+# Final check of what we have inserted
+xCursor = self._uno.getDoc().getText().createTextCursor()
+xCursor.goRight(21, True)
+self.assertEqual(xCursor.getString(), "before0123456789after")
+
+def test_textRangesInTable(self):
+xTextTables = self._uno.getDoc().getTextTables()
+self.assertIsNotNone(xTextTables)
+xTextTable = xTextTables[0]
+self.assertIsNotNone(xTextTable)
+
+xTextRange = xTextTable.getCellByName("A1")
+self.assertIsNotNone(xTextRange)
+self.assertEqual(xTextRange.getString(), "C1")
+
+xTextRangeStart = xTextRange.getStart()
+self.assertIsNotNone(xTextRangeStart)
+self.assertEqual(xTextRangeStart.getString(), "")
+xTextRangeStart.setString("before")
+self.assertEqual(xTextRangeStart.getString(), "before")
+
+xTextRangeEnd = xTextRange.getEnd()
+self.assertIsNotNone(xTextRangeEnd)
+self.assertEqual(xTextRangeEnd.getString(), "")
+xTextRangeEnd.setString("after")
+self.assertEqual(xTextRangeEnd.getString(), "after")
+
+# Ensure that what we inserted is in cell
+xTextRange2 = xTextTable.getCellByName("A1")
+self.assertEqual(xTextRange2.getString(), "beforeC1after")
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-11-22 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/python/check_xautotextgroup.py |  150 +++
 2 files changed, 151 insertions(+)

New commits:
commit c690fb0fa0f1e1e9ebdc782321b0b166f61e76f0
Author: Serge Krot 
AuthorDate: Tue Oct 2 18:59:29 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Fri Nov 23 00:07:39 2018 +0100

sw: new unit test for XAutoTextGroup

Change-Id: I3928248b73025f304c0e1ef7b5f86349df9a3c8d
Reviewed-on: https://gerrit.libreoffice.org/61267
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 836c6e06378a..0dc15f929de0 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -27,6 +27,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_xtexttable \
check_table \
check_xautotextcontainer \
+   check_xautotextgroup \
check_xmodifiable2 \
check_xnamedgraph \
check_xrefreshable \
diff --git a/sw/qa/python/check_xautotextgroup.py 
b/sw/qa/python/check_xautotextgroup.py
new file mode 100644
index ..a41987103e6b
--- /dev/null
+++ b/sw/qa/python/check_xautotextgroup.py
@@ -0,0 +1,150 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.container import ElementExistException
+from com.sun.star.container import NoSuchElementException
+from com.sun.star.uno import RuntimeException
+
+
+class XAutoTextGroup(unittest.TestCase):
+# 0 indicates the path of the Office Basis layer
+# 1 indicates the path of the user directory
+GROUP_NAME = 'atg_name1*1'
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+cls._uno.openEmptyWriterDoc()
+
+def setUp(self):
+self.xAutoTextContainer = self.createAutoTextContainer()
+self.xAutoTextGroup = self.insertNewGroup(self.xAutoTextContainer)
+
+self.xText = self._uno.getDoc().getText()
+self.xCursor = self.xText.createTextCursor()
+self.xRange = self.xCursor.getStart()
+
+def tearDown(self):
+self.xAutoTextContainer.removeByName(self.GROUP_NAME)
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_XAutoTextGroup(self):
+xName = 'Name'
+xTitle = 'Title'
+
+titlesBefore = self.xAutoTextGroup.getTitles()
+
+self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+self.assertNotEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+self.xAutoTextGroup.removeByName(xName)
+self.assertEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+def test_XAutoTextGroup_NoTitle(self):
+xName = 'Name'
+
+titlesBefore = self.xAutoTextGroup.getTitles()
+
+self.xAutoTextGroup.insertNewByName(xName, xName, self.xRange)
+self.assertNotEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+self.xAutoTextGroup.removeByName(xName)
+self.assertEqual(titlesBefore, self.xAutoTextGroup.getTitles())
+
+def test_insertNewByName_Twice(self):
+xName = 'Name'
+xTitle = 'Title'
+
+self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+
+with self.assertRaises(ElementExistException):
+self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+
+self.xAutoTextGroup.removeByName(xName)
+
+def test_renameByName(self):
+xName = 'Name'
+xTitle = 'Title'
+
+xNewName = 'New Name'
+xNewTitle = 'New Title'
+
+self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+self.xAutoTextGroup.renameByName(xName, xNewName, xNewTitle)
+
+titlesBefore = self.xAutoTextGroup.getTitles()
+with self.assertRaises(NoSuchElementException):
+self.xAutoTextGroup.removeByName(xName)
+titlesAfter = self.xAutoTextGroup.getTitles()
+self.assertEqual(titlesBefore, titlesAfter)
+
+self.xAutoTextGroup.removeByName(xNewName)
+titlesAfter2 = self.xAutoTextGroup.getTitles()
+self.assertNotEqual(titlesBefore, titlesAfter2)
+
+def test_renameByName_Failed(self):
+xName = 'Name'
+xTitle = 'Title'
+
+xNewName = 'New Name'
+xNewTitle = 'New Title'
+
+self.xAutoTextGroup.insertNewByName(xName, xTitle, self.xRange)
+self.xAutoTextGroup.insertNewByName(xNewName, xNewTitle, self.xRange)
+
+with self.assertRaises(ElementExistException):
+

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-11-22 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/python/check_xcloseable.py |   88 +++
 2 files changed, 89 insertions(+)

New commits:
commit 7878a30e0977f23f49a89031631a92528fdde8c5
Author: Serge Krot 
AuthorDate: Fri Sep 28 16:02:34 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Thu Nov 22 15:27:47 2018 +0100

sw: new unit test for XCloseable

Change-Id: I1c89abffcc985d6f5b2e0f570fcb82601d923b5e
Reviewed-on: https://gerrit.libreoffice.org/61091
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index b7c66bba7bfe..836c6e06378a 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -19,6 +19,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_index \
check_flies \
check_fields \
+   check_xcloseable \
check_cross_references \
check_named_property_values \
check_indexed_property_values \
diff --git a/sw/qa/python/check_xcloseable.py b/sw/qa/python/check_xcloseable.py
new file mode 100644
index ..172b852dcd00
--- /dev/null
+++ b/sw/qa/python/check_xcloseable.py
@@ -0,0 +1,88 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.util import XCloseListener
+
+
+listenerCallsOwner = 0
+listenerCallsNoOwner = 0
+
+
+class XCloseListenerExtended(unohelper.Base, XCloseListener):
+@classmethod
+def queryClosing(self, Source, GetsOwnership):
+if GetsOwnership is True:
+global listenerCallsOwner
+listenerCallsOwner += 1
+else:
+global listenerCallsNoOwner
+listenerCallsNoOwner += 1
+
+@classmethod
+def notifyClosing(self, Source):
+pass
+
+@classmethod
+def disposing(self, Event):
+pass
+
+
+class XCloseable(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_closeTrue(self):
+# prepare
+global listenerCallsOwner
+global listenerCallsNoOwner
+listenerCallsOwner = 0
+listenerCallsNoOwner = 0
+
+# run
+xDoc = self._uno.openEmptyWriterDoc()
+xListener = XCloseListenerExtended()
+xDoc.addCloseListener(xListener)
+xDoc.close(True)
+
+# verify results
+self.assertEqual(1, listenerCallsOwner)
+self.assertEqual(0, listenerCallsNoOwner)
+
+def test_closeFalse(self):
+# prepare
+global listenerCallsOwner
+global listenerCallsNoOwner
+listenerCallsOwner = 0
+listenerCallsNoOwner = 0
+
+# run
+xDoc = self._uno.openEmptyWriterDoc()
+xListener = XCloseListenerExtended()
+xDoc.addCloseListener(xListener)
+xDoc.close(False)
+
+# verify results
+self.assertEqual(0, listenerCallsOwner)
+self.assertEqual(1, listenerCallsNoOwner)
+
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-10-12 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk  |1 
 sw/qa/python/testdocuments/xtextcontent.odt |binary
 sw/qa/python/xtextcontent.py|   80 
 3 files changed, 81 insertions(+)

New commits:
commit 50c2effdf7f2f209d8d256b9c48580c79ece7fbd
Author: Vasily Melenchuk 
AuthorDate: Thu Oct 4 10:03:59 2018 +0300
Commit: Samuel Mehrbrodt 
CommitDate: Fri Oct 12 13:11:51 2018 +0200

sw: new unit test for XTextContent

Change-Id: Ic5f6740b145a473f69052489ce6c48894f33c74d
Reviewed-on: https://gerrit.libreoffice.org/61351
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 573ebbc95182..b7c66bba7bfe 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -37,6 +37,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
xscriptprovider \
xtextfieldssupplier \
xcontrolshape \
+   xtextcontent \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextcontent.odt 
b/sw/qa/python/testdocuments/xtextcontent.odt
new file mode 100644
index ..a1eb82741b69
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextcontent.odt differ
diff --git a/sw/qa/python/xtextcontent.py b/sw/qa/python/xtextcontent.py
new file mode 100644
index ..bae9b79f898e
--- /dev/null
+++ b/sw/qa/python/xtextcontent.py
@@ -0,0 +1,80 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.lang import IllegalArgumentException
+import uno
+
+
+class TestXTextContent(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_anchorOperations(self):
+xDoc = self._uno.openDocFromTDOC("xtextcontent.odt")
+self.assertIsNotNone(xDoc)
+
+# getAnchor for both text frames and ensure we receive ranges we expect
+xFrame1 = self.getTextFrame("Frame1")
+xRange1 = xFrame1.getAnchor()
+self.assertIsNotNone(xRange1)
+self.compareRange(xRange1, "String1")
+
+xFrame2 = self.getTextFrame("Frame2")
+xRange2 = xFrame2.getAnchor()
+self.assertIsNotNone(xRange2)
+self.compareRange(xRange2, "String2")
+
+# Check how XTextContent::attach works. Try to exchange anchors
+xFrame1.attach(xRange2)
+xFrame2.attach(xRange1)
+self.compareRange(xFrame1.getAnchor(), "String2")
+self.compareRange(xFrame2.getAnchor(), "String1")
+
+# Try to attach to None
+with self.assertRaises(IllegalArgumentException):
+xFrame1.attach(None)
+
+# Trying to attach frame to range from other document
+xDoc2 = self._uno.openDocFromTDOC("xcontrolshape.odt")
+with self.assertRaises(IllegalArgumentException):
+xFrame1.attach(xDoc2.getText())
+
+xDoc2.close(True)
+xDoc.close(True)
+
+def getTextFrame(self, frameName):
+xTextFrames = self._uno.getDoc().getTextFrames()
+self.assertIsNotNone(xTextFrames)
+xTextFrame = xTextFrames[frameName]
+self.assertIsNotNone(xTextFrame)
+return xTextFrame
+
+# Helper to extract text content from range and compare to expected string
+def compareRange(self, xRange, expectedContent):
+xCursor = xRange.getText().createTextCursor()
+self.assertIsNotNone(xCursor)
+xCursor.collapseToStart()
+xCursor.goRight(len(expectedContent), True)
+self.assertEqual(xCursor.getString(), expectedContent)
+
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-10-03 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/python/check_xautotextcontainer.py |  176 +++
 2 files changed, 177 insertions(+)

New commits:
commit 4967d498c486800b72ba34192c82c232bc0685bd
Author: Serge Krot 
AuthorDate: Mon Sep 24 21:10:45 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Wed Oct 3 10:57:22 2018 +0200

sw: new unit test for XAutoTextContainer

Change-Id: I8c4fba4d576256c4ca3870b521aec999407af4e5
Reviewed-on: https://gerrit.libreoffice.org/60945
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 728e3e29141c..573ebbc95182 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -25,6 +25,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_styles \
check_xtexttable \
check_table \
+   check_xautotextcontainer \
check_xmodifiable2 \
check_xnamedgraph \
check_xrefreshable \
diff --git a/sw/qa/python/check_xautotextcontainer.py 
b/sw/qa/python/check_xautotextcontainer.py
new file mode 100644
index ..a3cf91b89ae6
--- /dev/null
+++ b/sw/qa/python/check_xautotextcontainer.py
@@ -0,0 +1,176 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.container import NoSuchElementException
+from com.sun.star.lang import IllegalArgumentException
+
+
+class XAutoTextContainer(unittest.TestCase):
+
+@classmethod
+def setUpClass(self):
+self._uno = UnoInProcess()
+self._uno.setUp()
+self._uno.openEmptyWriterDoc()
+
+@classmethod
+def tearDownClass(self):
+self._uno.tearDown()
+
+def test_insertNewByName(self):
+# initialization
+xAutoTextContainer = self.createAutoTextContainer()
+if xAutoTextContainer is None:
+return
+
+# perform unit test
+# group name must contain a-z, A-z, 0-9, '_', ' ' only
+xNames = ['Name', 'TEST', 'Name2', '_With_underscore_', 'with space', 
'123456']
+for xName in xNames:
+xAutoTextContainer.insertNewByName(xName)
+xAutoTextContainer.removeByName(xName)
+
+def test_insertNewByName_Spaces(self):
+# initialization
+xAutoTextContainer = self.createAutoTextContainer()
+if xAutoTextContainer is None:
+return
+
+# perform unit test
+# add
+xName = '  spaces  '
+xAutoTextContainer.insertNewByName(xName)
+
+# try to remove
+with self.assertRaises(NoSuchElementException):
+xAutoTextContainer.removeByName(xName)
+
+# remove trimmed
+xAutoTextContainer.removeByName('spaces')
+
+def test_insertNewByName_Several(self):
+# initialization
+xAutoTextContainer = self.createAutoTextContainer()
+if xAutoTextContainer is None:
+return
+
+# perform unit test
+xAutoTextGroup1 = xAutoTextContainer.insertNewByName("atc_name1")
+xAutoTextGroup2 = xAutoTextContainer.insertNewByName("atc_name2")
+xAutoTextGroup3 = xAutoTextContainer.insertNewByName("atc_name3")
+
+self.assertEqual("atc_name1*0", xAutoTextGroup1.getName())
+self.assertEqual("atc_name2*0", xAutoTextGroup2.getName())
+self.assertEqual("atc_name3*0", xAutoTextGroup3.getName())
+
+xAutoTextContainer.removeByName("atc_name1")
+xAutoTextContainer.removeByName("atc_name2")
+xAutoTextContainer.removeByName("atc_name3")
+
+def test_insertNewByName_DifferentCase(self):
+# initialization
+xAutoTextContainer = self.createAutoTextContainer()
+if xAutoTextContainer is None:
+return
+
+# perform unit test
+xAutoTextGroup1 = xAutoTextContainer.insertNewByName("myname")
+xAutoTextGroup2 = xAutoTextContainer.insertNewByName("MYNAME")
+xAutoTextGroup3 = xAutoTextContainer.insertNewByName("MyName")
+
+self.assertEqual("myname*0", xAutoTextGroup1.getName())
+
+# Note: different platforms could support different cases
+#   in container names
+validName2 = False
+validName2 |= (xAutoTextGroup2.getName() == "MYNAME*0")
+validName2 |= (xAutoTextGroup2.getName()[:5] == "group")
+
+validName3 = False
+validName3 |= (xAutoTextGroup3.getName() == "MyName*0")
+validName3 |= (xAutoTextGroup3.getName()[:5] == "group")
+
+self.assertTrue(validName2)
+self.assertTrue(validName3)
+
+

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-10-02 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/python/testdocuments/xcontrolshape.odt |binary
 sw/qa/python/xcontrolshape.py|   79 +++
 3 files changed, 80 insertions(+)

New commits:
commit 41b1038874a45097cd9a6b981142029a8466200c
Author: Vasily Melenchuk 
AuthorDate: Sat Sep 29 02:57:31 2018 +0300
Commit: Thorsten Behrens 
CommitDate: Tue Oct 2 15:45:14 2018 +0200

sw: new unit test for XControlShape

Change-Id: Ic7b56da1f48760770ca5617cea6c91e10ff0dcee
Reviewed-on: https://gerrit.libreoffice.org/61100
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 5daae9b957ae..728e3e29141c 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -35,6 +35,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
var_fields \
xscriptprovider \
xtextfieldssupplier \
+   xcontrolshape \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xcontrolshape.odt 
b/sw/qa/python/testdocuments/xcontrolshape.odt
new file mode 100644
index ..d8a003b137ce
Binary files /dev/null and b/sw/qa/python/testdocuments/xcontrolshape.odt differ
diff --git a/sw/qa/python/xcontrolshape.py b/sw/qa/python/xcontrolshape.py
new file mode 100644
index ..cfbcedba73c9
--- /dev/null
+++ b/sw/qa/python/xcontrolshape.py
@@ -0,0 +1,79 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.beans import UnknownPropertyException
+import uno
+
+
+class TestXControlShape(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_getAndSetControlShape(self):
+xDoc = self.__class__._uno.openDocFromTDOC("xcontrolshape.odt")
+self.assertIsNotNone(xDoc)
+
+xDrawPage = xDoc.getDrawPage()
+self.assertIsNotNone(xDrawPage)
+
+# Date picker has control
+xShapeDatePicker = xDrawPage[0]
+self.assertIsNotNone(xShapeDatePicker)
+self.assertIsNotNone(xShapeDatePicker.getControl())
+
+# Combobox also has control
+xShapeCombo = xDrawPage[1]
+self.assertIsNotNone(xShapeCombo)
+self.assertIsNotNone(xShapeCombo.getControl())
+
+# Simple draw shape has no ControlShape
+xShapeSimple = xDrawPage[2]
+self.assertIsNotNone(xShapeSimple)
+# Shape has no XControlShape interface and we get AttributeError 
exception
+# during getControl() call
+with self.assertRaises(AttributeError):
+self.assertIsNone(xShapeSimple.getControl())
+
+xOldControlShape = xShapeCombo.getControl()
+
+# Combo box was a combo box and had no "Date" attribute"
+with self.assertRaises(UnknownPropertyException):
+xShapeCombo.getControl().getPropertyValue("Date")
+
+# We are setting new Control Shape
+xShapeCombo.setControl(xShapeDatePicker.getControl())
+
+# And we can get date with some value
+xDate = xShapeCombo.getControl().getPropertyValue("Date")
+self.assertIsNotNone(xDate)
+self.assertTrue(xDate.Day > 0 and xDate.Month > 0 and xDate.Year > 0)
+
+# Return back original controlshape
+xShapeCombo.setControl(xOldControlShape)
+# ...and ensure that date no longer available
+with self.assertRaises(UnknownPropertyException):
+xShapeCombo.getControl().getPropertyValue("Date")
+
+xDoc.close(True)
+
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-10-02 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/check_xrefreshable.py |  110 +
 2 files changed, 111 insertions(+)

New commits:
commit 307b1cab436f63b5e879ca65cf3c74065ee4ad14
Author: Serge Krot 
AuthorDate: Mon Oct 1 19:54:35 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Tue Oct 2 15:42:32 2018 +0200

sw: new unit test for XRefreshable

Change-Id: Idaea2e46451ee80b82764e573fdea1c7bf0c86ef
Reviewed-on: https://gerrit.libreoffice.org/61213
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 37c0100fd70d..5daae9b957ae 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -27,6 +27,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_table \
check_xmodifiable2 \
check_xnamedgraph \
+   check_xrefreshable \
check_xtextrangecompare \
get_expression \
set_expression \
diff --git a/sw/qa/python/check_xrefreshable.py 
b/sw/qa/python/check_xrefreshable.py
new file mode 100644
index ..2d79a947ad1a
--- /dev/null
+++ b/sw/qa/python/check_xrefreshable.py
@@ -0,0 +1,110 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.util import XRefreshListener
+
+
+refreshed = 0
+
+
+class XRefreshListenerExtended(unohelper.Base, XRefreshListener):
+@classmethod
+def refreshed(self, Event):
+global refreshed
+refreshed += 1
+
+@classmethod
+def disposing(self, event):
+pass
+
+
+class XRefreshable(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_None(self):
+global refreshed
+refreshed = 0
+xDoc = self._uno.openEmptyWriterDoc()
+
+# attempt to add/remove none
+xDoc.addRefreshListener(None)
+xDoc.removeRefreshListener(None)
+
+# refresh without listeners
+xDoc.refresh()
+xDoc.close(True)
+
+def test_refresh(self):
+global refreshed
+refreshed = 0
+
+xDoc = self._uno.openEmptyWriterDoc()
+xListener = XRefreshListenerExtended()
+xDoc.addRefreshListener(xListener)
+xDoc.refresh()
+xDoc.removeRefreshListener(xListener)
+self.assertEqual(1, refreshed)
+xDoc.refresh()
+self.assertEqual(1, refreshed)
+xDoc.close(True)
+
+def test_refreshTwice(self):
+global refreshed
+refreshed = 0
+
+xDoc = self._uno.openEmptyWriterDoc()
+xListener = XRefreshListenerExtended()
+xDoc.addRefreshListener(xListener)
+xDoc.refresh()
+xDoc.refresh()
+xDoc.removeRefreshListener(xListener)
+self.assertEqual(2, refreshed)
+xDoc.refresh()
+self.assertEqual(2, refreshed)
+xDoc.close(True)
+
+def test_DoubleInstances(self):
+global refreshed
+refreshed = 0
+
+xDoc = self._uno.openEmptyWriterDoc()
+xListener = XRefreshListenerExtended()
+
+xDoc.addRefreshListener(xListener)
+xDoc.addRefreshListener(xListener)
+xDoc.addRefreshListener(xListener)
+
+xDoc.refresh()
+xDoc.refresh()
+self.assertEqual(3*2, refreshed)
+
+refreshed = 0
+xDoc.removeRefreshListener(xListener)
+xDoc.refresh()
+# two instances should remain in the list
+self.assertEqual(2, refreshed)
+
+xDoc.close(True)
+
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-10-02 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk|1 
 sw/qa/python/check_xmodifiable2.py|  195 ++
 sw/qa/python/testdocuments/WriteProtected.odt |binary
 3 files changed, 196 insertions(+)

New commits:
commit e92a4bf08624159c64fcc45a9786ff2e41727bf2
Author: Serge Krot 
AuthorDate: Fri Sep 28 19:53:36 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Tue Oct 2 15:25:14 2018 +0200

sw: new unit test for XModifiable2

Change-Id: I30c4db19db068ff73f34236776cb511280acbbd7
Reviewed-on: https://gerrit.libreoffice.org/61096
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 6c5a4c818fe8..37c0100fd70d 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -25,6 +25,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_styles \
check_xtexttable \
check_table \
+   check_xmodifiable2 \
check_xnamedgraph \
check_xtextrangecompare \
get_expression \
diff --git a/sw/qa/python/check_xmodifiable2.py 
b/sw/qa/python/check_xmodifiable2.py
new file mode 100644
index ..e8b95dc2b329
--- /dev/null
+++ b/sw/qa/python/check_xmodifiable2.py
@@ -0,0 +1,195 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+
+
+class XModifiable2(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_XModifiable2(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+
+# perform unit test
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+self.assertTrue(xDoc.disableSetModified())
+self.assertFalse(xDoc.isSetModifiedEnabled())
+
+self.assertFalse(xDoc.enableSetModified())
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+# clean up
+xDoc.close(True)
+
+def test_XModifiable2_Double(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+
+# perform unit test
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+# try to disable
+# Expected return value:
+#   `TRUE` the changing of the modified state was disabled
+self.assertTrue(xDoc.disableSetModified())
+self.assertFalse(xDoc.isSetModifiedEnabled())
+
+# try to disable twice
+# Expected return value:
+#   `FALSE` the changing of the modified state was already disabled
+self.assertFalse(xDoc.disableSetModified())
+self.assertFalse(xDoc.isSetModifiedEnabled())
+
+# try to disable third time
+# Expected return value:
+#   `FALSE` the changing of the modified state was already disabled
+#   i.e. the same as in previous call
+self.assertFalse(xDoc.disableSetModified())
+self.assertFalse(xDoc.isSetModifiedEnabled())
+
+# try to enable
+# Expected return value:
+#   `FALSE` the changing of the modified state was enabled
+self.assertFalse(xDoc.enableSetModified())
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+# try to enable twice
+# Expected return value:
+#   `TRUE` the changing of the modified state was already enabled
+self.assertTrue(xDoc.enableSetModified())
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+# try to enable third time
+# Expected return value:
+#   `TRUE` the changing of the modified state was already enabled
+#   i.e. the same as in previous call
+self.assertTrue(xDoc.enableSetModified())
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+# clean up
+xDoc.close(True)
+
+def test_XModifiable2_setModified(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+
+# perform unit test
+# try to set modified flag when modification enabled
+self.assertTrue(xDoc.isSetModifiedEnabled())
+
+self.assertFalse(xDoc.isModified())
+xDoc.setModified(True)
+self.assertTrue(xDoc.isModified())
+
+xDoc.setModified(False)
+self.assertFalse(xDoc.isModified())
+
+# try to set modified flag when modification disabled
+self.assertTrue(xDoc.disableSetModified())
+self.assertFalse(xDoc.isSetModifiedEnabled())
+
+self.assertFalse(xDoc.isModified())
+

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-10-01 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/python/check_xautotextgroup.py |  211 ---
 2 files changed, 212 deletions(-)

New commits:
commit e9c1cbce903d325b1e19602d72765511589f5bf2
Author: Stephan Bergmann 
AuthorDate: Mon Oct 1 14:13:56 2018 +0200
Commit: Stephan Bergmann 
CommitDate: Mon Oct 1 14:13:56 2018 +0200

Revert "sw: new unit test for XAutoTextGroup"

This reverts commit 9356a2d98b13f45b3d17d181b1ad79d541d7d2f8.  For one, it
caused PythonTest_sw_python to crash like
 with

> include/vcl/vclptr.hxx:112: VclPtr::~VclPtr() [with reference_type = 
vcl::Window]: Assertion `m_rInnerRef.get() == nullptr || vclmain::isAlive()' 
failed.

firing (presumably because some more clean-up as in
e7a3329fd0a68c95f00e6cdfdc3e40e6afa5411c "DeInitVCL in PythonTest" is 
needed).
And for another, it left behind instdir/share/autotext/atg_name1.bau at 
least in
my build, and a subsequent PythonTest_sw_python would then fail due to
css.container.ElementExistException from some of those tests'
xAutoTextContainer.insertNewByName("atg_name1").  That apparently all needs
further inspection before re-introducing that test.

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index f7a868d79d1c..6c5a4c818fe8 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -22,7 +22,6 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_cross_references \
check_named_property_values \
check_indexed_property_values \
-   check_xautotextgroup \
check_styles \
check_xtexttable \
check_table \
diff --git a/sw/qa/python/check_xautotextgroup.py 
b/sw/qa/python/check_xautotextgroup.py
deleted file mode 100644
index 95d4a0bce67c..
--- a/sw/qa/python/check_xautotextgroup.py
+++ /dev/null
@@ -1,211 +0,0 @@
-#! /usr/bin/env python
-# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
-#
-import unittest
-from org.libreoffice.unotest import UnoInProcess
-from com.sun.star.container import ElementExistException
-
-
-class XAutoTextGroup(unittest.TestCase):
-
-@classmethod
-def setUpClass(cls):
-cls._uno = UnoInProcess()
-cls._uno.setUp()
-
-@classmethod
-def tearDownClass(cls):
-cls._uno.tearDown()
-
-def test_XAutoTextGroup(self):
-# initialization
-xDoc = self._uno.openEmptyWriterDoc()
-xAutoTextContainer = self.createAutoTextContainer()
-xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
-
-xText = xDoc.getText()
-xCursor = xText.createTextCursor()
-xRange = xCursor.getStart()
-
-# perform unit test
-xName = 'Name'
-xTitle = 'Title'
-
-titlesBefore = xAutoTextGroup.getTitles()
-
-xAutoTextGroup.insertNewByName(xName, xTitle, xRange)
-self.assertNotEqual(titlesBefore, xAutoTextGroup.getTitles())
-
-xAutoTextGroup.removeByName(xName)
-self.assertEqual(titlesBefore, xAutoTextGroup.getTitles())
-
-# clean up
-xAutoTextContainer.removeByName("atg_name1")
-xDoc.close(True)
-
-def test_XAutoTextGroup_NoTitle(self):
-# initialization
-xDoc = self._uno.openEmptyWriterDoc()
-xAutoTextContainer = self.createAutoTextContainer()
-xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
-
-xText = xDoc.getText()
-xCursor = xText.createTextCursor()
-xRange = xCursor.getStart()
-
-# perform unit test
-xName = 'Name'
-
-titlesBefore = xAutoTextGroup.getTitles()
-
-xAutoTextGroup.insertNewByName(xName, xName, xRange)
-self.assertNotEqual(titlesBefore, xAutoTextGroup.getTitles())
-
-xAutoTextGroup.removeByName(xName)
-self.assertEqual(titlesBefore, xAutoTextGroup.getTitles())
-
-# clean up
-xAutoTextContainer.removeByName("atg_name1")
-xDoc.close(True)
-
-def test_insertNewByName_Twice(self):
-# initialization
-xDoc = self._uno.openEmptyWriterDoc()
-xAutoTextContainer = self.createAutoTextContainer()
-xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
-
-xText = xDoc.getText()
-xCursor = xText.createTextCursor()
-xRange = xCursor.getStart()
-
-# perform unit test
-xName = 'Name'
-xTitle = 'Title'
-
-xAutoTextGroup.insertNewByName(xName, xTitle, xRange)
-
-with self.assertRaises(ElementExistException):
-

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-09-30 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/python/check_xautotextgroup.py |  211 +++
 2 files changed, 212 insertions(+)

New commits:
commit 9356a2d98b13f45b3d17d181b1ad79d541d7d2f8
Author: Serge Krot 
AuthorDate: Tue Sep 25 16:36:33 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Mon Oct 1 01:39:35 2018 +0200

sw: new unit test for XAutoTextGroup

Change-Id: Ia43a59def79b3379e051020771e9ce45ce03a9ac
Reviewed-on: https://gerrit.libreoffice.org/60976
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 6c5a4c818fe8..f7a868d79d1c 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -22,6 +22,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_cross_references \
check_named_property_values \
check_indexed_property_values \
+   check_xautotextgroup \
check_styles \
check_xtexttable \
check_table \
diff --git a/sw/qa/python/check_xautotextgroup.py 
b/sw/qa/python/check_xautotextgroup.py
new file mode 100644
index ..95d4a0bce67c
--- /dev/null
+++ b/sw/qa/python/check_xautotextgroup.py
@@ -0,0 +1,211 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.container import ElementExistException
+
+
+class XAutoTextGroup(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_XAutoTextGroup(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+xAutoTextContainer = self.createAutoTextContainer()
+xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
+
+xText = xDoc.getText()
+xCursor = xText.createTextCursor()
+xRange = xCursor.getStart()
+
+# perform unit test
+xName = 'Name'
+xTitle = 'Title'
+
+titlesBefore = xAutoTextGroup.getTitles()
+
+xAutoTextGroup.insertNewByName(xName, xTitle, xRange)
+self.assertNotEqual(titlesBefore, xAutoTextGroup.getTitles())
+
+xAutoTextGroup.removeByName(xName)
+self.assertEqual(titlesBefore, xAutoTextGroup.getTitles())
+
+# clean up
+xAutoTextContainer.removeByName("atg_name1")
+xDoc.close(True)
+
+def test_XAutoTextGroup_NoTitle(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+xAutoTextContainer = self.createAutoTextContainer()
+xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
+
+xText = xDoc.getText()
+xCursor = xText.createTextCursor()
+xRange = xCursor.getStart()
+
+# perform unit test
+xName = 'Name'
+
+titlesBefore = xAutoTextGroup.getTitles()
+
+xAutoTextGroup.insertNewByName(xName, xName, xRange)
+self.assertNotEqual(titlesBefore, xAutoTextGroup.getTitles())
+
+xAutoTextGroup.removeByName(xName)
+self.assertEqual(titlesBefore, xAutoTextGroup.getTitles())
+
+# clean up
+xAutoTextContainer.removeByName("atg_name1")
+xDoc.close(True)
+
+def test_insertNewByName_Twice(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+xAutoTextContainer = self.createAutoTextContainer()
+xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
+
+xText = xDoc.getText()
+xCursor = xText.createTextCursor()
+xRange = xCursor.getStart()
+
+# perform unit test
+xName = 'Name'
+xTitle = 'Title'
+
+xAutoTextGroup.insertNewByName(xName, xTitle, xRange)
+
+with self.assertRaises(ElementExistException):
+xAutoTextGroup.insertNewByName(xName, xTitle, xRange)
+
+xAutoTextGroup.removeByName(xName)
+
+# clean up
+xAutoTextContainer.removeByName("atg_name1")
+xDoc.close(True)
+
+def test_renameByName(self):
+# initialization
+xDoc = self._uno.openEmptyWriterDoc()
+xAutoTextContainer = self.createAutoTextContainer()
+xAutoTextGroup = xAutoTextContainer.insertNewByName("atg_name1")
+
+xText = xDoc.getText()
+xCursor = xText.createTextCursor()
+xRange = xCursor.getStart()
+
+# perform unit test
+xName = 'Name'
+xTitle = 'Title'
+
+xNewName = 'New Name'
+xNewTitle = 'New Title'
+
+

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-09-28 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk  |1 
 sw/qa/python/check_xtextrangecompare.py |  167 
 2 files changed, 168 insertions(+)

New commits:
commit e9efc76f90291ba54dd2c6359f6fecef8c540841
Author: Serge Krot 
AuthorDate: Wed Sep 26 16:28:19 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Fri Sep 28 10:26:24 2018 +0200

sw: new unit test for XTextRangeCompare

Change-Id: Ia0d216b94f8090c3479c6e4c593baf84cb28e5e2
Reviewed-on: https://gerrit.libreoffice.org/61005
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index a2d677045367..6c5a4c818fe8 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -26,6 +26,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_xtexttable \
check_table \
check_xnamedgraph \
+   check_xtextrangecompare \
get_expression \
set_expression \
text_portion_enumeration_test \
diff --git a/sw/qa/python/check_xtextrangecompare.py 
b/sw/qa/python/check_xtextrangecompare.py
new file mode 100644
index ..002e54c40a14
--- /dev/null
+++ b/sw/qa/python/check_xtextrangecompare.py
@@ -0,0 +1,167 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.lang import IllegalArgumentException
+
+
+class XTextRangeCompare(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_compareRegionStarts(self):
+xDoc = self._uno.openEmptyWriterDoc()
+
+cursor = xDoc.Text.createTextCursor()
+xDoc.Text.insertString(cursor, "The first paragraph", 0)
+
+self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor, cursor))
+
+with self.assertRaises(IllegalArgumentException):
+xDoc.Text.compareRegionStarts(cursor, None)
+
+with self.assertRaises(IllegalArgumentException):
+xDoc.Text.compareRegionStarts(None, cursor)
+
+with self.assertRaises(IllegalArgumentException):
+xDoc.Text.compareRegionStarts(None, None)
+
+xDoc.close(True)
+
+def test_compareRegionEnds(self):
+xDoc = self._uno.openEmptyWriterDoc()
+
+cursor = xDoc.Text.createTextCursor()
+xDoc.Text.insertString(cursor, "The first paragraph", 0)
+
+self.assertEqual(0, xDoc.Text.compareRegionEnds(cursor, cursor))
+
+with self.assertRaises(IllegalArgumentException):
+xDoc.Text.compareRegionEnds(cursor, None)
+
+with self.assertRaises(IllegalArgumentException):
+xDoc.Text.compareRegionEnds(None, cursor)
+
+with self.assertRaises(IllegalArgumentException):
+xDoc.Text.compareRegionEnds(None, None)
+
+xDoc.close(True)
+
+def test_compareRegionStarts_Different(self):
+xDoc = self._uno.openEmptyWriterDoc()
+
+cursor1 = xDoc.Text.createTextCursor()
+cursor2 = xDoc.Text.createTextCursor()
+
+xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+cursor1.gotoStart(False)
+cursor2.gotoEnd(False)
+
+self.assertTrue(cursor1.isCollapsed())
+self.assertTrue(cursor1.isCollapsed())
+
+self.assertEqual(1, xDoc.Text.compareRegionStarts(cursor1, cursor2))
+self.assertEqual(-1, xDoc.Text.compareRegionStarts(cursor2, cursor1))
+
+xDoc.close(True)
+
+def test_compareRegionStarts_DiffSelection(self):
+xDoc = self._uno.openEmptyWriterDoc()
+
+cursor1 = xDoc.Text.createTextCursor()
+cursor2 = xDoc.Text.createTextCursor()
+
+xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+cursor1.gotoStart(False)
+cursor1.gotoEnd(True)
+cursor2.gotoEnd(False)
+cursor2.gotoStart(True)
+
+self.assertFalse(cursor1.isCollapsed())
+self.assertFalse(cursor1.isCollapsed())
+
+self.assertEqual(0, xDoc.Text.compareRegionStarts(cursor1, cursor2))
+self.assertEqual(0, xDoc.Text.compareRegionEnds(cursor1, cursor2))
+
+xDoc.close(True)
+
+def test_compareRegionStarts_DiffSelection(self):
+xDoc = self._uno.openEmptyWriterDoc()
+
+cursor1 = xDoc.Text.createTextCursor()
+cursor2 = xDoc.Text.createTextCursor()
+
+xDoc.Text.insertString(cursor1, "The first paragraph", 0)
+
+cursor1.gotoStart(False)
+cursor1.gotoEnd(True)
+cursor1.goLeft(2, True)
+

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-09-25 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/testdocuments/xtextfieldssupplier.odt |binary
 sw/qa/python/xtextfieldssupplier.py|   89 +
 3 files changed, 90 insertions(+)

New commits:
commit 6328c56e1819cf85cb58539f7f3bace8ff577245
Author: Vasily Melenchuk 
AuthorDate: Thu Sep 20 11:24:48 2018 +0300
Commit: Thorsten Behrens 
CommitDate: Tue Sep 25 22:19:00 2018 +0200

sw: new unit test for XTextFieldsSupplier

Change-Id: I44c2fd97beeaa328774e241459b2a631b6a72030
Reviewed-on: https://gerrit.libreoffice.org/60794
Reviewed-by: Samuel Mehrbrodt 
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 13bf75122742..a2d677045367 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -31,6 +31,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
text_portion_enumeration_test \
var_fields \
xscriptprovider \
+   xtextfieldssupplier \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xtextfieldssupplier.odt 
b/sw/qa/python/testdocuments/xtextfieldssupplier.odt
new file mode 100644
index ..0b7764a2b6aa
Binary files /dev/null and b/sw/qa/python/testdocuments/xtextfieldssupplier.odt 
differ
diff --git a/sw/qa/python/xtextfieldssupplier.py 
b/sw/qa/python/xtextfieldssupplier.py
new file mode 100755
index ..ab1e96f89246
--- /dev/null
+++ b/sw/qa/python/xtextfieldssupplier.py
@@ -0,0 +1,89 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.container import NoSuchElementException
+import uno
+
+
+class TestXTextFieldsSupplier(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_getTextFields(self):
+xDoc = self.__class__._uno.openDocFromTDOC("xtextfieldssupplier.odt")
+self.assertIsNotNone(xDoc, "document was not loaded")
+xTextFieldsSupplier = xDoc
+
+# Get text fields collection
+xTextFields = xTextFieldsSupplier.getTextFields()
+self.assertIsNotNone(xTextFields, "getTextFields fails")
+
+# Iterate through collection and ensure that we receive expected fields
+fieldTypesList = [
+"com.sun.star.text.textfield.PageNumber",
+"com.sun.star.text.textfield.Annotation",
+"com.sun.star.text.textfield.docinfo.CreateDateTime"
+]
+xFieldEnum = xTextFields.createEnumeration()
+for fieldType, xField in zip(fieldTypesList, xFieldEnum):
+self.assertTrue(xField.supportsService(fieldType),
+"field " + xField.getPresentation(True) +
+" does not support " + fieldType + " service!")
+
+xDoc.close(True)
+
+def test_getTextFieldMasters(self):
+xDoc = self.__class__._uno.openDocFromTDOC("xtextfieldssupplier.odt")
+self.assertIsNotNone(xDoc, "document was not loaded")
+xTextFieldsSupplier = xDoc
+
+# Get text fields master
+xFieldMasters = xTextFieldsSupplier.getTextFieldMasters()
+self.assertIsNotNone(xFieldMasters, "getTextFieldMasters fails")
+self.assertTrue(xFieldMasters.hasElements(), "TextFieldMaster has no 
elements")
+
+# Check elements in TextFieldsMaster collection
+masterNames = [
+"com.sun.star.text.fieldmaster.SetExpression.Illustration",
+"com.sun.star.text.fieldmaster.SetExpression.Table",
+"com.sun.star.text.fieldmaster.SetExpression.Text",
+"com.sun.star.text.fieldmaster.SetExpression.Drawing",
+"com.sun.star.text.fieldmaster.SetExpression.Figure",
+]
+for masterName in masterNames:
+self.assertTrue(xFieldMasters.hasByName(masterName),
+"TextFieldMaster has no element " + masterName)
+self.assertIsNotNone(xFieldMasters.getByName(masterName),
+ "can't get " + masterName + " from 
TextFieldMaster")
+
+# Ensure that invalid elements are not accessible
+invalidMasterName = 
"com.sun.star.text.fieldmaster.SetExpression.NoSuchMaster"
+self.assertFalse(xFieldMasters.hasByName(invalidMasterName),
+ "TextFieldMaster has element " + invalidMasterName)
+
+with 

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-09-25 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/check_xnamedgraph.py  |  168 +
 sw/qa/python/testdocuments/XNamedGraph.ott |binary
 3 files changed, 169 insertions(+)

New commits:
commit 6d3a04546542156d50151cf9b4507661bde39df0
Author: Serge Krot 
AuthorDate: Thu Sep 20 14:39:20 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Tue Sep 25 17:17:50 2018 +0200

sw: new unit test for XNamedGraph

Change-Id: I222179c92cda3e0b2503544b7f120f35957265ac
Reviewed-on: https://gerrit.libreoffice.org/60815
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 2e2ef509add2..13bf75122742 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -25,6 +25,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_styles \
check_xtexttable \
check_table \
+   check_xnamedgraph \
get_expression \
set_expression \
text_portion_enumeration_test \
diff --git a/sw/qa/python/check_xnamedgraph.py 
b/sw/qa/python/check_xnamedgraph.py
new file mode 100644
index ..75d030fd3e3b
--- /dev/null
+++ b/sw/qa/python/check_xnamedgraph.py
@@ -0,0 +1,168 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+
+
+class XNamedGraph(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_getStatements(self):
+xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+xRepo = xDMA.getRDFRepository()
+xGraphs = xRepo.getGraphNames()
+
+all = self.getStatementsCount(xGraphs, xDMA, None, None)
+self.assertTrue(all > 0)
+
+# check that we have some node from the second RDF graph
+# (but not any from the list of LO standard nodes)
+DATE_URI_STR = "http://www.wollmux.org/WollMuxMetadata#WollMuxVersion;
+xUri = self.nameToUri(DATE_URI_STR)
+
+onlyWollMux = self.getStatementsCount(xGraphs, xDMA, xUri, None)
+self.assertTrue(onlyWollMux > 0)
+self.assertTrue(onlyWollMux < all)
+
+xDMA.close(True)
+
+def test_Statements_AddRemove(self):
+# take any first graph
+xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+xGraph = self.getAnyGraph(xDMA)
+
+DATE_URI_STR = "http://www.example.com/Metadata#Version;
+OBJECT_STR = "foo"
+
+# not exist => add => remove
+self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+self.addStatement(xDMA, xGraph, DATE_URI_STR, OBJECT_STR)
+self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+self.removeStatement(xDMA, xGraph, DATE_URI_STR, None)
+self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+
+xDMA.close(True)
+
+def test_Statements_RemoveByObject(self):
+# take any first graph
+xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+xGraph = self.getAnyGraph(xDMA)
+
+DATE_URI_STR = "http://www.example.com/Metadata#Version;
+OBJECT_STR = "foo"
+
+# remove by object
+self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+self.addStatement(xDMA, xGraph, DATE_URI_STR, OBJECT_STR)
+self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+self.removeStatement(xDMA, xGraph, None, OBJECT_STR)
+self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR))
+
+xDMA.close(True)
+
+def test_Statements_RemoveByObject(self):
+# take any first graph
+xDMA = self._uno.openTemplateFromTDOC("XNamedGraph.ott")
+xGraph = self.getAnyGraph(xDMA)
+
+DATE_URI_STR_1 = "http://www.example.com/Metadata#Version;
+DATE_URI_STR_2 = "http://www.example.com/Metadata#Second;
+OBJECT_STR = "foo"
+
+# remove several with one call
+self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR_1))
+self.assertFalse(self.hasStatement(xDMA, xGraph, DATE_URI_STR_2))
+self.addStatement(xDMA, xGraph, DATE_URI_STR_1, OBJECT_STR)
+self.addStatement(xDMA, xGraph, DATE_URI_STR_2, OBJECT_STR)
+self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR_1))
+self.assertTrue(self.hasStatement(xDMA, xGraph, DATE_URI_STR_2))
+self.removeStatement(xDMA, xGraph, None, OBJECT_STR)
+  

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-09-25 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk|1 
 sw/qa/python/check_xtexttable.py  |   78 ++
 sw/qa/python/testdocuments/XTextTable.odt |binary
 3 files changed, 79 insertions(+)

New commits:
commit 0a853def66bdaa9fbf2a6025aeb4351388235671
Author: Serge Krot 
AuthorDate: Tue Sep 18 17:52:35 2018 +0200
Commit: Thorsten Behrens 
CommitDate: Tue Sep 25 17:16:17 2018 +0200

sw: new unit test for XTextTable

Change-Id: Ide5e7dd75ddb30eb1db61406c6811c6846d603bd
Reviewed-on: https://gerrit.libreoffice.org/60694
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt 
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index b9d8d509ced3..2e2ef509add2 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -23,6 +23,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_named_property_values \
check_indexed_property_values \
check_styles \
+   check_xtexttable \
check_table \
get_expression \
set_expression \
diff --git a/sw/qa/python/check_xtexttable.py b/sw/qa/python/check_xtexttable.py
new file mode 100644
index ..9823ed86909b
--- /dev/null
+++ b/sw/qa/python/check_xtexttable.py
@@ -0,0 +1,78 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+import random
+
+
+class XTextTable(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_newTable(self):
+xDoc = XTextTable._uno.openEmptyWriterDoc()
+xTable = xDoc.createInstance("com.sun.star.text.TextTable")
+xTable.initialize(4, 3)
+xCursor = xDoc.Text.createTextCursor()
+xDoc.Text.insertTextContent(xCursor, xTable, False)
+xTable.Data = ((1, 2, 3), (4, 5, 6), (7, 8, 9), (10, 11, 12))
+
+self.checkTable(xTable)
+xDoc.close(True)
+
+def test_tableFromOdt(self):
+hasNestedTable = False
+
+xDoc = self._uno.openTemplateFromTDOC("XTextTable.odt")
+itr = iter(xDoc.Text.createEnumeration())
+for element in itr:
+if element.supportsService("com.sun.star.text.TextTable"):
+self.checkTable(element)
+
+# in second table, inside B1 cell we have nested table
+xCellB1 = element.getCellByName("B1")
+self.assertIsNotNone(xCellB1)
+cellContent = iter(xCellB1.Text.createEnumeration())
+for cellElement in cellContent:
+if 
cellElement.supportsService("com.sun.star.text.TextTable"):
+self.checkTable(cellElement)
+hasNestedTable = True
+
+self.assertTrue(hasNestedTable)
+xDoc.close(True)
+
+def checkTable(self, xTable):
+# in order
+xNames = xTable.getCellNames()
+for xName in xNames:
+xCell = xTable.getCellByName(xName)
+self.assertIsNotNone(xCell)
+
+# random access
+xNames = xTable.getCellNames()
+for i in random.sample(range(0, len(xNames)), len(xNames)):
+xName = xNames[i]
+xCell = xTable.getCellByName(xName)
+self.assertIsNotNone(xCell)
+
+# wrong name
+xCell = xTable.getCellByName('WRONG CELL NAME')
+self.assertIsNone(xCell)
+
+
+if __name__ == '__main__':
+unittest.main()
diff --git a/sw/qa/python/testdocuments/XTextTable.odt 
b/sw/qa/python/testdocuments/XTextTable.odt
new file mode 100644
index ..2c15fc781a52
Binary files /dev/null and b/sw/qa/python/testdocuments/XTextTable.odt differ
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2018-09-19 Thread Libreoffice Gerrit user
 sw/PythonTest_sw_python.mk |1 
 sw/qa/python/testdocuments/xscriptprovider.odt |binary
 sw/qa/python/xscriptprovider.py|   74 +
 3 files changed, 75 insertions(+)

New commits:
commit 62cd86977ca41677c56fb2d1f97bb1c5cbdbd416
Author: Vasily Melenchuk 
AuthorDate: Mon Sep 17 21:57:26 2018 +0300
Commit: Thorsten Behrens 
CommitDate: Wed Sep 19 23:50:01 2018 +0200

sw: new unit test for XScriptProvider

Change-Id: I2954bff51d6a507fef4d8a22ff5964735f1cee60
Reviewed-on: https://gerrit.libreoffice.org/60640
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index c47c5cbcbbd3..b9d8d509ced3 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -28,6 +28,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
set_expression \
text_portion_enumeration_test \
var_fields \
+   xscriptprovider \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/sw/qa/python/testdocuments/xscriptprovider.odt 
b/sw/qa/python/testdocuments/xscriptprovider.odt
new file mode 100644
index ..fa3b8ec75229
Binary files /dev/null and b/sw/qa/python/testdocuments/xscriptprovider.odt 
differ
diff --git a/sw/qa/python/xscriptprovider.py b/sw/qa/python/xscriptprovider.py
new file mode 100644
index ..b79b379ad16d
--- /dev/null
+++ b/sw/qa/python/xscriptprovider.py
@@ -0,0 +1,74 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.script.provider import ScriptFrameworkErrorException
+import uno
+
+
+class TestXScriptProvider(unittest.TestCase):
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_getScriptApplication(self):
+# getScript for built-in StarBasic function
+xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
+xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
+xScript = xScriptProvider.getScript(
+"vnd.sun.star.script:Tools.Misc.CreateNewDocument?language=Basic&"
+"location=application")
+self.assertIsNotNone(xScript, "xScript was not loaded")
+
+def test_getScriptDocument(self):
+# getScript for StarBasic function in loaded document
+xDoc = self.__class__._uno.openTemplateFromTDOC("xscriptprovider.odt")
+xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
+xScriptProvider = 
xMasterScriptProviderFactory.createScriptProvider(xDoc)
+xScript = xScriptProvider.getScript(
+"vnd.sun.star.script:Standard.Module1.Main?language=Basic&"
+"location=document")
+self.assertIsNotNone(xScript, "xScript was not loaded")
+xDoc.close(True)
+
+def test_getScriptInvalidURI(self):
+# getScript fails with invalid URI
+xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
+xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
+with self.assertRaises(ScriptFrameworkErrorException):
+xScript = xScriptProvider.getScript("invalid URI, isn't it?")
+
+def test_getScriptNotFound(self):
+# getScript fails when script not found
+xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
+xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
+with self.assertRaises(ScriptFrameworkErrorException):
+xScript = xScriptProvider.getScript(
+"vnd.sun.star.script:NotExisting.NotExisting.NotExisting?"
+"language=Basic=document")
+
+def createMasterScriptProviderFactory(self):
+xServiceManager = uno.getComponentContext().ServiceManager
+return xServiceManager.createInstanceWithContext(
+"com.sun.star.script.provider.MasterScriptProviderFactory",
+uno.getComponentContext())
+
+
+if __name__ == '__main__':
+unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2017-06-14 Thread jmzambon
 sw/PythonTest_sw_python.mk   |1 
 sw/qa/complex/writer/TextPortionEnumerationTest.java |  205 ---
 sw/qa/python/text_portion_enumeration_test.py| 1023 +++
 3 files changed, 1024 insertions(+), 205 deletions(-)

New commits:
commit e07492e14790262abc24d44c280bd71e5ebeddf4
Author: jmzambon 
Date:   Mon Jun 5 19:16:35 2017 +0200

tdf#97362: TextPortionEnumerationTest partially migrated to python 
(test_portion_enumeration_test.py)

Add footnote tests:
- test_refmark_point
- test_refmark
- test_toxmark_point
- test_toxmark
- test_hyperlink
- test_hyperlink_empty
- test_ruby
- test_ruby_empty

Change-Id: I0920517b5e8806a5fc46708822fed33006f03fd5
Reviewed-on: https://gerrit.libreoffice.org/38418
Tested-by: Jenkins 
Reviewed-by: Miklos Vajna 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 6676cff2da74..2d1d8bb44eca 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -26,6 +26,7 @@ $(eval $(call 
gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
check_table \
get_expression \
set_expression \
+   text_portion_enumeration_test \
var_fields \
 ))
 
diff --git a/sw/qa/complex/writer/TextPortionEnumerationTest.java 
b/sw/qa/complex/writer/TextPortionEnumerationTest.java
index e36fc650b500..358d772cb6a5 100644
--- a/sw/qa/complex/writer/TextPortionEnumerationTest.java
+++ b/sw/qa/complex/writer/TextPortionEnumerationTest.java
@@ -1258,211 +1258,6 @@ public class TextPortionEnumerationTest
 util.DesktopTools.closeDoc(m_xDoc);
 }
 
-@Test public void testText() throws Exception
-{
-TreeNode root = new TreeNode();
-TreeNode text = new TextNode("abc");
-root.appendChild(text);
-doTest(root);
-}
-
-@Test public void testTextField() throws Exception
-{
-mkName("ruby");
-TreeNode root = new TreeNode();
-TreeNode txtf = new TextFieldNode("abc");
-root.appendChild(txtf);
-doTest(root);
-}
-
-/*@Test*/ public void testControlChar() throws Exception
-{
-//FIXME this is converted to a text portion: ControlCharacter is obsolete
-TreeNode root = new TreeNode();
-TreeNode cchr = new ControlCharacterNode(HARD_HYPHEN);
-root.appendChild(cchr);
-doTest(root);
-}
-
-/*@Test*/ public void testSoftPageBreak() throws Exception
-{
-//FIXME: insert a soft page break: not done
-TreeNode root = new TreeNode();
-TreeNode spbk = new SoftPageBreakNode();
-TreeNode text = new TextNode("abc");
-root.appendChild(spbk);
-root.appendChild(text);
-doTest(root);
-}
-
-@Test public void testFootnote() throws Exception
-{
-String name = mkName("ftn");
-TreeNode root = new TreeNode();
-TreeNode ftnd = new FootnoteNode(name);
-root.appendChild(ftnd);
-doTest(root);
-}
-
-@Test public void testFrameAs() throws Exception
-{
-String name = mkName("frame");
-TreeNode root = new TreeNode();
-TreeNode fram = new FrameNode(name, AS_CHARACTER);
-root.appendChild(fram);
-doTest(root);
-}
-
-@Test public void testFrameAt() throws Exception
-{
-String name = mkName("frame");
-TreeNode root = new TreeNode();
-TreeNode fram = new FrameNode(name, AT_CHARACTER);
-root.appendChild(fram);
-doTest(root);
-}
-
-@Test public void testBookmarkPoint() throws Exception
-{
-String name = mkName("mark");
-TreeNode root = new TreeNode();
-TreeNode bkmk = new BookmarkNode(name);
-TreeNode text = new TextNode("abc");
-root.appendChild(bkmk);
-root.appendChild(text);
-doTest(root);
-}
-
-@Test public void testBookmark() throws Exception
-{
-String name = mkName("mark");
-TreeNode root = new TreeNode();
-TreeNode bkm1 = new BookmarkStartNode(name);
-TreeNode text = new TextNode("abc");
-TreeNode bkm2 = new BookmarkEndNode(name);
-root.appendChild(bkm1);
-root.appendChild(text);
-root.appendChild(bkm2);
-doTest(root);
-}
-
-@Test public void testBookmarkPointXmlId() throws Exception
-{
-String name = mkName("mark");
-StringPair id = mkId("id");
-TreeNode root = new TreeNode();
-TreeNode bkmk = new BookmarkNode(name, id);
-TreeNode text = new TextNode("abc");
-root.appendChild(bkmk);
-root.appendChild(text);
-doTest(root);
-}
-
-@Test public void testBookmarkXmlId() throws Exception
-{
-String name = mkName("mark");
-StringPair id = mkId("id");
-TreeNode root = new TreeNode();
-

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2015-12-15 Thread kadertarlan
 sw/PythonTest_sw_python.mk   |3 
 sw/qa/complex/writer/CheckFlies.java |  207 ---
 sw/qa/python/check_flies.py  |  126 +
 3 files changed, 128 insertions(+), 208 deletions(-)

New commits:
commit b71540c1980955b439d334c875f47d2ee44e4c5f
Author: kadertarlan 
Date:   Mon Dec 14 17:06:17 2015 +0200

Java unit tests were converted to Python unit tests

Remark test document not moved, due to other test cases.

Change-Id: I9564b72fae60cceb60121fec06e1ed015add8453
Reviewed-on: https://gerrit.libreoffice.org/20703
Reviewed-by: jan iversen 
Tested-by: jan iversen 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 695bbf9..c24d418 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -15,7 +15,8 @@ $(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_flies \
+   check_fields \
check_styles \
check_table \
get_expression \
diff --git a/sw/qa/complex/writer/CheckFlies.java 
b/sw/qa/complex/writer/CheckFlies.java
deleted file mode 100644
index 6682696..000
--- a/sw/qa/complex/writer/CheckFlies.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-package complex.writer;
-
-import com.sun.star.lang.XMultiServiceFactory;
-import com.sun.star.text.XTextDocument;
-import com.sun.star.uno.UnoRuntime;
-import java.util.Collection;
-import java.util.ArrayList;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.openoffice.test.OfficeConnection;
-import static org.junit.Assert.*;
-
-public class CheckFlies {
-@Test public void checkFlies()
-throws com.sun.star.uno.Exception
-{
-com.sun.star.text.XTextFramesSupplier xTFS = UnoRuntime.queryInterface(
-com.sun.star.text.XTextFramesSupplier.class,
-document);
-checkTextFrames(xTFS);
-com.sun.star.text.XTextGraphicObjectsSupplier xTGOS = 
UnoRuntime.queryInterface(
-com.sun.star.text.XTextGraphicObjectsSupplier.class,
-document);
-checkGraphicFrames(xTGOS);
-com.sun.star.text.XTextEmbeddedObjectsSupplier xTEOS = 
UnoRuntime.queryInterface(
-com.sun.star.text.XTextEmbeddedObjectsSupplier.class,
-document);
-checkEmbeddedFrames(xTEOS);
-}
-
-private void 
checkEmbeddedFrames(com.sun.star.text.XTextEmbeddedObjectsSupplier xTGOS)
-throws com.sun.star.uno.Exception
-{
-Collection vExpectedEmbeddedFrames = new ArrayList();
-vExpectedEmbeddedFrames.add("Object1");
-int nEmbeddedFrames = vExpectedEmbeddedFrames.size();
-com.sun.star.container.XNameAccess xEmbeddedFrames = 
xTGOS.getEmbeddedObjects();
-for(String sFrameName : xEmbeddedFrames.getElementNames())
-{
-assertTrue(
-"Unexpected frame name",
-vExpectedEmbeddedFrames.remove(sFrameName));
-xEmbeddedFrames.getByName(sFrameName);
-assertTrue(
-"Could not find embedded frame by name.",
-xEmbeddedFrames.hasByName(sFrameName));
-}
-assertTrue(
-"Missing expected embedded frames.",
-vExpectedEmbeddedFrames.isEmpty());
-try
-{
-xEmbeddedFrames.getByName("Nonexisting embedded frame");
-fail("Got nonexisting embedded frame");
-}
-catch(com.sun.star.container.NoSuchElementException e)
-{}
-assertFalse(
-"Has nonexisting embedded frame",
-xEmbeddedFrames.hasByName("Nonexisting embedded frame"));
-
-com.sun.star.container.XIndexAccess xEmbeddedFramesIdx = 
UnoRuntime.queryInterface(
-com.sun.star.container.XIndexAccess.class,
-xEmbeddedFrames);
-assertEquals(
-

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

2015-12-11 Thread Bjoern Michaelsen
 sw/PythonTest_sw_python.mk  |1 
 sw/qa/python/check_styles.py|  107 
 sw/source/core/unocore/unostyle.cxx |   15 ++---
 3 files changed, 115 insertions(+), 8 deletions(-)

New commits:
commit ce3d3f5543e3e132a3473af27aa2c827336add0f
Author: Bjoern Michaelsen 
Date:   Thu Dec 10 18:43:32 2015 +0100

add test for UNO writer style families ...

... and fix the breakages it finds.

Change-Id: Ibc7289cc0cd7fb5648d686bd55afff9016f58b3b
Reviewed-on: https://gerrit.libreoffice.org/20638
Reviewed-by: Björn Michaelsen 
Tested-by: Jenkins 

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 52907c1..695bbf9 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 000..a9b0c81
--- /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', 

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2013-08-20 Thread Xiaoli
 sw/PythonTest_sw_python.mk  |1 
 sw/qa/python/check_table.py |  260 
 2 files changed, 261 insertions(+)

New commits:
commit d89e02e4a7100bff3e7d81c389cdbc6d43adf480
Author: Xiaoli duan19002...@gmail.com
Date:   Sun Jul 7 22:41:52 2013 +0200

Translate writer test 'Checktable.java' to Python

Change-Id: I66a36acdb4aa67d438fb36597f41e847bbde10e3
Reviewed-on: https://gerrit.libreoffice.org/4796
Reviewed-by: Petr Mladek pmla...@suse.cz
Tested-by: Petr Mladek pmla...@suse.cz

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 9421249..52907c1 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_table \
get_expression \
set_expression \
var_fields \
diff --git a/sw/qa/python/check_table.py b/sw/qa/python/check_table.py
new file mode 100644
index 000..2760e7c
--- /dev/null
+++ b/sw/qa/python/check_table.py
@@ -0,0 +1,260 @@
+import unittest
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.uno import RuntimeException
+from com.sun.star.table import BorderLine
+from com.sun.star.table import BorderLine2
+from com.sun.star.table.BorderLineStyle import (DOUBLE, SOLID, EMBOSSED,\
+THICKTHIN_LARGEGAP, DASHED, DOTTED)
+
+class CheckTable(unittest.TestCase):
+_uno = None
+_xDoc = None
+_xDocF = None
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+cls._xDoc = cls._uno.openEmptyWriterDoc()
+cls._xDocF = cls._uno.openEmptyWriterDoc()
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown()
+
+def test_tableborder(self):
+xDoc = self.__class__._xDoc
+# insert table
+xTable = xDoc.createInstance(com.sun.star.text.TextTable)
+xTable.initialize(3, 3)
+xText = xDoc.getText()
+xCursor = xText.createTextCursor()
+xText.insertTextContent(xCursor, xTable, False)
+
+border = xTable.getPropertyValue(TableBorder)
+
+self.assertTrue(border.IsTopLineValid)
+self.assertEquals(0, border.TopLine.InnerLineWidth)
+self.assertEquals(2, border.TopLine.OuterLineWidth)
+self.assertEquals(0, border.TopLine.LineDistance)
+self.assertEquals(0, border.TopLine.Color)
+
+self.assertTrue(border.IsBottomLineValid)
+self.assertEquals(0, border.BottomLine.InnerLineWidth)
+self.assertEquals(2, border.BottomLine.OuterLineWidth)
+self.assertEquals(0, border.BottomLine.LineDistance)
+self.assertEquals(0, border.BottomLine.Color)
+
+self.assertTrue(border.IsLeftLineValid)
+self.assertEquals(0, border.LeftLine.InnerLineWidth)
+self.assertEquals(2, border.LeftLine.OuterLineWidth)
+self.assertEquals(0, border.LeftLine.LineDistance)
+self.assertEquals(0, border.LeftLine.Color)
+
+self.assertTrue(border.IsRightLineValid)
+self.assertEquals(0, border.RightLine.InnerLineWidth)
+self.assertEquals(2, border.RightLine.OuterLineWidth)
+self.assertEquals(0, border.RightLine.LineDistance)
+self.assertEquals(0, border.RightLine.Color)
+
+self.assertTrue(border.IsHorizontalLineValid)
+self.assertEquals(0, border.HorizontalLine.InnerLineWidth)
+self.assertEquals(2, border.HorizontalLine.OuterLineWidth)
+self.assertEquals(0, border.HorizontalLine.LineDistance)
+self.assertEquals(0, border.HorizontalLine.Color)
+
+self.assertTrue(border.IsVerticalLineValid)
+self.assertEquals(0, border.VerticalLine.InnerLineWidth)
+self.assertEquals(2, border.VerticalLine.OuterLineWidth)
+self.assertEquals(0, border.VerticalLine.LineDistance)
+self.assertEquals(0, border.VerticalLine.Color)
+
+self.assertTrue(border.IsDistanceValid)
+self.assertEquals(97, border.Distance)
+# set border
+border.TopLine= BorderLine(0,  11, 19, 19)
+border.BottomLine = BorderLine(0xFF,   00, 11, 00)
+border.HorizontalLine = BorderLine(0xFF00, 00, 90, 00)
+xTable.setPropertyValue(TableBorder, border)
+# read set border
+border = xTable.getPropertyValue(TableBorder)
+
+self.assertTrue(border.IsTopLineValid)
+self.assertEquals(11, border.TopLine.InnerLineWidth)
+self.assertEquals(19, border.TopLine.OuterLineWidth)
+self.assertEquals(19, border.TopLine.LineDistance)
+self.assertEquals(0, border.TopLine.Color)
+
+self.assertTrue(border.IsBottomLineValid)
+self.assertEquals(0, border.BottomLine.InnerLineWidth)
+self.assertEquals(11, border.BottomLine.OuterLineWidth)
+self.assertEquals(0, 

[Libreoffice-commits] core.git: sw/PythonTest_sw_python.mk sw/qa

2013-06-17 Thread Xiaoli
 sw/PythonTest_sw_python.mk  |1 
 sw/qa/python/check_index.py |   97 
 2 files changed, 98 insertions(+)

New commits:
commit 99eee227ac5a96a2657e26d64b8fbf228fd10bf2
Author: Xiaoli duan19002...@gmail.com
Date:   Sun Jun 16 17:13:43 2013 +0200

migrate check_index test from Java to Python

Change-Id: I5080cb0c3ca4b28d197137407da0d5f5b3d6c6d7
Reviewed-on: https://gerrit.libreoffice.org/4310
Reviewed-by: David Ostrovsky david.ostrov...@gmx.de
Tested-by: David Ostrovsky david.ostrov...@gmx.de

diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index cbddfc5..0b582a2 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -10,6 +10,7 @@
 $(eval $(call gb_PythonTest_PythonTest,sw_python))
 
 $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
+   check_index \
get_expression \
set_expression \
var_fields \
diff --git a/sw/qa/python/check_index.py b/sw/qa/python/check_index.py
new file mode 100644
index 000..6ea5b0b
--- /dev/null
+++ b/sw/qa/python/check_index.py
@@ -0,0 +1,97 @@
+import unittest
+import unohelper
+import os
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
+from com.sun.star.util import XRefreshListener
+
+class RefreshListener(XRefreshListener, unohelper.Base):
+ 
+def __init__(self):
+self.m_bDisposed = False
+self.m_bRefreshed = False
+
+def disposing(self, event):
+self.m_bDisposed = True
+
+def refreshed(self, event):
+self.m_bRefreshed = True
+
+def assertRefreshed(self):
+assert(self.m_bRefreshed)
+self.m_bRefreshed = False
+
+class CheckIndex(unittest.TestCase):
+_uno = None
+_xDoc = None
+
+@classmethod
+def setUpClass(cls):
+cls._uno = UnoInProcess()
+cls._uno.setUp()
+cls._xDoc = cls._uno.openEmptyWriterDoc()
+
+@classmethod
+def tearDownClass(cls):
+cls._uno.tearDown() 
+   
+def test_check_index(self):
+xDoc = self.__class__._xDoc
+xIndex = xDoc.createInstance(com.sun.star.text.ContentIndex)
+xBodyText = xDoc.getText()
+xCursor = xBodyText.createTextCursor()
+xIndex.setPropertyValue(CreateFromOutline, True)
+xBodyText.insertTextContent(xCursor, xIndex, True)
+
+# register listener
+listener = RefreshListener()
+xIndex.addRefreshListener(listener)
+self.assertFalse(listener.m_bRefreshed)
+xIndex.refresh()
+listener.assertRefreshed()
+
+# insert some heading
+xCursor.gotoEnd(False)
+xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
+xCursor.gotoEnd(False)
+test_string = a heading
+xCursor.setString(test_string)
+xCursor.gotoStartOfParagraph(True)
+xCursor.setPropertyValue(ParaStyleName,Heading 1)
+
+# hope text is in last paragraph...
+xIndex.refresh()
+listener.assertRefreshed()
+xCursor.gotoRange(xIndex.getAnchor().getEnd(), False)
+xCursor.gotoStartOfParagraph(True)
+text = xCursor.getString()
+# check if we got text with 'test_string'
+assert( text.find(test_string) = 0 )
+
+# insert some more heading
+xCursor.gotoEnd(False)
+xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
+xCursor.gotoEnd(False)
+test_string = yet another heading
+xCursor.setString(test_string)
+xCursor.gotoStartOfParagraph(True)
+xCursor.setPropertyValue(ParaStyleName,Heading 1)
+
+# try agian with update
+xIndex.update()
+listener.assertRefreshed()
+xCursor.gotoRange(xIndex.getAnchor().getEnd(), False)
+xCursor.gotoStartOfParagraph(True)
+text = xCursor.getString()
+# check if we got text with 'test_string'
+assert( text.find(test_string) = 0 )
+ 
+# dispose must call the listener
+assert(not listener.m_bDisposed)
+xIndex.dispose()
+assert(listener.m_bDisposed)
+
+# close the document
+xDoc.dispose()
+if __name__ == __main__:
+unittest.main()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits