test_battery_manager/
lib.rsuse battery_client::BatteryClient;
use fidl::client::QueryResponseFut;
use fidl_fuchsia_power_battery as fpower;
use futures::StreamExt;
pub struct TestBatteryManager {
_stream: fpower::BatteryManagerRequestStream,
watcher_client: fpower::BatteryInfoWatcherProxy,
}
impl TestBatteryManager {
pub fn new(
s: fpower::BatteryManagerRequestStream,
watcher_client: fpower::BatteryInfoWatcherProxy,
) -> Self {
Self { _stream: s, watcher_client }
}
pub async fn make_battery_client_with_test_manager() -> (BatteryClient, TestBatteryManager) {
let (c, mut s) = fidl::endpoints::create_proxy_and_stream::<fpower::BatteryManagerMarker>();
let battery_client =
BatteryClient::register_updates(c).expect("can register battery client");
let watcher_client = match s.next().await.expect("valid fidl request") {
Ok(fpower::BatteryManagerRequest::Watch { watcher, .. }) => watcher.into_proxy(),
x => panic!("Expected watch request, got: {:?}", x),
};
let mgr = TestBatteryManager::new(s, watcher_client);
(battery_client, mgr)
}
pub fn send_update(&self, update: fpower::BatteryInfo) -> QueryResponseFut<()> {
let update_fut = self.watcher_client.on_change_battery_info(&update);
update_fut
}
}