summaryrefslogtreecommitdiff
path: root/tests/ecore/test_03_poller.py
blob: c85eada12c585f25fc2f786d73445e9c6ffb0143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python

import unittest
import logging

from efl import ecore


class TestPoller(unittest.TestCase):

    def cb_renew(self):
        self.counters[0] += 1
        return ecore.ECORE_CALLBACK_RENEW

    def cb_cancel(self, one, two, three, test):
        self.assertEqual(one, "uno")
        self.assertEqual(two, "due")
        self.assertEqual(three, "tre")
        self.assertEqual(test, self)
        self.counters[1] += 1
        return ecore.ECORE_CALLBACK_CANCEL

    def testInit(self):
        self.counters = [0, 0]

        p1 = ecore.Poller(4, self.cb_renew)
        p2 = ecore.Poller(2, self.cb_cancel, ecore.ECORE_POLLER_CORE,
                          "uno", "due", three="tre", test=self)
        p3 = ecore.Poller(16, lambda: ecore.main_loop_quit())

        self.assertIsInstance(p1, ecore.Poller)
        self.assertIsInstance(p2, ecore.Poller)
        self.assertIsInstance(p3, ecore.Poller)

        ecore.main_loop_begin()

        # all the callback has been called?
        self.assertEqual(self.counters, [4, 1])

        # not yet deleted since returned true
        self.assertEqual(p1.is_deleted(), False)
        p1.delete()
        self.assertEqual(p1.is_deleted(), True)
        del p1

        # already deleted since returned false
        self.assertEqual(p2.is_deleted(), True)
        self.assertEqual(p3.is_deleted(), True)
        del p2 
        del p3


if __name__ == '__main__':
    formatter = logging.Formatter("[%(levelname)s] %(name)s (%(filename)s: %(lineno)d) --- %(message)s")
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    efllog = logging.getLogger("efl")
    efllog.addHandler(handler)
    efllog.setLevel(logging.DEBUG)
    unittest.main(verbosity=2)