Add some joystick flag tests. The important checks are the ones done with the invertX&Y apply. The isJoystickFlagged checks are sanity checks, you could replace those with whatever you use for flag testing next @csmartdalton. Note that the flag value is loaded via core (auto-generated) as a raw uint32_t: https://github.com/rive-app/rive/blob/eef7de3b1a5b34a3deb3591781ab9ca2d6e15f0d/packages/runtime/include/rive/generated/joystick_base.hpp#L170 Diffs= 7bbf083ce Add some joystick flag tests. (#5921) Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
diff --git a/.rive_head b/.rive_head index 21d0ac5..e430605 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -d35df04272e659d8244c776e9c4f558452888501 +7bbf083ce32d92ba240dbf08b852d2702fac18ca
diff --git a/test/assets/joystick_flag_test.riv b/test/assets/joystick_flag_test.riv new file mode 100644 index 0000000..2979532 --- /dev/null +++ b/test/assets/joystick_flag_test.riv Binary files differ
diff --git a/test/joystick_flags_test.cpp b/test/joystick_flags_test.cpp new file mode 100644 index 0000000..2e064bb --- /dev/null +++ b/test/joystick_flags_test.cpp
@@ -0,0 +1,54 @@ +#include "rive/joystick.hpp" +#include "rive/shapes/shape.hpp" +#include "rive_file_reader.hpp" +#include "rive_testing.hpp" + +TEST_CASE("joystick flags load as expected", "[file]") +{ + auto file = ReadRiveFile("../../test/assets/joystick_flag_test.riv"); + auto artboard = file->artboard(); + + auto invertX = artboard->find<rive::Joystick>("Invert X Joystick"); + REQUIRE(invertX->isJoystickFlagged(rive::JoystickFlags::invertX)); + REQUIRE(!invertX->isJoystickFlagged(rive::JoystickFlags::invertY)); + REQUIRE(!invertX->isJoystickFlagged(rive::JoystickFlags::worldSpace)); + + invertX->x(0.0f); + invertX->apply(artboard); + REQUIRE(artboard->find<rive::Shape>("invert_x_rect")->x() == 350.0f); + + invertX->x(1.0f); + invertX->apply(artboard); + REQUIRE(artboard->find<rive::Shape>("invert_x_rect")->x() == 300.0f); + + invertX->x(-1.0f); + invertX->apply(artboard); + REQUIRE(artboard->find<rive::Shape>("invert_x_rect")->x() == 400.0f); + + auto invertY = artboard->find<rive::Joystick>("Invert Y Joystick"); + REQUIRE(!invertY->isJoystickFlagged(rive::JoystickFlags::invertX)); + REQUIRE(invertY->isJoystickFlagged(rive::JoystickFlags::invertY)); + REQUIRE(!invertY->isJoystickFlagged(rive::JoystickFlags::worldSpace)); + + invertY->y(0.0f); + invertY->apply(artboard); + REQUIRE(artboard->find<rive::Shape>("invert_y_ellipse")->x() == 425.0f); + + invertY->y(1.0f); + invertY->apply(artboard); + REQUIRE(artboard->find<rive::Shape>("invert_y_ellipse")->x() == 400.0f); + + invertY->y(-1.0f); + invertY->apply(artboard); + REQUIRE(artboard->find<rive::Shape>("invert_y_ellipse")->x() == 450.0f); + + auto world = artboard->find<rive::Joystick>("World Joystick"); + REQUIRE(!world->isJoystickFlagged(rive::JoystickFlags::invertX)); + REQUIRE(!world->isJoystickFlagged(rive::JoystickFlags::invertY)); + REQUIRE(world->isJoystickFlagged(rive::JoystickFlags::worldSpace)); + + auto normal = artboard->find<rive::Joystick>("Normal Joystick"); + REQUIRE(!normal->isJoystickFlagged(rive::JoystickFlags::invertX)); + REQUIRE(!normal->isJoystickFlagged(rive::JoystickFlags::invertY)); + REQUIRE(!normal->isJoystickFlagged(rive::JoystickFlags::worldSpace)); +} \ No newline at end of file