Skip to content

Commit

Permalink
Add some joystick flag tests.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
luigi-rosso and luigi-rosso committed Aug 30, 2023
1 parent 23be2fe commit f65d21c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d35df04272e659d8244c776e9c4f558452888501
7bbf083ce32d92ba240dbf08b852d2702fac18ca
Binary file added test/assets/joystick_flag_test.riv
Binary file not shown.
54 changes: 54 additions & 0 deletions test/joystick_flags_test.cpp
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit f65d21c

Please sign in to comment.