use super::*;
fn press() -> RawControlEvent {
RawControlEvent::DivertedButtons([reprog_controls::GESTURE_BUTTON_CID, 0, 0, 0])
}
fn release() -> RawControlEvent {
RawControlEvent::DivertedButtons([0, 0, 0, 0])
}
#[test]
fn quick_tap_is_a_click_even_while_the_cursor_moves() {
let (tx, mut rx) = mpsc::unbounded_channel();
let mut acc = CaptureAccum::default();
handle_reprog(&mut acc, press(), &[], &tx);
handle_reprog(
&mut acc,
RawControlEvent::RawXy { dx: 120, dy: 5 },
&[],
&tx,
);
handle_reprog(&mut acc, release(), &[], &tx);
assert_eq!(
rx.try_recv(),
Ok(CapturedInput::Gesture(GestureDirection::Click))
);
assert!(
rx.try_recv().is_err(),
"a quick tap emits exactly one click"
);
}
#[test]
fn a_held_gesture_commits_a_swipe_and_does_not_also_click() {
let (tx, mut rx) = mpsc::unbounded_channel();
let mut acc = CaptureAccum::default();
handle_reprog(&mut acc, press(), &[], &tx);
acc.swipe.backdate_hold_for_test();
handle_reprog(
&mut acc,
RawControlEvent::RawXy { dx: 120, dy: 5 },
&[],
&tx,
);
assert_eq!(
rx.try_recv(),
Ok(CapturedInput::Gesture(GestureDirection::Right))
);
handle_reprog(&mut acc, release(), &[], &tx);
assert!(
rx.try_recv().is_err(),
"a committed swipe must not also click on release"
);
}
#[test]
fn a_held_dpi_button_presses_once_on_the_rising_edge() {
let (tx, mut rx) = mpsc::unbounded_channel();
let mut acc = CaptureAccum::default();
let dpi = reprog_controls::DPI_MODE_SHIFT_CIDS[0];
let down = RawControlEvent::DivertedButtons([dpi, 0, 0, 0]);
handle_reprog(&mut acc, down, &[dpi], &tx);
handle_reprog(&mut acc, down, &[dpi], &tx);
assert_eq!(
rx.try_recv(),
Ok(CapturedInput::ButtonPressed(ButtonId::DpiToggle))
);
assert!(rx.try_recv().is_err(), "a held DPI button presses once");
}
#[test]
fn a_dpi_button_re_presses_after_a_release() {
let (tx, mut rx) = mpsc::unbounded_channel();
let mut acc = CaptureAccum::default();
let dpi = reprog_controls::DPI_MODE_SHIFT_CIDS[0];
let down = RawControlEvent::DivertedButtons([dpi, 0, 0, 0]);
let up = RawControlEvent::DivertedButtons([0, 0, 0, 0]);
handle_reprog(&mut acc, down, &[dpi], &tx);
handle_reprog(&mut acc, up, &[dpi], &tx);
handle_reprog(&mut acc, down, &[dpi], &tx);
assert_eq!(
rx.try_recv(),
Ok(CapturedInput::ButtonPressed(ButtonId::DpiToggle))
);
assert_eq!(
rx.try_recv(),
Ok(CapturedInput::ButtonPressed(ButtonId::DpiToggle)),
"a release re-arms the rising edge"
);
assert!(rx.try_recv().is_err());
}