Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / python / check_xcloseable.py
blob172b852dcd0060b29b42b22089aa288f0448b8f3
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 XCloseListener
16 listenerCallsOwner = 0
17 listenerCallsNoOwner = 0
20 class XCloseListenerExtended(unohelper.Base, XCloseListener):
21 @classmethod
22 def queryClosing(self, Source, GetsOwnership):
23 if GetsOwnership is True:
24 global listenerCallsOwner
25 listenerCallsOwner += 1
26 else:
27 global listenerCallsNoOwner
28 listenerCallsNoOwner += 1
30 @classmethod
31 def notifyClosing(self, Source):
32 pass
34 @classmethod
35 def disposing(self, Event):
36 pass
39 class XCloseable(unittest.TestCase):
41 @classmethod
42 def setUpClass(cls):
43 cls._uno = UnoInProcess()
44 cls._uno.setUp()
46 @classmethod
47 def tearDownClass(cls):
48 cls._uno.tearDown()
50 def test_closeTrue(self):
51 # prepare
52 global listenerCallsOwner
53 global listenerCallsNoOwner
54 listenerCallsOwner = 0
55 listenerCallsNoOwner = 0
57 # run
58 xDoc = self._uno.openEmptyWriterDoc()
59 xListener = XCloseListenerExtended()
60 xDoc.addCloseListener(xListener)
61 xDoc.close(True)
63 # verify results
64 self.assertEqual(1, listenerCallsOwner)
65 self.assertEqual(0, listenerCallsNoOwner)
67 def test_closeFalse(self):
68 # prepare
69 global listenerCallsOwner
70 global listenerCallsNoOwner
71 listenerCallsOwner = 0
72 listenerCallsNoOwner = 0
74 # run
75 xDoc = self._uno.openEmptyWriterDoc()
76 xListener = XCloseListenerExtended()
77 xDoc.addCloseListener(xListener)
78 xDoc.close(False)
80 # verify results
81 self.assertEqual(0, listenerCallsOwner)
82 self.assertEqual(1, listenerCallsNoOwner)
85 if __name__ == '__main__':
86 unittest.main()
88 # vim: set shiftwidth=4 softtabstop=4 expandtab: