ya2 · news · projects · code · about

fullscreen test
[pmachines.git] / lib / tools / functional_test.py
1 '''Create ref:
2 * M-x fla-set-fun-test
3 * rm options.ini
4 * python main.py --functional-test --functional-ref & python -m lib.tools.functional_test.py 1
5 * python main.py --functional-test --functional-ref & python -m lib.tools.functional_test.py 2
6 * M-x fla-unset-fun-test'''
7 from panda3d.core import load_prc_file_data
8 load_prc_file_data('', 'window-type none')
9 import datetime
10 from time import sleep
11 from os import getcwd, system
12 from multiprocessing.connection import Client
13 from logging import debug, info
14 from pathlib import Path
15 from shutil import rmtree
16 from os import makedirs
17 from os.path import join, exists
18 from glob import glob
19 from sys import exit, argv
20 from panda3d.core import Filename
21 from direct.showbase.ShowBase import ShowBase
22 from direct.gui.OnscreenText import OnscreenText
23 from lib.gameobject import GameObject
24 from lib.build.build import _branch
25
26
27 class FunctionalTest(GameObject):
28
29 screenshot_time = 1.2
30 evt_time = 1.0
31 drag_time = 1.0
32 start_time = 2
33
34 def __init__(self, idx, offset):
35 super().__init__()
36 info('test idx: %s' % idx)
37 self._offset = offset
38 sleep(5)
39 address = ('localhost', 6000)
40 self._conn = Client(address)
41 self._curr_time = 0
42 self._tasks = []
43 self._prev_time = 0
44 taskMgr.add(self.on_frame_unpausable, 'on-frame-unpausable')
45 self._conn.send(['set_idx', idx])
46 self._do_screenshots(idx)
47
48 def _do_screenshot(self, name):
49 time = datetime.datetime.now().strftime('%y%m%d%H%M%S')
50 name = name + '.png'
51 self._conn.send(['screenshot', name])
52 info('screenshot %s' % name)
53
54 def _screenshot(self, time, name):
55 self._tasks += [(
56 self._curr_time + time,
57 lambda: self._do_screenshot(name),
58 'screenshot: %s' % name)]
59 self._curr_time += time
60
61 def __mouse_click(self, pos, btn):
62 offset_x = int((1920 - 1360) / 2) #+ 1 # xfce decorations
63 offset_y = int((1080 - 768) / 2) #+ 24 + self._offset # xfce decorations
64 btn = 3 if btn == 'right' else 1
65 system('xdotool mousemove %s %s' % (offset_x + pos[0], offset_y + pos[1]))
66 def click(task):
67 system('xdotool click %s' % btn)
68 taskMgr.do_method_later(.28, click, 'click')
69
70 def __mouse_drag(self, start, end, btn):
71 offset_x = int((1920 - 1360) / 2) #+ 1 # xfce decorations
72 offset_y = int((1080 - 768) / 2) #+ 24 + self._offset # xfce decorations
73 btn = 3 if btn == 'right' else 1
74 system('xdotool mousemove %s %s' % (offset_x + start[0], offset_y + start[1]))
75 def mousedown(task):
76 system('xdotool mousedown %s' % btn)
77 def mousemove(task):
78 system('xdotool mousemove %s %s' % (offset_x + end[0], offset_y + end[1]))
79 def mouseup(task):
80 system('xdotool mouseup %s' % btn)
81 taskMgr.do_method_later(.28, mouseup, 'mouseup')
82 taskMgr.do_method_later(.28, mousemove, 'mousemove')
83 taskMgr.do_method_later(.28, mousedown, 'mousedown')
84
85 def _event(self, time, evt, mouse_args=None):
86 if evt == 'mouseclick':
87 cback = lambda: self.__mouse_click(*mouse_args)
88 elif evt == 'mousedrag':
89 cback = lambda: self.__mouse_drag(*mouse_args)
90 self._tasks += [(
91 self._curr_time + time,
92 cback,
93 'event: %s' % evt)]
94 self._curr_time += time
95
96 def _enforce_res(self, time, res):
97 def cback():
98 self._conn.send(['enforce_res', res])
99 info('enforce_res %s' % res)
100 self._tasks += [(
101 self._curr_time + time,
102 cback,
103 'enforce res: %s' % res)]
104 self._curr_time += time
105
106 def _verify(self):
107 def __verify():
108 self._conn.send(['verify'])
109 info('verify')
110 self._tasks += [(
111 self._curr_time + 3,
112 lambda: __verify(),
113 'verify')]
114 self._curr_time += 3
115
116 def _exit(self):
117 def do_exit():
118 self._conn.close()
119 exit()
120 self._tasks += [(
121 self._curr_time + 3,
122 lambda: do_exit(),
123 'exit')]
124
125 def on_frame_unpausable(self, task):
126 for tsk in self._tasks:
127 #if self._prev_time <= tsk[0] < self.eng.event.unpaused_time:
128 if self._prev_time <= tsk[0] < globalClock.getFrameTime():
129 debug('%s %s' % (tsk[0], tsk[2]))
130 tsk[1]()
131 self._prev_time = globalClock.getFrameTime() # self.eng.event.unpaused_time
132 return task.cont
133
134 def _do_screenshots_1(self):
135 info('_do_screenshots_1')
136 self._screenshot(FunctionalTest.start_time, 'main_menu')
137 self._do_screenshots_credits()
138 self._do_screenshots_options()
139 self._do_screenshots_exit()
140
141 def _do_screenshots_credits(self):
142 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 450), 'left'])
143 self._screenshot(FunctionalTest.screenshot_time, 'credits_menu')
144 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 680), 'left'])
145 self._screenshot(FunctionalTest.screenshot_time, 'main_menu_back_from_credits')
146
147 def _do_screenshots_options(self):
148 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 300), 'left'])
149 self._screenshot(FunctionalTest.screenshot_time, 'options_menu')
150 # languages
151 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 60), 'left'])
152 self._screenshot(FunctionalTest.screenshot_time, 'open_languages')
153 self._event(FunctionalTest.evt_time, 'mouseclick', [(980, 120), 'left'])
154 self._screenshot(FunctionalTest.screenshot_time, 'options_menu_italian')
155 # volume
156 self._event(FunctionalTest.evt_time, 'mouseclick', [(740, 163), 'left'])
157 self._screenshot(FunctionalTest.screenshot_time, 'options_menu_drag_1')
158 # antialiasing
159 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 440), 'left'])
160 self._screenshot(FunctionalTest.screenshot_time, 'antialiasing_no')
161 # shadows
162 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 540), 'left'])
163 self._screenshot(FunctionalTest.screenshot_time, 'shadows_no')
164 # test aa and shadows
165 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 680), 'left']) # back
166 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 140), 'left']) # play
167 self._event(FunctionalTest.evt_time, 'mouseclick', [(230, 160), 'left']) # domino
168 self._event(FunctionalTest.evt_time, 'mouseclick', [(900, 490), 'left']) # close instructions
169 self._screenshot(FunctionalTest.screenshot_time, 'aa_no_shadows_no')
170 self._event(FunctionalTest.evt_time, 'mouseclick', [(25, 740), 'left']) # home
171
172 def _do_screenshots_restore_options(self):
173 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 300), 'left'])
174 self._screenshot(FunctionalTest.screenshot_time, 'options_menu_restored')
175 # languages
176 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 60), 'left'])
177 self._screenshot(FunctionalTest.screenshot_time, 'open_languages_restored')
178 self._event(FunctionalTest.evt_time, 'mouseclick', [(980, 20), 'left'])
179 self._screenshot(FunctionalTest.screenshot_time, 'options_menu_english')
180 # volume
181 self._event(FunctionalTest.evt_time, 'mouseclick', [(719, 163), 'left'])
182 self._screenshot(FunctionalTest.screenshot_time, 'options_menu_drag_2')
183 # fullscreen
184 # the first one is because of the windowed mode in test
185 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 250), 'left'])
186 self._screenshot(FunctionalTest.screenshot_time, 'fullscreen')
187 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 250), 'left'])
188 self._screenshot(FunctionalTest.screenshot_time, 'fullscreen')
189 self._event(8 + FunctionalTest.evt_time, 'mouseclick', [(440, 120), 'left'])
190 self._screenshot(8 + FunctionalTest.screenshot_time, 'back_from_fullscreen')
191 # resolution
192 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 340), 'left'])
193 self._screenshot(FunctionalTest.screenshot_time, 'resolutions')
194 self._event(FunctionalTest.evt_time, 'mouseclick', [(1000, 400), 'left'])
195 self._screenshot(FunctionalTest.screenshot_time, '1440x900')
196 self._event(FunctionalTest.evt_time, 'mouseclick', [(740, 400), 'left'])
197 self._screenshot(FunctionalTest.screenshot_time, 'resolutions_2')
198 self._event(FunctionalTest.evt_time, 'mouseclick', [(1110, 80), 'left'])
199 self._screenshot(FunctionalTest.screenshot_time, '1360x768')
200 # antialiasing
201 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 440), 'left'])
202 self._screenshot(FunctionalTest.screenshot_time, 'antialiasing_yes')
203 # shadows
204 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 540), 'left'])
205 self._screenshot(FunctionalTest.screenshot_time, 'shadows_yes')
206 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 680), 'left']) # back
207
208 def _do_screenshots_play(self):
209 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 140), 'left']) # play
210 self._screenshot(FunctionalTest.screenshot_time, 'play_menu')
211 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 680), 'left']) # back
212 self._screenshot(FunctionalTest.screenshot_time, 'back_from_play')
213 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 140), 'left']) # play
214 self._event(FunctionalTest.evt_time, 'mouseclick', [(230, 160), 'left']) # domino scene
215 self._screenshot(FunctionalTest.screenshot_time, 'scene_domino_instructions')
216 self._event(FunctionalTest.evt_time, 'mouseclick', [(850, 490), 'left']) # close instructions
217 self._screenshot(FunctionalTest.screenshot_time, 'scene_domino')
218 self._event(FunctionalTest.evt_time, 'mouseclick', [(25, 740), 'left']) # home
219 self._screenshot(FunctionalTest.screenshot_time, 'home_back_from_scene')
220 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 140), 'left']) # play
221 self._event(FunctionalTest.evt_time, 'mouseclick', [(230, 160), 'left']) # domino
222 self._event(FunctionalTest.evt_time, 'mouseclick', [(850, 490), 'left']) # close instructions
223 self._event(FunctionalTest.evt_time, 'mouseclick', [(70, 740), 'left']) # info
224 self._screenshot(FunctionalTest.screenshot_time, 'info')
225 self._event(FunctionalTest.evt_time, 'mouseclick', [(850, 490), 'left']) # close instructions
226 self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (430, 280), 'left']) # drag a piece
227 self._screenshot(FunctionalTest.screenshot_time, 'domino_dragged')
228 self._event(FunctionalTest.evt_time, 'mouseclick', [(1220, 740), 'left']) # rewind
229 self._screenshot(FunctionalTest.screenshot_time, 'rewind')
230 self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (550, 380), 'left']) # drag a piece
231 # self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (715, 380), 'left']) # drag a piece
232 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
233 self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_domino')
234 self._event(FunctionalTest.evt_time, 'mouseclick', [(630, 450), 'left']) # home
235 self._screenshot(FunctionalTest.screenshot_time, 'home_back_from_fail')
236 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 140), 'left']) # play
237 self._event(FunctionalTest.evt_time, 'mouseclick', [(230, 160), 'left']) # domino
238 self._event(FunctionalTest.evt_time, 'mouseclick', [(850, 490), 'left']) # close instructions
239 self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (550, 380), 'left']) # drag a piece
240 self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (715, 380), 'left']) # drag a piece
241 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
242 self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_domino_2')
243 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 450), 'left']) # replay
244 self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (570, 380), 'left']) # drag a piece
245 self._event(FunctionalTest.drag_time, 'mousedrag', [(570, 355), (605, 355), 'right']) # rotate the piece
246 self._event(FunctionalTest.drag_time, 'mousedrag', [(35, 60), (715, 380), 'left']) # drag a piece
247 self._enforce_res(FunctionalTest.evt_time, 'win')
248 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
249 self._screenshot(16 + FunctionalTest.screenshot_time, 'win_domino')
250 self._enforce_res(FunctionalTest.evt_time, '')
251 self._event(FunctionalTest.evt_time, 'mouseclick', [(735, 450), 'left']) # next
252 self._screenshot(FunctionalTest.screenshot_time, 'scene_box')
253 # scene 2
254 self._event(FunctionalTest.evt_time, 'mouseclick', [(880, 490), 'left']) # close instructions
255 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (710, 620), 'left']) # drag a box
256 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (710, 540), 'left']) # drag a box
257 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
258 self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_box')
259 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 450), 'left']) # replay
260 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (710, 620), 'left']) # drag a box
261 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (710, 540), 'left']) # drag a box
262 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (705, 460), 'left']) # drag a box
263 self._enforce_res(FunctionalTest.evt_time, 'win')
264 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
265 self._screenshot(16 + FunctionalTest.screenshot_time, 'win_box')
266 self._enforce_res(FunctionalTest.evt_time, '')
267 self._event(FunctionalTest.evt_time, 'mouseclick', [(735, 450), 'left']) # next
268 self._screenshot(FunctionalTest.screenshot_time, 'scene_box_domino')
269 # scene 3
270 self._event(FunctionalTest.evt_time, 'mouseclick', [(930, 485), 'left']) # close instructions
271 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (910, 440), 'left']) # drag a box
272 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (910, 360), 'left']) # drag a box
273 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
274 self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_box_domino')
275 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 450), 'left']) # replay
276 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (910, 440), 'left']) # drag a box
277 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (835, 250), 'left']) # drag a box
278 self._enforce_res(FunctionalTest.evt_time, 'win')
279 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
280 self._screenshot(16 + FunctionalTest.screenshot_time, 'win_box_domino')
281 self._enforce_res(FunctionalTest.evt_time, '')
282 self._event(FunctionalTest.evt_time, 'mouseclick', [(735, 450), 'left']) # next
283 self._screenshot(FunctionalTest.screenshot_time, 'scene_basketball')
284 # scene 4
285 self._event(FunctionalTest.evt_time, 'mouseclick', [(870, 490), 'left']) # close instructions
286 self._event(FunctionalTest.drag_time, 'mousedrag', [(55, 50), (650, 310), 'left']) # drag a ball
287 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
288 self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_basketball')
289 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 450), 'left']) # replay
290 self._event(FunctionalTest.drag_time, 'mousedrag', [(55, 50), (380, 50), 'left']) # drag a ball
291 self._enforce_res(FunctionalTest.evt_time, 'win')
292 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
293 self._screenshot(16 + FunctionalTest.screenshot_time, 'win_basketball')
294 self._enforce_res(FunctionalTest.evt_time, '')
295 self._event(FunctionalTest.evt_time, 'mouseclick', [(735, 450), 'left']) # next
296 self._screenshot(FunctionalTest.screenshot_time, 'scene_domino_box_basketball')
297 # scene 5
298 self._event(FunctionalTest.evt_time, 'mouseclick', [(865, 490), 'left']) # close instructions
299 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (580, 440), 'left']) # drag a box
300 self._event(FunctionalTest.drag_time, 'mousedrag', [(30, 60), (590, 370), 'left']) # drag a piece
301 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
302 self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_domino_box_basketball')
303 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 450), 'left']) # replay
304 self._event(FunctionalTest.drag_time, 'mousedrag', [(65, 60), (580, 440), 'left']) # drag a box
305 self._event(FunctionalTest.drag_time, 'mousedrag', [(30, 60), (660, 440), 'left']) # drag a piece
306 self._event(FunctionalTest.drag_time, 'mousedrag', [(660, 425), (625, 425), 'right']) # rotate a piece
307 self._event(FunctionalTest.drag_time, 'mousedrag', [(660, 435), (650, 445), 'left']) # drag a piece
308 self._enforce_res(FunctionalTest.evt_time, 'win')
309 self._event(FunctionalTest.evt_time, 'mouseclick', [(1340, 740), 'left']) # play
310 self._screenshot(16 + FunctionalTest.screenshot_time, 'win_domino_box_basketball')
311 self._enforce_res(FunctionalTest.evt_time, '')
312 # self._event(FunctionalTest.evt_time, 'mouseclick', [(735, 450), 'left']) # next
313 # self._screenshot(FunctionalTest.screenshot_time, 'scene_teeter_tooter')
314 # # scene 6
315 # self._event(FunctionalTest.evt_time, 'mouseclick', [(820, 455), 'left']) # close instructions
316 # self._event(FunctionalTest.drag_time, 'mousedrag', [(60, 60), (490, 300), 'left']) # drag a box
317 # self._event(FunctionalTest.evt_time, 'mouseclick', [(1260, 695), 'left']) # play
318 # self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_teeter_tooter')
319 # self._event(FunctionalTest.evt_time, 'mouseclick', [(640, 420), 'left']) # replay
320 # self._event(FunctionalTest.drag_time, 'mousedrag', [(60, 60), (490, 150), 'left']) # drag a box
321 # self._event(FunctionalTest.drag_time, 'mousedrag', [(515, 115), (515, 122), 'right']) # rotate a box
322 # self._event(FunctionalTest.evt_time, 'mouseclick', [(1260, 695), 'left']) # play
323 # self._screenshot(16 + FunctionalTest.screenshot_time, 'win_teeter_tooter')
324 # self._event(FunctionalTest.evt_time, 'mouseclick', [(690, 420), 'left']) # next
325 # self._screenshot(FunctionalTest.screenshot_time, 'scene_teeter_domino_box_basketball')
326 # # scene 7
327 # self._event(FunctionalTest.evt_time, 'mouseclick', [(880, 455), 'left']) # close instructions
328 # self._event(FunctionalTest.drag_time, 'mousedrag', [(60, 60), (155, 180), 'left']) # drag a box
329 # self._event(FunctionalTest.evt_time, 'mouseclick', [(1260, 695), 'left']) # play
330 # self._screenshot(16 + FunctionalTest.screenshot_time, 'fail_teeter_domino_box_basketball')
331 # self._event(FunctionalTest.evt_time, 'mouseclick', [(640, 420), 'left']) # replay
332 # self._event(FunctionalTest.drag_time, 'mousedrag', [(60, 60), (170, 80), 'left']) # drag a box
333 # self._event(FunctionalTest.drag_time, 'mousedrag', [(195, 50), (195, 80), 'right']) # rotate a box
334 # self._event(FunctionalTest.evt_time, 'mouseclick', [(1260, 695), 'left']) # play
335 # self._screenshot(16 + FunctionalTest.screenshot_time, 'win_teeter_domino_box_basketball')
336 self._event(FunctionalTest.evt_time, 'mouseclick', [(630, 450), 'left']) # home
337 self._screenshot(FunctionalTest.screenshot_time, 'home_from_play')
338
339 def _exit(self):
340 self._tasks += [(
341 self._curr_time + 3,
342 lambda: exit(),
343 'exit')]
344
345 def _do_screenshots_exit(self):
346 self._verify()
347 self._event(FunctionalTest.evt_time, 'mouseclick', [(680, 600), 'left'])
348 self._exit()
349
350 def _do_screenshots_2(self):
351 info('_do_screenshots_2')
352 self._screenshot(FunctionalTest.start_time, 'main_menu_2')
353 self._do_screenshots_restore_options()
354 self._do_screenshots_play()
355 self._do_screenshots_exit()
356
357 def _do_screenshots(self, idx):
358 [self._do_screenshots_1, self._do_screenshots_2][int(idx) - 1]()
359
360
361 class TestApp(ShowBase):
362
363 def __init__(self):
364 ShowBase.__init__(self)
365 offset = int(argv[2]) if len(argv) >= 3 else 0
366 fun_test = FunctionalTest(int(argv[1]), offset)
367
368
369 TestApp().run()