MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / test_controller_api

Function test_controller_api

test/python/binding_test.py:366–439  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

364
365
366def test_controller_api():
367 print("\n=== test_controller_api ===")
368
369 dbg_controller = DbgController(
370 install_dir / "test" / "PipelineSmoking" / "Screenshot",
371 )
372 print(f" controller: {dbg_controller}")
373
374 # 测试事件监听器
375 sink = MyControllerEventSink()
376 sink_id = dbg_controller.add_sink(sink)
377 print(f" sink_id: {sink_id}")
378
379 # 连接
380 dbg_controller.post_connection().wait()
381 print(f" connected: {dbg_controller.connected}")
382 print(f" uuid: {dbg_controller.uuid}")
383
384 # 测试截图
385 screencap_job = dbg_controller.post_screencap().wait()
386 assert screencap_job.succeeded, "screencap should succeed"
387 image = screencap_job.get()
388 print(f" screencap shape: {image.shape}")
389
390 # 测试 cached_image
391 cached = dbg_controller.cached_image
392 print(f" cached_image shape: {cached.shape}")
393
394 # 测试 resolution (需要在首次截图后才能获取有效值)
395 resolution = dbg_controller.resolution
396 print(f" resolution: {resolution}")
397 assert isinstance(resolution, tuple), "resolution should be a tuple"
398 assert len(resolution) == 2, "resolution should have 2 elements"
399 assert isinstance(resolution[0], int), "resolution width should be int"
400 assert isinstance(resolution[1], int), "resolution height should be int"
401
402 # 测试 info
403 info = dbg_controller.info
404 print(f" info: {info}")
405 assert isinstance(info, dict), "info should be a dict"
406 assert "type" in info, "info should contain 'type'"
407 assert info["type"] == "dbg", "dbg controller type should be 'dbg'"
408
409 # 测试输入操作
410 dbg_controller.post_click(100, 100).wait()
411 dbg_controller.post_swipe(100, 100, 200, 200, 100).wait()
412 dbg_controller.post_click_key(32).wait()
413 dbg_controller.post_key_down(65).wait()
414 dbg_controller.post_key_up(65).wait()
415 dbg_controller.post_input_text("test").wait()
416 dbg_controller.post_touch_down(0, 100, 100, 0).wait()
417 dbg_controller.post_touch_move(0, 150, 150, 0).wait()
418 dbg_controller.post_touch_up(0).wait()
419 assert not dbg_controller.post_scroll(0, 120).wait().succeeded, (
420 "dbg controller scroll should fail"
421 )
422 dbg_controller.post_start_app("com.test.app").wait()
423 dbg_controller.post_stop_app("com.test.app").wait()

Callers 1

binding_test.pyFile · 0.85

Calls 15

DbgControllerClass · 0.90
waitMethod · 0.65
add_sinkMethod · 0.45
post_connectionMethod · 0.45
post_screencapMethod · 0.45
getMethod · 0.45
post_clickMethod · 0.45
post_swipeMethod · 0.45
post_click_keyMethod · 0.45
post_key_downMethod · 0.45
post_key_upMethod · 0.45

Tested by

no test coverage detected