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/.
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
):
22 def queryClosing(self
, Source
, GetsOwnership
):
23 if GetsOwnership
is True:
24 global listenerCallsOwner
25 listenerCallsOwner
+= 1
27 global listenerCallsNoOwner
28 listenerCallsNoOwner
+= 1
31 def notifyClosing(self
, Source
):
35 def disposing(self
, Event
):
39 class XCloseable(unittest
.TestCase
):
43 cls
._uno
= UnoInProcess()
47 def tearDownClass(cls
):
50 def test_closeTrue(self
):
52 global listenerCallsOwner
53 global listenerCallsNoOwner
54 listenerCallsOwner
= 0
55 listenerCallsNoOwner
= 0
58 xDoc
= self
._uno
.openEmptyWriterDoc()
59 xListener
= XCloseListenerExtended()
60 xDoc
.addCloseListener(xListener
)
64 self
.assertEqual(1, listenerCallsOwner
)
65 self
.assertEqual(0, listenerCallsNoOwner
)
67 def test_closeFalse(self
):
69 global listenerCallsOwner
70 global listenerCallsNoOwner
71 listenerCallsOwner
= 0
72 listenerCallsNoOwner
= 0
75 xDoc
= self
._uno
.openEmptyWriterDoc()
76 xListener
= XCloseListenerExtended()
77 xDoc
.addCloseListener(xListener
)
81 self
.assertEqual(0, listenerCallsOwner
)
82 self
.assertEqual(1, listenerCallsNoOwner
)
85 if __name__
== '__main__':
88 # vim: set shiftwidth=4 softtabstop=4 expandtab: