Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / check_xrefreshable.py
blob0b7b89652c9ea230a35c971a5922bc6d99068708
1 #! /usr/bin/env python
2 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
4 # This file is part of the LibreOffice project.
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import unittest
11 import unohelper
12 from org.libreoffice.unotest import UnoInProcess
13 from com.sun.star.util import XRefreshListener
16 refreshed = 0
19 class XRefreshListenerExtended(unohelper.Base, XRefreshListener):
20 @classmethod
21 def refreshed(self, Event):
22 global refreshed
23 refreshed += 1
25 @classmethod
26 def disposing(self, event):
27 pass
30 class XRefreshable(unittest.TestCase):
32 @classmethod
33 def setUpClass(cls):
34 cls._uno = UnoInProcess()
35 cls._uno.setUp()
37 @classmethod
38 def tearDownClass(cls):
39 cls._uno.tearDown()
41 def test_None(self):
42 global refreshed
43 refreshed = 0
44 xDoc = self._uno.openEmptyWriterDoc()
46 # attempt to add/remove none
47 xDoc.addRefreshListener(None)
48 xDoc.removeRefreshListener(None)
50 # refresh without listeners
51 xDoc.refresh()
52 xDoc.close(True)
54 def test_refresh(self):
55 global refreshed
56 refreshed = 0
58 xDoc = self._uno.openEmptyWriterDoc()
59 xListener = XRefreshListenerExtended()
60 xDoc.addRefreshListener(xListener)
61 xDoc.refresh()
62 xDoc.removeRefreshListener(xListener)
63 self.assertEqual(1, refreshed)
64 xDoc.refresh()
65 self.assertEqual(1, refreshed)
66 xDoc.close(True)
68 def test_refreshTwice(self):
69 global refreshed
70 refreshed = 0
72 xDoc = self._uno.openEmptyWriterDoc()
73 xListener = XRefreshListenerExtended()
74 xDoc.addRefreshListener(xListener)
75 xDoc.refresh()
76 xDoc.refresh()
77 xDoc.removeRefreshListener(xListener)
78 self.assertEqual(2, refreshed)
79 xDoc.refresh()
80 self.assertEqual(2, refreshed)
81 xDoc.close(True)
83 def test_DoubleInstances(self):
84 global refreshed
85 refreshed = 0
87 xDoc = self._uno.openEmptyWriterDoc()
88 xListener = XRefreshListenerExtended()
90 xDoc.addRefreshListener(xListener)
91 xDoc.addRefreshListener(xListener)
92 xDoc.addRefreshListener(xListener)
94 xDoc.refresh()
95 xDoc.refresh()
96 self.assertEqual(3*2, refreshed)
98 refreshed = 0
99 xDoc.removeRefreshListener(xListener)
100 xDoc.refresh()
101 # two instances should remain in the list
102 self.assertEqual(2, refreshed)
104 xDoc.close(True)
107 if __name__ == '__main__':
108 unittest.main()
110 # vim: set shiftwidth=4 softtabstop=4 expandtab: