switch-pico/tests/firmware/test_switch_input.cpp
Joey Yakimowich-Payne a1dd3af692 Share input model
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-08-11 12:23:07 +09:00

52 lines
2.4 KiB
C++

#include "test_support.h"
#include <cstddef>
#include "../../switch_input.h"
namespace {
bool switch_input_constants_match_legacy_values() {
// Given/When: the shared input constants are compiled after extraction.
// Then: every UART-visible legacy value remains unchanged.
CHECK(SWITCH_PRO_HAT_UP == 0x00 && SWITCH_PRO_HAT_UPRIGHT == 0x01);
CHECK(SWITCH_PRO_HAT_RIGHT == 0x02 && SWITCH_PRO_HAT_DOWNRIGHT == 0x03);
CHECK(SWITCH_PRO_HAT_DOWN == 0x04 && SWITCH_PRO_HAT_DOWNLEFT == 0x05);
CHECK(SWITCH_PRO_HAT_LEFT == 0x06 && SWITCH_PRO_HAT_UPLEFT == 0x07);
CHECK(SWITCH_PRO_HAT_NOTHING == 0x08);
CHECK(SWITCH_PRO_MASK_Y == (1U << 0) && SWITCH_PRO_MASK_B == (1U << 1));
CHECK(SWITCH_PRO_MASK_A == (1U << 2) && SWITCH_PRO_MASK_X == (1U << 3));
CHECK(SWITCH_PRO_MASK_L == (1U << 4) && SWITCH_PRO_MASK_R == (1U << 5));
CHECK(SWITCH_PRO_MASK_ZL == (1U << 6) && SWITCH_PRO_MASK_ZR == (1U << 7));
CHECK(SWITCH_PRO_MASK_MINUS == (1U << 8) && SWITCH_PRO_MASK_PLUS == (1U << 9));
CHECK(SWITCH_PRO_MASK_L3 == (1U << 10) && SWITCH_PRO_MASK_R3 == (1U << 11));
CHECK(SWITCH_PRO_MASK_HOME == (1U << 12) && SWITCH_PRO_MASK_CAPTURE == (1U << 13));
CHECK(SWITCH_PRO_JOYSTICK_MIN == 0x0000);
CHECK(SWITCH_PRO_JOYSTICK_MID == 0x7FFF);
CHECK(SWITCH_PRO_JOYSTICK_MAX == 0xFFFF);
return true;
}
bool switch_input_layout_matches_legacy_layout() {
// Given/When: the shared input types are compiled after extraction.
// Then: field offsets and aggregate sizes match the former driver-owned layout.
CHECK(sizeof(SwitchImuSample) == 12);
CHECK(offsetof(SwitchImuSample, accel_x) == 0);
CHECK(offsetof(SwitchImuSample, gyro_z) == 10);
CHECK(offsetof(SwitchInputState, dpad_up) == 0);
CHECK(offsetof(SwitchInputState, button_a) == 4);
CHECK(offsetof(SwitchInputState, button_r3) == 17);
CHECK(offsetof(SwitchInputState, lx) == 18);
CHECK(offsetof(SwitchInputState, ry) == 24);
CHECK(offsetof(SwitchInputState, imu_sample_count) == 26);
CHECK(offsetof(SwitchInputState, imu_samples) == 28);
CHECK(sizeof(SwitchInputState) == 64);
return true;
}
} // namespace
void run_switch_input_tests(TestRunner& runner) {
runner.run("shared input constants preserve legacy values", switch_input_constants_match_legacy_values);
runner.run("shared input types preserve legacy layout", switch_input_layout_matches_legacy_layout);
}