1 mod common;
2
3 use adevice::adevice::Profiler;
4 use adevice::cli::RestartChoice;
5 use adevice::cli::Wait;
6 use adevice::commands::{AdbAction, AdbCommand};
7 use adevice::restart_chooser::RestartChooser;
8 use anyhow::Result;
9 use common::fakes::FakeDevice;
10 use std::collections::HashMap;
11 use std::path::PathBuf;
12
13 // Just placeholder for now to show we can call adevice.
14
call_update_with_reboot(wait: Wait) -> Result<FakeDevice>15 fn call_update_with_reboot(wait: Wait) -> Result<FakeDevice> {
16 // Use real device for device tests.
17 let device = FakeDevice::new(&HashMap::new());
18 let mut profiler = Profiler::default();
19 // Capture adb command?
20 let restart_chooser = RestartChooser::new(&RestartChoice::Reboot);
21 let initial_adb_cmds = HashMap::from([(
22 PathBuf::from("ignore_me"),
23 AdbCommand::from_action(AdbAction::Mkdir, &PathBuf::from("ignore_me")),
24 )]);
25 adevice::device::update(&restart_chooser, &initial_adb_cmds, &mut profiler, &device, wait)?;
26 Ok(device)
27 }
28 #[test]
update_has_timeout_commands() -> Result<()>29 fn update_has_timeout_commands() -> Result<()> {
30 // Wait has two parts
31 // 1) The prep that clear sys.boot_completed.
32 let device = call_update_with_reboot(Wait::Yes)?;
33 assert!(
34 device.raw_cmds().iter().any(|c| c.contains("setprop sys.boot_completed")),
35 "Did not find setprop cmd, did find\n{:?}",
36 device.raw_cmds()
37 );
38 // 2) A call to device.wait() that calls "adb timeout ..."
39 // but the FakeDevice mocks this out.
40 assert_eq!(1, device.wait_calls());
41
42 Ok(())
43 }
44
45 #[test]
update_nowait_has_no_timeout_commands() -> Result<()>46 fn update_nowait_has_no_timeout_commands() -> Result<()> {
47 let device = call_update_with_reboot(Wait::No)?;
48 // Wait has two parts
49 // 1) The prep that clear sys.boot_completed.
50 assert_eq!(
51 0,
52 device.raw_cmds().iter().filter(|c| c.contains("setprop sys.boot_completed")).count(),
53 "Found timeout cmd, did not expect to\nn{:?}",
54 device.raw_cmds()
55 );
56 // 2) A call to device.wait() that calls "adb timeout ..."
57 // but the FakeDevice mocks this out.
58 assert_eq!(0, device.wait_calls());
59
60 Ok(())
61 }
62