Debian Codegraph @

tests/swig_tests/timer_tests.py

raw
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 import time
27
28 class MyTimeEvent(fife.TimeEvent):
29 def __init__(self, period):
30 fife.TimeEvent.__init__(self, period)
31 self.counter = 0
32
33 def updateEvent(self, curtime):
34 print("testing timer event... %d, %d" % (curtime, self.counter))
35 self.counter += 1
36
37 class TestTimer(unittest.TestCase):
38 def setUp(self):
39 self.engine = getEngine(True)
40 self.timemanager = self.engine.getTimeManager()
41
42 def tearDown(self):
43 self.engine.destroy()
44
45 def testEvents(self):
46 e = MyTimeEvent(100)
47 self.timemanager.registerEvent(e)
48
49 for i in range(10):
50 time.sleep(0.1)
51 self.timemanager.update()
52
53 self.timemanager.unregisterEvent(e)
54
55 TEST_CLASSES = [TestTimer]
56
57 if __name__ == '__main__':
58 unittest.main()
59