///| A backend for tests: it serves whatever status and network list it is given and records the /// actions it receives (switching Wi-Fi off empties the list, as NetworkManager's would). pub(all) struct FakeNet { mut status : NetStatus mut networks : Array[WifiNetwork] actions : Array[NetAction] mut ticks : Int } ///| pub fn FakeNet::new(status : NetStatus, networks : Array[WifiNetwork]) -> FakeNet { { status, networks, actions: [], ticks: 0 } } ///| pub impl NetBackend for FakeNet with tick(self, _now) { self.ticks = self.ticks + 1 } ///| pub impl NetBackend for FakeNet with status(self) { self.status } ///| pub impl NetBackend for FakeNet with networks(self) { if self.status.wifi_enabled { self.networks } else { [] } } ///| pub impl NetBackend for FakeNet with act(self, a) { self.actions.push(a) match a { SetWifi(on) => self.status = { ..self.status, wifi_enabled: on } SetAirplane(on) => self.status = { ..self.status, airplane: on, wifi_enabled: !on } _ => () } } ///| pub impl NetBackend for FakeNet with alive(_self) { true }