summaryrefslogtreecommitdiff
path: root/tests/test_gdk.py
blob: 77fe5cc1f93ea4982d5a39034d84587712e3a2c2 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import unittest
import gc

from common import gtk

class CallOnDel:
    def __init__(self, callback):
        self.callback = callback
    def __del__(self):
        self.callback()

class GdkTest(unittest.TestCase):
    def testBitmapCreateFromData(self):
        gtk.gdk.bitmap_create_from_data(None, '\x00', 1, 1)

    def testPixmapCreateFromData(self):
        black = gtk.gdk.color_parse('black')
        gtk.gdk.pixmap_create_from_data(None, '\x00', 1, 1, 1,
                                        black, black)

    def _testWindow(self):
        common = {'finalized': False}
        def on_finalize():
            common['finalized'] = True
        w = gtk.gdk.Window(None, 200, 200, gtk.gdk.WINDOW_TEMP, 0, 0)
        w.set_data('foo', CallOnDel(on_finalize))
        w.destroy()
        while gtk.events_pending():
            gtk.main_iteration(block=False)
        del w

        # Note that this depends on the mainloop processing an X event so
        # if might fail if the timing is off
        while gc.collect():
            pass
        assert common['finalized']


    def testDrawIndexedImage(self):
        w = gtk.Window()
        w.realize()
        w.window.draw_indexed_image(gtk.gdk.GC(w.window),
                                    0, 0,
                                    1, 2,
                                    gtk.gdk.RGB_DITHER_NONE,
                                    '\x00\x01',
                                    1,
                                    [0xdeadbe, 0xbebabe])

    def testDisplay(self):
        while gc.collect():
            pass

        display = gtk.gdk.Display(None)
        del display

        cnt = 0
        while True:
            x = gc.collect()
            cnt += x
            if x:
                break
        self.assertEquals(cnt, 1)
        
        display = gtk.gdk.Display(None)
        display.close()
        del display

        cnt = 0
        while True:
            x = gc.collect()
            cnt += x
            if x:
                break
        self.assertEquals(cnt, 1)