implement lucca_layouttile_resize_block
[luccawm.git] / layout / test / test.py
blobbd56402806ca3d8b6755ef5d7d8ec2a8d77e7e08
1 #!/bin/python
3 import sys
4 import subprocess
6 proc = subprocess.Popen(sys.argv[1], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
8 LEFT, RIGHT, TOP, BOTTOM = 0, 1, 2, 3
10 def send(line):
11 print('> %s' % line)
12 proc.stdin.write('%s\n' % line)
14 def getline():
15 line = proc.stdout.readline().rstrip('\n')
16 print('< %s' % line)
17 return line.split(' ')
19 try:
20 line = getline()
21 assert(line[0] == 'layout')
22 layout = line[1]
24 send('getui %s width' % layout)
25 line = getline()
26 assert(line[0] == '0')
28 send('getui %s height' % layout)
29 line = getline()
30 assert(line[0] == '0')
32 send('getui %s border-size' % layout)
33 line = getline()
34 assert(line[0] == '0')
36 send('get_tiles')
37 line = getline()
38 assert(len(line) == 1)
40 send('geom_set_min 80 60')
41 send('geom_get_min')
42 line = getline()
43 assert(line[0] == '80')
44 assert(line[1] == '60')
46 #initialize layout
47 send('init 800 600 4')
48 line = getline()
49 assert(line[0] == 'new-tile')
50 tile1 = line[1]
52 send('get_layout %s' % tile1)
53 line = getline()
54 assert(line[0] == layout)
56 send('getui %s width' % layout)
57 line = getline()
58 assert(line[0] == '800')
60 send('getui %s height' % layout)
61 line = getline()
62 assert(line[0] == '600')
64 send('getui %s border-size' % layout)
65 line = getline()
66 assert(line[0] == '4')
68 send('getb %s valid' % tile1)
69 line = getline()
70 assert(line[0] == '1')
72 send('get_geometry_hints %s' % tile1)
73 send('geom_get_min')
74 line = getline()
75 assert(line[0] == '80')
76 assert(line[1] == '60')
78 send('getui %s x' % tile1)
79 line = getline()
80 assert(line[0] == '0')
82 send('getui %s y' % tile1)
83 line = getline()
84 assert(line[0] == '0')
86 send('getui %s width' % tile1)
87 line = getline()
88 assert(line[0] == '800')
90 send('getui %s height' % tile1)
91 line = getline()
92 assert(line[0] == '600')
94 send('get_tile_at_position 400 300')
95 line = getline()
96 assert(line[0] == tile1)
98 send('get_tile_at_position 801 601')
99 line = getline()
100 assert(line[0] == '(nil)')
102 send('get_tile_at_position -10 300')
103 line = getline()
104 assert(line[0] == '(nil)')
106 send('get_tiles_in_rectangle 400 300 10 10')
107 line = getline()
108 assert(line[0] == tile1)
109 assert(len(line) == 2)
111 send('get_tiles_in_rectangle 801 601 10 10')
112 line = getline()
113 assert(len(line) == 1)
115 send('get_tiles')
116 line = getline()
117 assert(line[0] == tile1)
118 assert(len(line) == 2)
120 #try to split the layout when tile1 has a minimum size of 800x600
121 send('geom_set_min 800 600')
122 send('set_geometry_hints %s' % tile1)
123 send('geom_unset_min')
125 send('split %s %s' % (tile1, LEFT))
126 line = getline()
127 assert(line[0] == '(nil)')
129 send('geom_set_min 80 60')
130 send('set_geometry_hints %s' % tile1)
132 #try to split the layout creating a new tile with a minimum size of 800x600
133 send('geom_set_min 800 600')
135 send('split %s %s' % (tile1, LEFT))
136 line = getline()
137 assert(line[0] == '(nil)')
139 send('geom_unset_min')
141 #horizontal split
142 send('geom_set_min 80 60')
143 send('split %s %s' % (tile1, LEFT))
144 line = getline()
145 assert(line[0] == 'configure' and line[1] == tile1)
146 line = getline()
147 assert(line[0] == 'new-tile')
148 tile2 = line[1]
149 line = getline()
150 assert(line[0] == tile2)
152 send('getui %s width' % tile2)
153 tile2_width = int(getline()[0])
154 send('getui %s x' % tile1)
155 tile1_x = int(getline()[0])
156 assert(tile1_x == tile2_width + 4)
158 send('getb %s valid' % tile2)
159 line = getline()
160 assert(line[0] == '1')
162 send('get_layout %s' % tile2)
163 line = getline()
164 assert(line[0] == layout)
166 #vertical split
167 send('geom_set_min 80 60')
168 send('split %s %s' % (tile1, BOTTOM))
169 line = getline()
170 assert(line[0] == 'configure' and line[1] == tile1)
171 line = getline()
172 assert(line[0] == 'new-tile')
173 tile3 = line[1]
174 line = getline()
175 assert(line[0] == tile3)
177 send('getui %s height' % tile1)
178 tile1_height = int(getline()[0])
179 send('getui %s y' % tile3)
180 tile3_y = int(getline()[0])
181 assert(tile3_y == tile1_height + 4)
183 #2-corner resize
184 send('resize %s 0 0 600 600' % tile2)
185 expected_configures = set([tile1, tile2, tile3])
186 configured_tiles = set()
187 for i in range(len(expected_configures)):
188 line = getline()
189 assert(line[0] == 'configure')
190 configured_tiles.add(line[1])
191 assert(configured_tiles == expected_configures)
193 send('getui %s width' % tile2)
194 line = getline()
195 assert(line[0] == '600')
197 send('getui %s x' % tile1)
198 line = getline()
199 assert(line[0] == '604')
201 send('getui %s x' % tile3)
202 line = getline()
203 assert(line[0] == '604')
205 send('getui %s width' % tile1)
206 line = getline()
207 assert(line[0] == '196')
209 send('getui %s width' % tile3)
210 line = getline()
211 assert(line[0] == '196')
213 #1-corner resize
214 send('resize_preview %s 400 0 400 400' % tile1)
215 line = getline()
216 assert(line == ['400', '0', '400', '400'])
218 send('resize %s 400 0 400 400' % tile1)
219 expected_configures = set([tile1, tile2, tile3])
220 configured_tiles = set()
221 for i in range(len(expected_configures)):
222 line = getline()
223 assert(line[0] == 'configure')
224 configured_tiles.add(line[1])
225 assert(configured_tiles == expected_configures)
227 send('getui %s width' % tile2)
228 line = getline()
229 assert(line[0] == '396')
231 send('getui %s x' % tile1)
232 line = getline()
233 assert(line[0] == '400')
235 send('getui %s x' % tile3)
236 line = getline()
237 assert(line[0] == '400')
239 send('getui %s width' % tile1)
240 line = getline()
241 assert(line[0] == '400')
243 send('getui %s width' % tile3)
244 line = getline()
245 assert(line[0] == '400')
247 send('getui %s height' % tile1)
248 line = getline()
249 assert(line[0] == '400')
251 send('getui %s y' % tile3)
252 line = getline()
253 assert(line[0] == '404')
255 send('getui %s height' % tile3)
256 line = getline()
257 assert(line[0] == '196')
259 #4-corner resize
260 send('resize %s 0 0 800 600' % tile1)
261 deleted_tiles = set()
262 expected_deletes = set([tile2, tile3])
263 for i in range(len(expected_deletes)):
264 line = getline()
265 assert(line[0] == 'delete')
266 deleted_tiles.add(line[1])
267 assert(deleted_tiles == expected_deletes)
268 line = getline()
269 assert(line[0] == 'configure')
270 assert(line[1] == tile1)
272 for i in expected_deletes:
273 send('getb %s valid' % i)
274 line = getline()
275 assert(line[0] == '0')
277 send('getui %s x' % tile1)
278 line = getline()
279 assert(line[0] == '0')
281 send('getui %s y' % tile1)
282 line = getline()
283 assert(line[0] == '0')
285 send('getui %s width' % tile1)
286 line = getline()
287 assert(line[0] == '800')
289 send('getui %s height' % tile1)
290 line = getline()
291 assert(line[0] == '600')
293 #0/1-corner resize
294 send('split %s %s' % (tile1, RIGHT))
295 line = getline()
296 assert(line[0] == 'configure' and line[1] == tile1)
297 line = getline()
298 assert(line[0] == 'new-tile')
299 tile2 = line[1]
300 line = getline()
301 assert(line[0] == tile2)
303 send('split %s %s' % (tile2, BOTTOM))
304 line = getline()
305 assert(line[0] == 'configure' and line[1] == tile2)
306 line = getline()
307 assert(line[0] == 'new-tile')
308 tile3 = line[1]
309 line = getline()
310 assert(line[0] == tile3)
312 send('split %s %s' % (tile3, BOTTOM))
313 line = getline()
314 assert(line[0] == 'configure' and line[1] == tile3)
315 line = getline()
316 assert(line[0] == 'new-tile')
317 tile4 = line[1]
318 line = getline()
319 assert(line[0] == tile4)
321 send('resize %s 200 200 600 300' % tile3)
322 expected_configures = set([tile1, tile2, tile3, tile4])
323 configured_tiles = set()
324 for i in range(len(expected_configures)):
325 line = getline()
326 assert(line[0] == 'configure')
327 configured_tiles.add(line[1])
328 assert(configured_tiles == expected_configures)
330 send('getui %s width' % tile1)
331 line = getline()
332 assert(line[0] == '196')
334 for t in (tile2, tile3, tile4):
335 send('getui %s x' % t)
336 line = getline()
337 assert(line[0] == '200')
339 send('getui %s width' % t)
340 line = getline()
341 assert(line[0] == '600')
343 #0/2-corner resize
344 send('resize %s 0 200 800 300' % tile3)
345 expected_configures = set([tile1, tile3, tile4])
346 configured_tiles = set()
347 for i in range(len(expected_configures)):
348 line = getline()
349 assert(line[0] == 'configure')
350 configured_tiles.add(line[1])
351 assert(configured_tiles == expected_configures)
353 send('getui %s height' % tile1)
354 line = getline()
355 assert(line[0] == '196')
357 send('getui %s x' % tile3)
358 line = getline()
359 assert(line[0] == '0')
361 send('getui %s width' % tile3)
362 line = getline()
363 assert(line[0] == '800')
365 send('getui %s x' % tile4)
366 line = getline()
367 assert(line[0] == '0')
369 send('getui %s width' % tile4)
370 line = getline()
371 assert(line[0] == '800')
373 #resize layout
374 send('layout_resize 640 480 2')
375 expected_configures = set([tile1, tile2, tile3, tile4])
376 configured_tiles = set()
377 for i in range(len(expected_configures)):
378 line = getline()
379 assert(line[0] == 'configure')
380 configured_tiles.add(line[1])
381 assert(configured_tiles == expected_configures)
383 send('getui %s x' % tile1)
384 line = getline()
385 assert(line[0] == '0')
387 send('getui %s width' % tile1)
388 line = getline()
389 tile1_width = int(line[0])
391 send('getui %s x' % tile2)
392 line = getline()
393 x = int(line[0])
394 assert(x == tile1_width+2)
396 prev_bottom = -2
397 for t in (tile2, tile3, tile4):
398 send('getui %s x' % t)
399 line = getline()
400 x = int(line[0])
402 send('getui %s width' % t)
403 line = getline()
404 width = int(line[0])
405 assert(x+width == 640)
407 send('getui %s y' % t)
408 line = getline()
409 y = int(line[0])
410 assert(y == prev_bottom+2)
412 send('getui %s height' % t)
413 line = getline()
414 height = int(line[0])
415 prev_bottom = y+height
417 assert(prev_bottom == 480)
419 #block resize (preview)
420 send('split %s %s' % (tile3, LEFT))
421 line = getline()
422 assert(line[0] == 'configure' and line[1] == tile3)
423 line = getline()
424 assert(line[0] == 'new-tile')
425 tile5 = line[1]
426 line = getline()
427 assert(line[0] == tile5)
429 send('getui %s x' % tile3)
430 line = getline()
431 x = int(line[0])
432 send('getui %s y' % tile3)
433 line = getline()
434 y = int(line[0])
435 send('getui %s width' % tile3)
436 line = getline()
437 width = int(line[0])
438 send('getui %s height' % tile3)
439 line = getline()
440 height = int(line[0])
442 send('getui %s x' % tile2)
443 line = getline()
444 tile2_x = int(line[0])
446 send('resize_block %s %s %s %s %s %s' % (tile3, LEFT, x, y, width, height))
447 line = getline()
448 newx = int(line[0])
449 newwidth = int(line[2])
450 assert(tile2_x == newx)
451 assert(newx+newwidth == 640)
453 send('geom_unset_min')
454 send('set_geometry_hints %s' % tile1)
455 send('geom_set_min 20 20')
456 send('get_geometry_hints %s' % tile1)
457 send('geom_get_min')
458 line = getline()
459 assert(line[0] == 'unset')
461 #deinitialize layout
462 send('deinit')
463 deleted_tiles = set()
464 expected_deletes = set([tile1, tile2, tile3, tile4, tile5])
465 for i in range(len(expected_deletes)):
466 line = getline()
467 assert(line[0] == 'delete')
468 deleted_tiles.add(line[1])
469 assert(deleted_tiles == expected_deletes)
471 for i in expected_deletes:
472 send('getb %s valid' % i)
473 line = getline()
474 assert(line[0] == '0')
476 send('get_tiles')
477 line = getline()
478 assert(len(line) == 1)
480 finally:
481 proc.stdin.close()
483 result, stdout, stderr = proc.wait(), proc.stdout.read(), proc.stderr.read()
485 print("%s\n%s\n%s" % (result, stdout, stderr));
487 assert(result == 0)
488 assert(stdout == '')
489 assert(stderr == '')
491 f = open(sys.argv[2], 'w')
492 f.close()