Skip to content

Commit

Permalink
clean up tests and result handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kshen0 committed Feb 15, 2024
1 parent 7f21a30 commit 74cb5de
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions apps/mark-scan/accessible-controller/src/controllerd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,12 @@ fn main() {
}
match port.read(serial_buf.as_mut_slice()) {
Ok(size) => match handle_command(&serial_buf[..size]) {
Ok(key_option) => {
if key_option.is_some() {
let key = key_option.unwrap();
if let Err(err) = send_key(&mut device, key) {
log!(EventId::UnknownError, "Error sending key: {err}");
}
Ok(Some(key)) => {
if let Err(err) = send_key(&mut device, key) {
log!(EventId::UnknownError, "Error sending key: {err}");
}
}
Ok(None) => {}
Err(err) => log!(
event_id: EventId::UnknownError,
message: format!(
Expand Down Expand Up @@ -438,8 +436,6 @@ fn main() {
mod tests {
use super::*;

const DEVICE_WAIT_DURATION: Duration = Duration::from_millis(100);

#[test]
fn test_handle_command_packet_length_error() {
let bad_data = [0x01];
Expand All @@ -463,10 +459,6 @@ mod tests {

#[test]
fn test_handle_command_success() {
// In prod we wait 1s for the device to register.
// We can afford to be riskier to speed up tests.
thread::sleep(DEVICE_WAIT_DURATION);

let data = [
0x30,
0x00,
Expand All @@ -476,8 +468,6 @@ mod tests {
0xc8,
0x37,
];
let key_option = handle_command(&data).unwrap();
assert!(key_option.is_some());
assert_eq!(key_option.unwrap(), keyboard::Key::R);
assert_eq!(handle_command(&data).unwrap().unwrap(), keyboard::Key::R);
}
}

0 comments on commit 74cb5de

Please sign in to comment.