mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-13 01:41:59 -04:00
wifi: Add enum round-trip tests
This commit is contained in:
parent
b7b09e6c17
commit
89a757b7fc
2 changed files with 73 additions and 3 deletions
44
src/wifi.rs
44
src/wifi.rs
|
@ -67,7 +67,7 @@ impl TryFrom<u32> for WifiDebugMode {
|
|||
impl FromStr for WifiDebugMode {
|
||||
type Err = Error;
|
||||
fn from_str(input: &str) -> Result<WifiDebugMode, Self::Err> {
|
||||
Ok(match input {
|
||||
Ok(match input.to_lowercase().as_str() {
|
||||
"enable" | "enabled" | "on" | "1" => WifiDebugMode::On,
|
||||
"disable" | "disabled" | "off" | "0" => WifiDebugMode::Off,
|
||||
v => bail!("No enum match for value {v}"),
|
||||
|
@ -98,7 +98,7 @@ impl TryFrom<u32> for WifiPowerManagement {
|
|||
impl FromStr for WifiPowerManagement {
|
||||
type Err = Error;
|
||||
fn from_str(input: &str) -> Result<WifiPowerManagement, Self::Err> {
|
||||
Ok(match input {
|
||||
Ok(match input.to_lowercase().as_str() {
|
||||
"enable" | "enabled" | "on" | "1" => WifiPowerManagement::Enabled,
|
||||
"disable" | "disabled" | "off" | "0" => WifiPowerManagement::Disabled,
|
||||
v => bail!("No enum match for value {v}"),
|
||||
|
@ -292,7 +292,7 @@ pub(crate) async fn set_wifi_power_management_state(state: WifiPowerManagement)
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::testing;
|
||||
use crate::{enum_on_off, enum_roundtrip, testing};
|
||||
use tokio::fs::{create_dir_all, read_to_string, remove_dir, try_exists, write};
|
||||
|
||||
#[test]
|
||||
|
@ -379,4 +379,42 @@ mod test {
|
|||
WifiBackend::WPASupplicant
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wifi_debug_mode_roundtrip() {
|
||||
enum_roundtrip!(WifiDebugMode {
|
||||
0: u32 = Off,
|
||||
1: u32 = On,
|
||||
"Off": str = Off,
|
||||
"On": str = On,
|
||||
});
|
||||
enum_on_off!(WifiDebugMode => (On, Off));
|
||||
assert!(WifiDebugMode::try_from(2).is_err());
|
||||
assert!(WifiDebugMode::from_str("onf").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wifi_power_management_roundtrip() {
|
||||
enum_roundtrip!(WifiPowerManagement {
|
||||
0: u32 = Disabled,
|
||||
1: u32 = Enabled,
|
||||
"Disabled": str = Disabled,
|
||||
"Enabled": str = Enabled,
|
||||
});
|
||||
enum_on_off!(WifiPowerManagement => (Enabled, Disabled));
|
||||
assert!(WifiPowerManagement::try_from(2).is_err());
|
||||
assert!(WifiPowerManagement::from_str("onf").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wifi_backend_roundtrip() {
|
||||
enum_roundtrip!(WifiBackend {
|
||||
0: u32 = Iwd,
|
||||
1: u32 = WPASupplicant,
|
||||
"iwd": str = Iwd,
|
||||
"wpa_supplicant": str = WPASupplicant,
|
||||
});
|
||||
assert!(WifiBackend::try_from(2).is_err());
|
||||
assert!(WifiBackend::from_str("iwl").is_err());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue