From e21ff29b499e826db720a85ad6ad4d1fa04ebc1c Mon Sep 17 00:00:00 2001 From: Manish Singh Date: Sun, 10 Jul 2005 22:17:15 +0000 Subject: gobject/pygobject-private.h gobject/gobjectmodule.c gobject/Makefile.am * gobject/pygobject-private.h * gobject/gobjectmodule.c * gobject/Makefile.am * gobject/pygsource.c: GSource wrapper, allows for pure python GSource implementations, as well as objectifying Idle and Timeout sources. * tests/Makefile.am * tests/test_source.py: Add test for the above. * gobject/gobjectmodule.c: timeout_add should take an explicit unsigned value. Also wrap g_get_current_time and g_main_depth. * gobject/pygiochannel.c (py_io_channel_write_chars): fix thread unblock/block logic. --- tests/test_source.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/test_source.py (limited to 'tests/test_source.py') diff --git a/tests/test_source.py b/tests/test_source.py new file mode 100644 index 0000000..5e0f01b --- /dev/null +++ b/tests/test_source.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +import exceptions +import os +import sys +import select +import unittest + +from common import gobject + +class Idle(gobject.Idle): + def __init__(self, loop): + gobject.Idle.__init__(self) + self.count = 0 + self.set_callback(self.callback, loop) + + def callback(self, loop): + self.count += 1 + return True + +class MySource(gobject.Source): + def __init__(self): + gobject.Source.__init__(self) + + def prepare(self): + return True, 0 + + def check(self): + return True + + def dispatch(self, callback, args): + return callback(*args) + +class TestSource(unittest.TestCase): + def timeout_callback(self, loop): + loop.quit() + + def my_callback(self, loop): + self.pos += 1 + return True + + def setup_timeout(self, loop): + timeout = gobject.Timeout(500) + timeout.set_callback(self.timeout_callback, loop) + timeout.attach() + + def testSources(self): + loop = gobject.MainLoop() + + self.setup_timeout(loop) + + idle = Idle(loop) + idle.attach() + + self.pos = 0 + + m = MySource() + m.set_callback(self.my_callback, loop) + m.attach() + + loop.run() + + assert self.pos >= 0 and idle.count >= 0 + +if __name__ == '__main__': + unittest.main() -- cgit