diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0ac05c23..d9d6466d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -64,6 +64,7 @@ set(WINDOW_SRC Window/Cursor.test.cpp Window/Event.test.cpp Window/GlResource.test.cpp + Window/Keyboard.test.cpp Window/VideoMode.test.cpp Window/Window.test.cpp Window/WindowBase.test.cpp diff --git a/test/Window/Keyboard.test.cpp b/test/Window/Keyboard.test.cpp new file mode 100644 index 00000000..8793a587 --- /dev/null +++ b/test/Window/Keyboard.test.cpp @@ -0,0 +1,61 @@ +#include + +// Other 1st party headers +#include + +#include + +#include + +// We're limited on what can be tested. Without control over the hardware and the +// configuration of the operating system, certain things cannot be tested. In +// general, the mapping between keys and scancodes is a user configuration. Our +// tests cannot assume any particular configuration. +// +// Regardless this test case represents a best faith effort to cover some of this +// code in a way that is hopefully not prone to fail on different machines. + +TEST_CASE("[Window] sf::Keyboard", runDisplayTests()) +{ + SECTION("isKeyPressed(Key)") + { + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::W)); + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::A)); + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::S)); + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::D)); + } + + SECTION("isKeyPressed(Scancode)") + { + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::Scan::W)); + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::Scan::A)); + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::Scan::S)); + CHECK(!sf::Keyboard::isKeyPressed(sf::Keyboard::Scan::D)); + } + + SECTION("localize(Scancode)") + { + CHECK(sf::Keyboard::localize(sf::Keyboard::Scan::Space) == sf::Keyboard::Space); + } + + SECTION("delocalize(Key)") + { + CHECK(sf::Keyboard::delocalize(sf::Keyboard::Space) == sf::Keyboard::Scan::Space); + } + + SECTION("getDescription(Scancode)") + { + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F1) == "F1"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F2) == "F2"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F3) == "F3"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F4) == "F4"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F5) == "F5"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F6) == "F6"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F7) == "F7"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F8) == "F8"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F9) == "F9"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F10) == "F10"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F11) == "F11"); + CHECK(sf::Keyboard::getDescription(sf::Keyboard::Scan::F12) == "F12"); + } +}