Fix background Unity input and shop boundaries; record login failure
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from unittest import mock
|
||||||
|
from lc_mcp.aalc_engine import AalcEngine
|
||||||
|
from lc_mcp.fake_engine import FakeEngine
|
||||||
|
from lc_mcp.protocol import Server
|
||||||
|
|
||||||
|
|
||||||
|
class BackgroundRestoreTest(unittest.TestCase):
|
||||||
|
def test_mouse_message_targets_game_without_system_pointer(self):
|
||||||
|
api = mock.Mock()
|
||||||
|
api.MAKELONG.return_value = 77
|
||||||
|
constants = SimpleNamespace(MK_LBUTTON=1)
|
||||||
|
engine = AalcEngine.__new__(AalcEngine)
|
||||||
|
engine.screen = SimpleNamespace(handle=SimpleNamespace(hwnd=456))
|
||||||
|
with mock.patch.dict(sys.modules, win32api=api, win32con=constants):
|
||||||
|
engine._background_mouse(512, 100, 200, held=True)
|
||||||
|
api.PostMessage.assert_called_once_with(456, 512, 1, 77)
|
||||||
|
api.SetCursorPos.assert_not_called()
|
||||||
|
|
||||||
|
def test_drag_releases_on_error_without_legacy_cursor_handler(self):
|
||||||
|
engine = AalcEngine.__new__(AalcEngine)
|
||||||
|
engine.cfg = SimpleNamespace(simulator=False, win_input_type='background')
|
||||||
|
engine.auto = mock.Mock()
|
||||||
|
engine._grab = mock.Mock(return_value=SimpleNamespace(width=800, height=600))
|
||||||
|
engine._background_mouse = mock.Mock()
|
||||||
|
constants = SimpleNamespace(WM_MOUSEMOVE=512, WM_LBUTTONDOWN=513, WM_LBUTTONUP=514)
|
||||||
|
with mock.patch.dict(sys.modules, win32con=constants), \
|
||||||
|
mock.patch('lc_mcp.aalc_engine.time.sleep', side_effect=[None, RuntimeError('stopped')]):
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
engine.drag(100, 100, 100, 500, 1.5)
|
||||||
|
self.assertEqual(engine._background_mouse.call_args, mock.call(514, 100, 100))
|
||||||
|
engine.auto.input_handler.set_mouse_pos.assert_not_called()
|
||||||
|
engine.auto.mouse_drag.assert_not_called()
|
||||||
|
|
||||||
|
def test_window_move_click_restores_after_release_without_system_pointer(self):
|
||||||
|
engine = AalcEngine.__new__(AalcEngine)
|
||||||
|
engine.cfg = SimpleNamespace(simulator=False, win_input_type='window_move')
|
||||||
|
engine.auto = mock.Mock()
|
||||||
|
engine.screen = mock.Mock()
|
||||||
|
engine.auto.input_handler._set_window_pos.return_value = (20, 30)
|
||||||
|
engine._background_mouse = mock.Mock()
|
||||||
|
engine._restore_background_position = mock.Mock()
|
||||||
|
constants = SimpleNamespace(WM_MOUSEMOVE=512, WM_LBUTTONDOWN=513, WM_LBUTTONUP=514)
|
||||||
|
with mock.patch.dict(sys.modules, win32con=constants), \
|
||||||
|
mock.patch('lc_mcp.aalc_engine.time.sleep'):
|
||||||
|
engine.click(100, 200)
|
||||||
|
engine._restore_background_position.assert_called_once_with((20, 30))
|
||||||
|
engine.auto.input_handler.set_mouse_pos.assert_not_called()
|
||||||
|
engine.screen.handle.set_window_transparent.assert_called_once_with(True)
|
||||||
|
|
||||||
|
def test_restore_uses_noactivate_and_preserves_foreground(self):
|
||||||
|
gui = mock.Mock()
|
||||||
|
gui.GetForegroundWindow.return_value = 123
|
||||||
|
gui.IsWindowVisible.return_value = True
|
||||||
|
engine = AalcEngine.__new__(AalcEngine)
|
||||||
|
engine.cfg = SimpleNamespace(simulator=False)
|
||||||
|
engine.screen = SimpleNamespace(handle=SimpleNamespace(hwnd=456))
|
||||||
|
with mock.patch.dict(sys.modules, {'win32gui': gui,
|
||||||
|
'win32con': SimpleNamespace(SW_SHOWNOACTIVATE=4)}):
|
||||||
|
result = engine.show_game_background()
|
||||||
|
gui.ShowWindow.assert_called_once_with(456, 4)
|
||||||
|
gui.SetForegroundWindow.assert_not_called()
|
||||||
|
self.assertFalse(result['foreground_changed'])
|
||||||
|
|
||||||
|
def test_running_task_blocks_restore(self):
|
||||||
|
tasks = mock.Mock()
|
||||||
|
tasks.running.return_value = True
|
||||||
|
tasks.info = {'task': 'mirror'}
|
||||||
|
engine = FakeEngine()
|
||||||
|
server = Server(engine, tasks)
|
||||||
|
self.assertFalse(server.call_tool('show_game_background', {})['ok'])
|
||||||
|
self.assertEqual(engine.actions, [])
|
||||||
Reference in New Issue
Block a user