summaryrefslogtreecommitdiff
path: root/tests/evas/test_02_canvas.py
blob: 3262907fba006b3168a0f2ba5ba762c4c8fcb494 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python

from efl import evas
import unittest
import logging


def _new_canvas():
    c = evas.Canvas(method="buffer", size=(400, 500), viewport=(0, 0, 400, 500))
    c.engine_info_set(c.engine_info_get())
    return c


class TestCanvasConstructor(unittest.TestCase):
    def testNoConstructorArgs(self):
        c = evas.Canvas(method="buffer")
        self.assertEqual(c.output_method_get(), 2)
        self.assertEqual(c.size_get(), (0, 0))
        self.assertEqual(c.viewport_get(), (0, 0, 1, 1))
        c.delete()

    def testConstructorArgs(self):
        m = "buffer"
        s = (400, 500)
        v = (0, 0, 30, 40)
        c = evas.Canvas(method=m, size=s, viewport=v)
        c.engine_info_set(c.engine_info_get())
        self.assertEqual(c.output_method_get(), evas.render_method_lookup(m))
        self.assertEqual(c.size_get(), s)
        self.assertEqual(c.viewport_get(), v)
        self.assertEqual(isinstance(str(c), str), True)
        self.assertEqual(isinstance(repr(c), str), True)
        c.delete()


class TestCanvasMethods(unittest.TestCase):
    def setUp(self):
        self.canvas = _new_canvas()

    def tearDown(self):
        self.canvas.delete()

    def testSizeGet(self):
        self.assertEqual(self.canvas.size_get(), (400, 500))

    def testSizeSet(self):
        self.canvas.size_set(200, 300)
        self.assertEqual(self.canvas.size_get(), (200, 300))


class TestCanvasProperties(unittest.TestCase):
    def setUp(self):
        self.canvas = _new_canvas()

    def tearDown(self):
        self.canvas.delete()

    def testSizeGet(self):
        self.assertEqual(self.canvas.size, (400, 500))

    def testSizeSet(self):
        self.canvas.size = (200, 300)
        self.assertEqual(self.canvas.size_get(), (200, 300))

    def testRectGet(self):
        self.assertEqual(self.canvas.rect, (0, 0, 400, 500))

    def testRectSetTuple(self):
        self.canvas.rect = (0, 0, 200, 300)
        self.assertEqual(self.canvas.size_get(), (200, 300))

    def testRectSetRect(self):
        self.canvas.rect = evas.Rect(size=(200, 300))
        self.assertEqual(self.canvas.size_get(), (200, 300))


class TestCanvasDeletion(unittest.TestCase):
    def testEmptyCanvasDelete(self):
        canvas = _new_canvas()
        canvas.delete()

    def testCanvasDelete(self):
        canvas = _new_canvas()
        r1 = evas.Rectangle(canvas)
        r2 = evas.Rectangle(canvas)
        r1.delete()
        r2.delete()
        canvas.delete()

    def testFullCanvasDelete(self):
        canvas = _new_canvas()
        r = evas.Rectangle(canvas)
        i = evas.Image(canvas)
        canvas.delete()


class TestCanvasFactory(unittest.TestCase):
    def setUp(self):
        self.canvas = _new_canvas()

    def tearDown(self):
        self.canvas.delete()

    def testRectangle(self):
        o = self.canvas.Rectangle()
        self.assertEqual(type(o), evas.Rectangle)
        o.delete()

    def testImage(self):
        o = self.canvas.Image()
        self.assertEqual(type(o), evas.Image)
        o.delete()

    def testBox(self):
        o = self.canvas.Box()
        self.assertEqual(type(o), evas.Box)
        o.delete()

    def testPolygon(self):
        o = self.canvas.Polygon()
        self.assertEqual(type(o), evas.Polygon)
        o.delete()

    def testText(self):
        o = self.canvas.Text()
        self.assertEqual(type(o), evas.Text)
        o.delete()

    def testTextblock(self):
        o = self.canvas.Textblock()
        self.assertEqual(type(o), evas.Textblock)
        o.delete()


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)