Changeset View
Changeset View
Standalone View
Standalone View
source/gui/tests/test_GuiManager.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | void test_hotkeysState() | ||||
std::shared_ptr<ScriptInterface::StructuredClone> data = scriptInterface.WriteStructuredClone(JS::NullHandleValue); | std::shared_ptr<ScriptInterface::StructuredClone> data = scriptInterface.WriteStructuredClone(JS::NullHandleValue); | ||||
g_GUI->PushPage(L"hotkey/page_hotkey.xml", data, JS::UndefinedHandleValue); | g_GUI->PushPage(L"hotkey/page_hotkey.xml", data, JS::UndefinedHandleValue); | ||||
// Press 'a'. | // Press 'a'. | ||||
SDL_Event_ hotkeyNotification; | SDL_Event_ hotkeyNotification; | ||||
hotkeyNotification.ev.type = SDL_KEYDOWN; | hotkeyNotification.ev.type = SDL_KEYDOWN; | ||||
hotkeyNotification.ev.key.keysym.sym = SDLK_a; | hotkeyNotification.ev.key.keysym.sym = SDLK_a; | ||||
hotkeyNotification.ev.key.repeat = 0; | |||||
// Init input and poll the event. | // Init input and poll the event. | ||||
InitInput(); | InitInput(); | ||||
in_push_priority_event(&hotkeyNotification); | in_push_priority_event(&hotkeyNotification); | ||||
SDL_Event_ ev; | SDL_Event_ ev; | ||||
while (in_poll_event(&ev)) | while (in_poll_event(&ev)) | ||||
in_dispatch_event(&ev); | in_dispatch_event(&ev); | ||||
Show All 10 Lines | void test_hotkeysState() | ||||
ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | ||||
TS_ASSERT_EQUALS(hotkey_pressed_value, true); | TS_ASSERT_EQUALS(hotkey_pressed_value, true); | ||||
hotkey_pressed_value = false; | hotkey_pressed_value = false; | ||||
pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value); | pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value); | ||||
ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | ||||
TS_ASSERT_EQUALS(hotkey_pressed_value, true); | TS_ASSERT_EQUALS(hotkey_pressed_value, true); | ||||
// We are listening to KeyDown events, so repeat shouldn't matter. | |||||
hotkeyNotification.ev.key.repeat = 1; | |||||
in_push_priority_event(&hotkeyNotification); | |||||
while (in_poll_event(&ev)) | |||||
in_dispatch_event(&ev); | |||||
hotkey_pressed_value = false; | |||||
pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value); | |||||
ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | |||||
TS_ASSERT_EQUALS(hotkey_pressed_value, true); | |||||
hotkey_pressed_value = false; | |||||
pageScriptInterface.GetProperty(global, "state_after", &js_hotkey_pressed_value); | |||||
ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | |||||
TS_ASSERT_EQUALS(hotkey_pressed_value, true); | |||||
hotkeyNotification.ev.type = SDL_KEYUP; | hotkeyNotification.ev.type = SDL_KEYUP; | ||||
in_push_priority_event(&hotkeyNotification); | in_push_priority_event(&hotkeyNotification); | ||||
while (in_poll_event(&ev)) | while (in_poll_event(&ev)) | ||||
in_dispatch_event(&ev); | in_dispatch_event(&ev); | ||||
hotkey_pressed_value = true; | hotkey_pressed_value = true; | ||||
pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value); | pageScriptInterface.GetProperty(global, "state_before", &js_hotkey_pressed_value); | ||||
ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | ScriptInterface::FromJSVal(pcx, js_hotkey_pressed_value, hotkey_pressed_value); | ||||
Show All 9 Lines |
Wildfire Games · Phabricator