| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# #################################################################### |
| 5 |
# Copyright (C) 2005-2019 by the FIFE team |
| 6 |
# http://www.fifengine.net |
| 7 |
# This file is part of FIFE. |
| 8 |
# |
| 9 |
# FIFE is free software; you can redistribute it and/or |
| 10 |
# modify it under the terms of the GNU Lesser General Public |
| 11 |
# License as published by the Free Software Foundation; either |
| 12 |
# version 2.1 of the License, or (at your option) any later version. |
| 13 |
# |
| 14 |
# This library is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
# Lesser General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU Lesser General Public |
| 20 |
# License along with this library; if not, write to the |
| 21 |
# Free Software Foundation, Inc., |
| 22 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 |
# #################################################################### |
| 24 |
|
| 25 |
from .swig_test_utils import * |
| 26 |
|
| 27 |
class MyEventListener(fife.ICommandListener): |
| 28 |
def __init__(self): |
| 29 |
fife.ICommandListener.__init__(self) |
| 30 |
|
| 31 |
def onCommand(self, command): |
| 32 |
print("received command with code %d" % command.getCode()) |
| 33 |
|
| 34 |
class TestEventChannel(unittest.TestCase): |
| 35 |
|
| 36 |
def setUp(self): |
| 37 |
self.engine = getEngine(True) |
| 38 |
self.eventmanager = self.engine.getEventManager() |
| 39 |
|
| 40 |
def tearDown(self): |
| 41 |
self.engine.destroy() |
| 42 |
|
| 43 |
def testEvents(self): |
| 44 |
l = MyEventListener() |
| 45 |
self.eventmanager.addCommandListener(l) |
| 46 |
cmd = fife.Command() |
| 47 |
cmd.setCode(0) |
| 48 |
print("Sending commands...") |
| 49 |
for i in range(20): |
| 50 |
self.eventmanager.dispatchCommand(cmd) |
| 51 |
cmd.setCode(i) |
| 52 |
self.eventmanager.removeCommandListener(l) |
| 53 |
|
| 54 |
TEST_CLASSES = [TestEventChannel] |
| 55 |
|
| 56 |
if __name__ == '__main__': |
| 57 |
unittest.main() |