summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2015-03-12 22:01:39 +0100
committerDave Andreoli <dave@gurumeditation.it>2015-03-12 22:02:07 +0100
commit807f0417db9c639ee6e92b59bf9a20f4973f4cbc (patch)
tree7f329dcf3c0d5d753de5667bc14a7a3e6f19c67f
parentccc88f66507442f21b0e7f180c638bf4b80ffeaa (diff)
Some tests for SmartObject callbacks
-rw-r--r--tests/evas/test_06_object_smart.py103
1 files changed, 99 insertions, 4 deletions
diff --git a/tests/evas/test_06_object_smart.py b/tests/evas/test_06_object_smart.py
index dd8419b..b672f87 100644
--- a/tests/evas/test_06_object_smart.py
+++ b/tests/evas/test_06_object_smart.py
@@ -12,6 +12,11 @@ class MySmart(evas.Smart):
12 obj.r1.geometry = (0, 0, w2, h2) 12 obj.r1.geometry = (0, 0, w2, h2)
13 obj.r2.geometry = (w2, h2, w2, h2) 13 obj.r2.geometry = (w2, h2, w2, h2)
14 14
15 @staticmethod
16 def move(obj, x, y):
17 obj.callback_call("event1")
18
19
15class MyObject(evas.SmartObject): 20class MyObject(evas.SmartObject):
16 def __init__(self, canvas, smart, *args, **kargs): 21 def __init__(self, canvas, smart, *args, **kargs):
17 evas.SmartObject.__init__(self, canvas, smart, *args, **kargs) 22 evas.SmartObject.__init__(self, canvas, smart, *args, **kargs)
@@ -26,6 +31,7 @@ class MyObject(evas.SmartObject):
26 color="#00ff00") 31 color="#00ff00")
27 self.member_add(self.r2) 32 self.member_add(self.r2)
28 33
34
29class SmartObjectTest(unittest.TestCase): 35class SmartObjectTest(unittest.TestCase):
30 def setUp(self): 36 def setUp(self):
31 self.canvas = evas.Canvas(method="buffer", 37 self.canvas = evas.Canvas(method="buffer",
@@ -38,15 +44,104 @@ class SmartObjectTest(unittest.TestCase):
38 self.assertEqual(self.obj.members, (self.obj.r1, self.obj.r2)) 44 self.assertEqual(self.obj.members, (self.obj.r1, self.obj.r2))
39 45
40 def testResize(self): 46 def testResize(self):
41 print(self.obj.geometry)
42 print(self.obj.r1.geometry)
43 self.obj.resize(100, 100) 47 self.obj.resize(100, 100)
44 print(self.obj.geometry)
45 print(self.obj.r1.geometry)
46 self.assertEqual(self.obj.r1.geometry, (0, 0, 50, 50)) 48 self.assertEqual(self.obj.r1.geometry, (0, 0, 50, 50))
47 self.assertEqual(self.obj.r2.geometry, (50, 50, 50, 50)) 49 self.assertEqual(self.obj.r2.geometry, (50, 50, 50, 50))
48 50
51 def testCallbackSimple(self):
52 self.expected_cbs = 2
53 def _event1_cb(obj):
54 self.expected_cbs -= 1
55 self.obj.callback_add("event1", _event1_cb)
56 self.obj.move(1, 1) # should fire "event1"
57 self.obj.move(2, 2) # should fire "event1"
58 self.obj.callback_del("event1", _event1_cb)
59 self.obj.move(0, 0) # should NOT fire "event1"
60 self.assertEqual(self.expected_cbs, 0)
61
62 def testCallbackArgs(self):
63 def _event1_cb(obj, arg1, arg2, arg3, mykarg2, mykarg1):
64 self.assertEqual(arg1, 11)
65 self.assertEqual(arg2, 22)
66 self.assertEqual(arg3, "arg3")
67 self.assertEqual(mykarg2, "k2")
68 self.assertEqual(mykarg1, "k1")
69 self.obj.callback_add("event1", _event1_cb, 11, 22, "arg3", mykarg1="k1", mykarg2="k2")
70 self.obj.move(1, 1) # should fire "event1" with the correct args
71 self.obj.callback_del("event1", _event1_cb)
72 self.obj.move(0, 0)
73
74 def testCallbackMulti(self):
75 def _event1_cb1(obj):
76 self.expected_cbs += 1
77 def _event1_cb2(obj):
78 self.expected_cbs += 10
79
80 self.expected_cbs = 0
81 self.obj.callback_add("event1", _event1_cb1)
82 self.obj.move(1, 1) # should fire "event1" in cb1
83 self.assertEqual(self.expected_cbs, 1)
84
85 self.expected_cbs = 0
86 self.obj.callback_add("event1", _event1_cb2)
87 self.obj.move(2, 2) # should fire "event1" in both cbs
88 self.assertEqual(self.expected_cbs, 11)
89
90 self.expected_cbs = 0
91 self.obj.callback_del("event1", _event1_cb1)
92 self.obj.move(3, 3) # should fire "event1" only in cb2
93 self.assertEqual(self.expected_cbs, 10)
94
95 self.expected_cbs = 0
96 self.obj.callback_del("event1", _event1_cb2)
97 self.obj.move(0, 0) # should NOT fire "event1"
98 self.assertEqual(self.expected_cbs, 0)
99
100 def testCallbackLots(self):
101 def _event1_cb(obj):
102 self.expected_cbs -= 1
103
104 self.expected_cbs = 20000
105 self.obj.callback_add("event1", _event1_cb)
106 self.obj.callback_add("event1", _event1_cb)
107 for i in range(10000):
108 self.obj.move(i+1, i-1) # should fire "event1" 10000 times * 2 cbs
109 self.assertEqual(self.expected_cbs, 0)
110 self.obj.callback_del("event1", _event1_cb)
111 self.obj.callback_del("event1", _event1_cb)
112 self.obj.move(0, 0) # should NOT fire "event1"
113 self.assertEqual(self.expected_cbs, 0)
114
115 def testCallbackLots2(self):
116 def _event1_cb(obj):
117 self.expected_cbs -= 1
118
119 self.expected_cbs = 10000
120 for i in range(10000):
121 self.obj.callback_add("event1", _event1_cb)
122 self.obj.move(1, 1)
123 self.assertEqual(self.expected_cbs, 0)
124 for i in range(10000):
125 self.obj.callback_del("event1", _event1_cb)
126 self.assertRaises(ValueError, self.obj.callback_del, "event1", _event1_cb)
127 self.obj.move(0, 0) # should NOT fire "event1"
128 self.assertEqual(self.expected_cbs, 0)
129
130 def testCallbackWrongDel1(self):
131 def _event1_cb(obj):
132 pass
133 self.assertRaises(ValueError, self.obj.callback_del, "event1", _event1_cb)
49 134
135 def testCallbackWrongDel2(self):
136 def _event1_cb(obj):
137 pass
138 self.obj.callback_add("event1", _event1_cb)
139 self.obj.callback_add("event1", _event1_cb)
140 self.obj.callback_del("event1", _event1_cb)
141 self.obj.callback_del("event1", _event1_cb)
142 self.assertRaises(ValueError, self.obj.callback_del, "event1", _event1_cb)
143
144
50if __name__ == '__main__': 145if __name__ == '__main__':
51 unittest.main(verbosity=2) 146 unittest.main(verbosity=2)
52 evas.shutdown() 147 evas.shutdown()