|
45 | 45 | from maa.toolkit import Toolkit |
46 | 46 | from maa.custom_action import CustomAction |
47 | 47 | from maa.custom_recognition import CustomRecognition |
| 48 | +from maa.buffer import ImageBuffer |
48 | 49 | from maa.define import MaaDbgControllerTypeEnum, LoggingLevelEnum |
49 | 50 | from maa.context import Context, ContextEventSink |
50 | 51 | from maa.event_sink import EventSink |
@@ -408,6 +409,28 @@ def test_controller_api(): |
408 | 409 | return dbg_controller |
409 | 410 |
|
410 | 411 |
|
| 412 | +# ============================================================================ |
| 413 | +# Buffer API 测试 |
| 414 | +# ============================================================================ |
| 415 | + |
| 416 | + |
| 417 | +def test_buffer_api(): |
| 418 | + print("\n=== test_buffer_api ===") |
| 419 | + |
| 420 | + buf = ImageBuffer() |
| 421 | + src = numpy.zeros((100, 200, 3), dtype=numpy.uint8) |
| 422 | + assert buf.set(src), "set should succeed" |
| 423 | + |
| 424 | + # 仅指定宽度,按比例缩放高度 |
| 425 | + assert buf.resize(50, 0), "resize should succeed" |
| 426 | + resized = buf.get() |
| 427 | + print(f" resized shape: {resized.shape}") |
| 428 | + assert resized.shape[1] == 50, "width should be 50" |
| 429 | + assert resized.shape[0] == 25, "height should keep aspect ratio" |
| 430 | + |
| 431 | + print(" PASS: buffer API") |
| 432 | + |
| 433 | + |
411 | 434 | # ============================================================================ |
412 | 435 | # Tasker API 测试 |
413 | 436 | # ============================================================================ |
@@ -688,6 +711,7 @@ def test_toolkit(): |
688 | 711 | # 测试各模块 API |
689 | 712 | resource = test_resource_api() |
690 | 713 | controller = test_controller_api() |
| 714 | + test_buffer_api() |
691 | 715 | tasker = test_tasker_api(resource, controller) |
692 | 716 |
|
693 | 717 | # 验证自定义识别和动作被调用 |
|
0 commit comments