summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorXiaoli <duan19002009@gmail.com>2013-06-16 17:13:43 +0200
committerDavid Ostrovsky <David.Ostrovsky@gmx.de>2013-06-17 04:09:22 +0000
commit99eee227ac5a96a2657e26d64b8fbf228fd10bf2 (patch)
tree7c2f62c55bb7a42128b71b5447cfdeeb54639dbe /sw
parent76a901298ea850f2150fd01ecf564cdcd7c6d798 (diff)
migrate check_index test from Java to Python
Change-Id: I5080cb0c3ca4b28d197137407da0d5f5b3d6c6d7 Reviewed-on: https://gerrit.libreoffice.org/4310 Reviewed-by: David Ostrovsky <David.Ostrovsky@gmx.de> Tested-by: David Ostrovsky <David.Ostrovsky@gmx.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/PythonTest_sw_python.mk1
-rw-r--r--sw/qa/python/check_index.py97
2 files changed, 98 insertions, 0 deletions
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index cbddfc513c8e..0b582a2b1c05 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 000000000000..6ea5b0b138f2
--- /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()