update emoji autocorrect entries from po-files
[LibreOffice.git] / sw / qa / python / check_index.py
blob4d3076c43b9a82b9bae0a1886f19d8174b4762c9
1 import unittest
2 import unohelper
3 import os
4 from org.libreoffice.unotest import UnoInProcess
5 from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
6 from com.sun.star.util import XRefreshListener
8 class RefreshListener(XRefreshListener, unohelper.Base):
10 def __init__(self):
11 self.m_bDisposed = False
12 self.m_bRefreshed = False
14 def disposing(self, event):
15 self.m_bDisposed = True
17 def refreshed(self, event):
18 self.m_bRefreshed = True
20 def assertRefreshed(self):
21 assert(self.m_bRefreshed)
22 self.m_bRefreshed = False
24 class CheckIndex(unittest.TestCase):
25 _uno = None
26 _xDoc = None
28 @classmethod
29 def setUpClass(cls):
30 cls._uno = UnoInProcess()
31 cls._uno.setUp()
32 cls._xDoc = cls._uno.openEmptyWriterDoc()
34 @classmethod
35 def tearDownClass(cls):
36 cls._uno.tearDown()
38 def test_check_index(self):
39 xDoc = self.__class__._xDoc
40 xIndex = xDoc.createInstance("com.sun.star.text.ContentIndex")
41 xBodyText = xDoc.getText()
42 xCursor = xBodyText.createTextCursor()
43 xIndex.setPropertyValue("CreateFromOutline", True)
44 xBodyText.insertTextContent(xCursor, xIndex, True)
46 # register listener
47 listener = RefreshListener()
48 xIndex.addRefreshListener(listener)
49 self.assertFalse(listener.m_bRefreshed)
50 xIndex.refresh()
51 listener.assertRefreshed()
53 # insert some heading
54 xCursor.gotoEnd(False)
55 xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
56 xCursor.gotoEnd(False)
57 test_string = "a heading"
58 xCursor.setString(test_string)
59 xCursor.gotoStartOfParagraph(True)
60 xCursor.setPropertyValue("ParaStyleName","Heading 1")
62 # hope text is in last paragraph...
63 xIndex.refresh()
64 listener.assertRefreshed()
65 xCursor.gotoRange(xIndex.getAnchor().getEnd(), False)
66 xCursor.gotoStartOfParagraph(True)
67 text = xCursor.getString()
68 # check if we got text with 'test_string'
69 assert( text.find(test_string) >= 0 )
71 # insert some more heading
72 xCursor.gotoEnd(False)
73 xBodyText.insertControlCharacter(xCursor, PARAGRAPH_BREAK, False)
74 xCursor.gotoEnd(False)
75 test_string = "yet another heading"
76 xCursor.setString(test_string)
77 xCursor.gotoStartOfParagraph(True)
78 xCursor.setPropertyValue("ParaStyleName","Heading 1")
80 # try again with update
81 xIndex.update()
82 listener.assertRefreshed()
83 xCursor.gotoRange(xIndex.getAnchor().getEnd(), False)
84 xCursor.gotoStartOfParagraph(True)
85 text = xCursor.getString()
86 # check if we got text with 'test_string'
87 assert( text.find(test_string) >= 0 )
89 # dispose must call the listener
90 assert(not listener.m_bDisposed)
91 xIndex.dispose()
92 assert(listener.m_bDisposed)
94 # close the document
95 xDoc.dispose()
96 if __name__ == "__main__":
97 unittest.main()