Skip to content

Commit

Permalink
Add more tests for the Window module
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Sep 8, 2024
1 parent 02d6d49 commit d971aad
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ catch_discover_tests(test-csfml-system)

add_executable(test-csfml-window
Window/Joystick.test.cpp
Window/Keyboard.test.cpp
Window/Mouse.test.cpp
Window/Sensor.test.cpp
Window/WindowBase.test.cpp
)
target_link_libraries(test-csfml-window PRIVATE csfml-window Catch2::Catch2WithMain)
target_link_libraries(test-csfml-window PRIVATE csfml-window Catch2::Catch2WithMain SFML::Window)
set_target_warnings(test-csfml-window)
catch_discover_tests(test-csfml-window)

Expand Down
14 changes: 14 additions & 0 deletions test/Window/Joystick.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <CSFML/Window/Joystick.h>

#include <SFML/Window/Joystick.hpp>

#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_range.hpp>

Expand All @@ -12,6 +14,18 @@ TEST_CASE("[Window] sfJoystick")
STATIC_CHECK(sfJoystickAxisCount == 8);
}

SECTION("sfJoystickAxis")
{
STATIC_CHECK(sfJoystickX == static_cast<int>(sf::Joystick::Axis::X));
STATIC_CHECK(sfJoystickY == static_cast<int>(sf::Joystick::Axis::Y));
STATIC_CHECK(sfJoystickZ == static_cast<int>(sf::Joystick::Axis::Z));
STATIC_CHECK(sfJoystickR == static_cast<int>(sf::Joystick::Axis::R));
STATIC_CHECK(sfJoystickU == static_cast<int>(sf::Joystick::Axis::U));
STATIC_CHECK(sfJoystickV == static_cast<int>(sf::Joystick::Axis::V));
STATIC_CHECK(sfJoystickPovX == static_cast<int>(sf::Joystick::Axis::PovX));
STATIC_CHECK(sfJoystickPovY == static_cast<int>(sf::Joystick::Axis::PovY));
}

// By avoiding calling sfJoystick_update() we can guarantee that
// no joysticks will be detected. This is how we can ensure these
// tests are portable and reliable.
Expand Down
29 changes: 29 additions & 0 deletions test/Window/Keyboard.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <CSFML/Window/Keyboard.h>

#include <SFML/Window/Keyboard.hpp>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Window] sfKeyboard")
{
SECTION("sfKeyCode")
{
STATIC_CHECK(sfKeyUnknown == static_cast<int>(sf::Keyboard::Key::Unknown));
STATIC_CHECK(sfKeyA == static_cast<int>(sf::Keyboard::Key::A));
STATIC_CHECK(sfKeyB == static_cast<int>(sf::Keyboard::Key::B));
STATIC_CHECK(sfKeyC == static_cast<int>(sf::Keyboard::Key::C));
STATIC_CHECK(sfKeyD == static_cast<int>(sf::Keyboard::Key::D));
STATIC_CHECK(sfKeyPause == static_cast<int>(sf::Keyboard::Key::Pause));
STATIC_CHECK(sfKeyCount == sf::Keyboard::KeyCount);
}

SECTION("sfScancode")
{
STATIC_CHECK(sfScanUnknown == static_cast<int>(sf::Keyboard::Scan::Unknown));
STATIC_CHECK(sfScanA == static_cast<int>(sf::Keyboard::Scan::A));
STATIC_CHECK(sfScanB == static_cast<int>(sf::Keyboard::Scan::B));
STATIC_CHECK(sfScanC == static_cast<int>(sf::Keyboard::Scan::C));
STATIC_CHECK(sfScanD == static_cast<int>(sf::Keyboard::Scan::D));
STATIC_CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
}
}
24 changes: 24 additions & 0 deletions test/Window/Mouse.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <CSFML/Window/Mouse.h>

#include <SFML/Window/Mouse.hpp>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Window] sfMouse")
{
SECTION("sfMouseButton")
{
STATIC_CHECK(sfMouseLeft == static_cast<int>(sf::Mouse::Button::Left));
STATIC_CHECK(sfMouseRight == static_cast<int>(sf::Mouse::Button::Right));
STATIC_CHECK(sfMouseMiddle == static_cast<int>(sf::Mouse::Button::Middle));
STATIC_CHECK(sfMouseXButton1 == static_cast<int>(sf::Mouse::Button::Extra1));
STATIC_CHECK(sfMouseXButton2 == static_cast<int>(sf::Mouse::Button::Extra2));
STATIC_CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount);
}

SECTION("sfMouseWheel")
{
STATIC_CHECK(sfMouseHorizontalWheel == static_cast<int>(sf::Mouse::Wheel::Horizontal));
STATIC_CHECK(sfMouseVerticalWheel == static_cast<int>(sf::Mouse::Wheel::Vertical));
}
}
19 changes: 19 additions & 0 deletions test/Window/Sensor.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <CSFML/Window/Sensor.h>

#include <SFML/Window/Sensor.hpp>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Window] sfSensor")
{
SECTION("sfSensorType")
{
STATIC_CHECK(sfSensorAccelerometer == static_cast<int>(sf::Sensor::Type::Accelerometer));
STATIC_CHECK(sfSensorGyroscope == static_cast<int>(sf::Sensor::Type::Gyroscope));
STATIC_CHECK(sfSensorMagnetometer == static_cast<int>(sf::Sensor::Type::Magnetometer));
STATIC_CHECK(sfSensorGravity == static_cast<int>(sf::Sensor::Type::Gravity));
STATIC_CHECK(sfSensorUserAcceleration == static_cast<int>(sf::Sensor::Type::UserAcceleration));
STATIC_CHECK(sfSensorOrientation == static_cast<int>(sf::Sensor::Type::Orientation));
STATIC_CHECK(sfSensorCount == sf::Sensor::Count);
}
}
23 changes: 23 additions & 0 deletions test/Window/WindowBase.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <CSFML/Window/WindowBase.h>

#include <SFML/Window/WindowBase.hpp>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Window] sfWindowBase")
{
SECTION("sfWindowStyle")
{
STATIC_CHECK(sfNone == static_cast<int>(sf::Style::None));
STATIC_CHECK(sfTitlebar == static_cast<int>(sf::Style::Titlebar));
STATIC_CHECK(sfResize == static_cast<int>(sf::Style::Resize));
STATIC_CHECK(sfClose == static_cast<int>(sf::Style::Close));
STATIC_CHECK(sfDefaultStyle == static_cast<int>(sf::Style::Default));
}

SECTION("sfWindowState")
{
STATIC_CHECK(sfWindowed == static_cast<int>(sf::State::Windowed));
STATIC_CHECK(sfFullscreen == static_cast<int>(sf::State::Fullscreen));
}
}

0 comments on commit d971aad

Please sign in to comment.