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
):
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
):
30 cls
._uno
= UnoInProcess()
32 cls
._xDoc
= cls
._uno
.openEmptyWriterDoc()
35 def tearDownClass(cls
):
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)
47 listener
= RefreshListener()
48 xIndex
.addRefreshListener(listener
)
49 self
.assertFalse(listener
.m_bRefreshed
)
51 listener
.assertRefreshed()
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...
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
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
)
92 assert(listener
.m_bDisposed
)
96 if __name__
== "__main__":