mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-23 18:45:48 -04:00
a8559bfbbc
* Update all CMakeLists of extensions to use clang-format * Run clang-format on all Extensions * Update GDCore CMakeLists.txt to add clang-format * Run clang-format on GDCore files * Update GDJS and GDCpp CMakeLists.txt to add clang-format * Run clang-format on GDCpp and GDJS files
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
/*
|
|
* GDevelop C++ Platform
|
|
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
|
|
* reserved. This project is released under the MIT License.
|
|
*/
|
|
/**
|
|
* @file Tests for InputManager
|
|
*/
|
|
#include "GDCpp/Runtime/InputManager.h"
|
|
#include <SFML/Window.hpp>
|
|
#include "GDCore/CommonTools.h"
|
|
#include "catch.hpp"
|
|
|
|
TEST_CASE("InputManager", "[game-engine]") {
|
|
SECTION("Key maps") {
|
|
REQUIRE(InputManager::GetSfKeyToKeyNameMap()
|
|
.find(static_cast<int>(sf::Keyboard::A))
|
|
->second == "a");
|
|
REQUIRE(InputManager::GetSfKeyToKeyNameMap()
|
|
.find(static_cast<int>(sf::Keyboard::Space))
|
|
->second == "Space");
|
|
REQUIRE(InputManager::GetKeyNameToSfKeyMap().find("Space")->second ==
|
|
sf::Keyboard::Space);
|
|
REQUIRE(InputManager::GetKeyNameToSfKeyMap().find("a")->second ==
|
|
sf::Keyboard::A);
|
|
}
|
|
SECTION("Button maps") {
|
|
REQUIRE(InputManager::GetSfButtonToButtonNameMap()
|
|
.find(static_cast<int>(sf::Mouse::Left))
|
|
->second == "Left");
|
|
REQUIRE(InputManager::GetButtonNameToSfButtonMap().find("Left")->second ==
|
|
sf::Mouse::Left);
|
|
}
|
|
SECTION("Key event management") {
|
|
InputManager m;
|
|
|
|
sf::Event keyEvent;
|
|
keyEvent.type = sf::Event::KeyPressed;
|
|
keyEvent.key = {sf::Keyboard::A, false, false, false, false};
|
|
|
|
sf::Event focusLost;
|
|
focusLost.type = sf::Event::LostFocus;
|
|
|
|
m.HandleEvent(keyEvent);
|
|
REQUIRE(m.AnyKeyIsPressed() == true);
|
|
|
|
m.NextFrame();
|
|
REQUIRE(m.AnyKeyIsPressed() == false);
|
|
|
|
m.NextFrame();
|
|
m.HandleEvent(focusLost);
|
|
m.HandleEvent(keyEvent);
|
|
REQUIRE(m.AnyKeyIsPressed() == false);
|
|
}
|
|
SECTION("Mouse event management") {
|
|
InputManager m;
|
|
|
|
REQUIRE(m.IsMouseButtonPressed("Left") == false);
|
|
REQUIRE(m.IsMouseButtonPressed("Right") == false);
|
|
REQUIRE(m.IsMouseButtonReleased("Left") == false);
|
|
REQUIRE(m.IsMouseButtonReleased("Right") == false);
|
|
|
|
// We can't mock mouse buttons.
|
|
}
|
|
}
|