/* SPDX-License-Identifier: GPL-3.0-or-later */ #include #include #include "input.h" static QInput s; static QActions step(Q16 keys,Q8 button,Q8 x,Q8 y,Q16 ms,Q8 playing){return q_input_step(&s,keys,button,x,y,31,31,1,ms,playing,0);} static void reset(void){q_input_reset(&s);step(0,0,31,31,0,1);} int main(void){QActions a; reset();a=step(Q_LEFT,0,31,31,0,1);assert(a.move==-1&&a.repeats==1); a=step(Q_LEFT,0,31,31,199,1);assert(!a.repeats); a=step(Q_LEFT,0,31,31,1,1);assert(a.move==-1&&a.repeats==1); a=step(Q_LEFT,0,31,31,39,1);assert(!a.repeats); a=step(Q_LEFT|Q_RIGHT,0,31,31,1,1);assert(a.move==-1&&a.repeats==1); a=step(Q_RIGHT,0,31,31,1,1);assert(a.move==1&&a.repeats==1); reset();a=step(Q_CCW,0,31,31,1,1);assert(a.pressed&Q_CCW); a=step(Q_CCW,0,31,31,500,1);assert(!(a.pressed&Q_CCW)); reset();step(0,1,31,31,100,1);a=step(0,0,31,31,1,1);assert(a.pressed&Q_CCW); reset();step(0,1,31,31,399,1);a=step(0,1,31,31,1,1);assert(a.pressed&Q_PAUSE); a=step(0,0,31,31,1,1);assert(!(a.pressed&Q_CCW)); reset();a=step(0,0,31,10,1,1);assert(a.pressed&Q_HARD); a=step(0,0,31,10,500,1);assert(!(a.pressed&Q_HARD)); step(0,0,31,31,1,1);a=step(0,0,31,10,1,1);assert(a.pressed&Q_HARD); reset();a=step(0,0,0,10,1,1);assert(!(a.pressed&Q_HARD)); q_input_reset(&s);step(0,0,0,0,1,1);a=step(Q_LEFT,0,0,0,1,1);assert(a.move==-1); reset();a=step(0,0,20,31,1,1);assert(a.move==-1); a=step(0,0,24,31,1,1);assert(a.held&Q_LEFT); a=step(0,0,25,31,1,1);assert(!(a.held&Q_LEFT)); reset();step(0,1,31,31,100,0);a=step(0,0,31,31,1,0);assert(a.pressed&Q_CONFIRM); /* X can center/arm while an uncalibrated or deliberately held Y stays low. */ q_input_reset(&s);step(0,0,31,0,1,1); a=step(0,0,0,0,1,1);assert(a.move==-1&&a.repeats==1&&!(a.pressed&Q_HARD)); a=step(0,0,0,0,200,1);assert(a.move==-1&&a.repeats==1); a=step(0,0,63,0,1,1);assert(a.move==1&&a.repeats==1); a=step(0,0,31,0,1,1);assert(!a.repeats); /* Releasing a deflected joystick need not center both axes at once. */ q_input_reset(&s);step(0,0,0,0,1,1); a=step(0,0,63,0,1,1);assert(!a.repeats); /* no X neutral observed yet */ step(0,0,31,0,1,1);a=step(0,0,63,0,1,1);assert(a.move==1); puts("PASS: input repeat, conflicting directions, edges, one-button timing, hysteresis, diagonal guard, disconnected-stick keyboard");return 0;}