#include #include #include TEST_CASE("[Window] sf::Event") { SECTION("Type traits") { STATIC_CHECK(std::is_copy_constructible_v); STATIC_CHECK(std::is_copy_assignable_v); STATIC_CHECK(std::is_nothrow_move_constructible_v); STATIC_CHECK(std::is_nothrow_move_assignable_v); } SECTION("Construction") { SECTION("Default constructor") { const sf::Event event; CHECK(!event); CHECK(event.is()); CHECK(event.getIf()); } SECTION("Template constructor") { const sf::Event event = sf::Event::Resized{{1, 2}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& resized = *event.getIf(); CHECK(resized.size == sf::Vector2u(1, 2)); } } SECTION("Assign all possible values") { sf::Event event; event = sf::Event::Closed{}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); event = sf::Event::Resized{{1, 2}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& resized = *event.getIf(); CHECK(resized.size == sf::Vector2u(1, 2)); event = sf::Event::FocusLost{}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); event = sf::Event::FocusGained{}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); event = sf::Event::TextEntered{123456}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& textEntered = *event.getIf(); CHECK(textEntered.unicode == 123456); event = sf::Event::KeyPressed{sf::Keyboard::Key::C, sf::Keyboard::Scan::C, true, true, true, true}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& keyPressed = *event.getIf(); CHECK(keyPressed.code == sf::Keyboard::Key::C); CHECK(keyPressed.scancode == sf::Keyboard::Scan::C); CHECK(keyPressed.alt); CHECK(keyPressed.control); CHECK(keyPressed.shift); CHECK(keyPressed.system); event = sf::Event::KeyReleased{sf::Keyboard::Key::D, sf::Keyboard::Scan::D, true, true, true, true}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& keyReleased = *event.getIf(); CHECK(keyReleased.code == sf::Keyboard::Key::D); CHECK(keyReleased.scancode == sf::Keyboard::Scan::D); CHECK(keyReleased.alt); CHECK(keyReleased.control); CHECK(keyReleased.shift); CHECK(keyReleased.system); event = sf::Event::MouseWheelScrolled{sf::Mouse::Wheel::Horizontal, 3.14f, {4, 5}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& mouseWheelScrolled = *event.getIf(); CHECK(mouseWheelScrolled.wheel == sf::Mouse::Wheel::Horizontal); CHECK(mouseWheelScrolled.delta == 3.14f); CHECK(mouseWheelScrolled.position == sf::Vector2i(4, 5)); event = sf::Event::MouseButtonPressed{sf::Mouse::Button::Middle, {6, 7}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& mouseButtonPressed = *event.getIf(); CHECK(mouseButtonPressed.button == sf::Mouse::Button::Middle); CHECK(mouseButtonPressed.position == sf::Vector2i(6, 7)); event = sf::Event::MouseButtonReleased{sf::Mouse::Button::Extra1, {8, 9}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& mouseButtonReleased = *event.getIf(); CHECK(mouseButtonReleased.button == sf::Mouse::Button::Extra1); CHECK(mouseButtonReleased.position == sf::Vector2i(8, 9)); event = sf::Event::MouseMoved{{4, 2}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& mouseMoved = *event.getIf(); CHECK(mouseMoved.position == sf::Vector2i(4, 2)); event = sf::Event::MouseEntered{}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); event = sf::Event::MouseLeft{}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); event = sf::Event::JoystickButtonPressed{100, 200}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& joystickButtonPressed = *event.getIf(); CHECK(joystickButtonPressed.joystickId == 100); CHECK(joystickButtonPressed.button == 200); event = sf::Event::JoystickButtonReleased{300, 400}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& joystickButtonReleased = *event.getIf(); CHECK(joystickButtonReleased.joystickId == 300); CHECK(joystickButtonReleased.button == 400); event = sf::Event::JoystickMoved{300, sf::Joystick::Axis::Z, 1.23f}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& joystickMoved = *event.getIf(); CHECK(joystickMoved.joystickId == 300); CHECK(joystickMoved.axis == sf::Joystick::Axis::Z); CHECK(joystickMoved.position == 1.23f); event = sf::Event::JoystickConnected{42}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& joystickConnected = *event.getIf(); CHECK(joystickConnected.joystickId == 42); event = sf::Event::JoystickDisconnected{43}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& joystickDisconnected = *event.getIf(); CHECK(joystickDisconnected.joystickId == 43); event = sf::Event::TouchBegan{99, {98, 97}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& touchBegan = *event.getIf(); CHECK(touchBegan.finger == 99); CHECK(touchBegan.position == sf::Vector2i(98, 97)); event = sf::Event::TouchMoved{96, {95, 94}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& touchMoved = *event.getIf(); CHECK(touchMoved.finger == 96); CHECK(touchMoved.position == sf::Vector2i(95, 94)); event = sf::Event::TouchEnded{93, {92, 91}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& touchEnded = *event.getIf(); CHECK(touchEnded.finger == 93); CHECK(touchEnded.position == sf::Vector2i(92, 91)); event = sf::Event::SensorChanged{sf::Sensor::Type::Gravity, {1.2f, 3.4f, 5.6f}}; CHECK(event); CHECK(event.is()); CHECK(event.getIf()); const auto& sensorChanged = *event.getIf(); CHECK(sensorChanged.type == sf::Sensor::Type::Gravity); CHECK(sensorChanged.value == sf::Vector3f(1.2f, 3.4f, 5.6f)); } SECTION("Subtypes") { // Empty structs STATIC_CHECK(std::is_empty_v); STATIC_CHECK(std::is_empty_v); STATIC_CHECK(std::is_empty_v); STATIC_CHECK(std::is_empty_v); STATIC_CHECK(std::is_empty_v); STATIC_CHECK(std::is_empty_v); // Non-empty structs const sf::Event::Resized resized; CHECK(resized.size == sf::Vector2u()); const sf::Event::TextEntered textEntered; CHECK(textEntered.unicode == 0); const sf::Event::KeyPressed keyPressed; CHECK(keyPressed.code == sf::Keyboard::Key{}); CHECK(keyPressed.scancode == sf::Keyboard::Scancode{}); CHECK(!keyPressed.alt); CHECK(!keyPressed.control); CHECK(!keyPressed.shift); CHECK(!keyPressed.system); const sf::Event::KeyReleased keyReleased; CHECK(keyReleased.code == sf::Keyboard::Key{}); CHECK(keyReleased.scancode == sf::Keyboard::Scancode{}); CHECK(!keyReleased.alt); CHECK(!keyReleased.control); CHECK(!keyReleased.shift); CHECK(!keyReleased.system); const sf::Event::MouseWheelScrolled mouseWheelScrolled; CHECK(mouseWheelScrolled.wheel == sf::Mouse::Wheel{}); CHECK(mouseWheelScrolled.delta == 0); CHECK(mouseWheelScrolled.position == sf::Vector2i()); const sf::Event::MouseButtonPressed mouseButtonPressed; CHECK(mouseButtonPressed.button == sf::Mouse::Button{}); CHECK(mouseButtonPressed.position == sf::Vector2i()); const sf::Event::MouseButtonReleased mouseButtonReleased; CHECK(mouseButtonReleased.button == sf::Mouse::Button{}); CHECK(mouseButtonReleased.position == sf::Vector2i()); const sf::Event::MouseMoved mouseMoved; CHECK(mouseMoved.position == sf::Vector2i()); const sf::Event::JoystickButtonPressed joystickButtonPressed; CHECK(joystickButtonPressed.joystickId == 0); CHECK(joystickButtonPressed.button == 0); const sf::Event::JoystickButtonReleased joystickButtonReleased; CHECK(joystickButtonReleased.joystickId == 0); CHECK(joystickButtonReleased.button == 0); const sf::Event::JoystickMoved joystickMoved; CHECK(joystickMoved.joystickId == 0); CHECK(joystickMoved.axis == sf::Joystick::Axis{}); CHECK(joystickMoved.position == 0); const sf::Event::JoystickConnected joystickConnected; CHECK(joystickConnected.joystickId == 0); const sf::Event::JoystickDisconnected joystickDisconnected; CHECK(joystickDisconnected.joystickId == 0); const sf::Event::TouchBegan touchBegan; CHECK(touchBegan.finger == 0); CHECK(touchBegan.position == sf::Vector2i()); const sf::Event::TouchMoved touchMoved; CHECK(touchMoved.finger == 0); CHECK(touchMoved.position == sf::Vector2i()); const sf::Event::TouchEnded touchEnded; CHECK(touchEnded.finger == 0); CHECK(touchEnded.position == sf::Vector2i()); const sf::Event::SensorChanged sensorChanged; CHECK(sensorChanged.type == sf::Sensor::Type{}); CHECK(sensorChanged.value == sf::Vector3f()); } }