fix macro_role: serde_field_string, add config tests
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
cb59825b8a
commit
8c0fa989b6
@ -105,12 +105,9 @@ macro_rules! serde_field_string {
|
|||||||
where
|
where
|
||||||
D: de::Deserializer<'de>,
|
D: de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let s: &str = de::Deserialize::deserialize(deserializer).unwrap_or_default();
|
let s: String =
|
||||||
Ok(if s.is_empty() {
|
de::Deserialize::deserialize(deserializer).unwrap_or(Self::$default_func());
|
||||||
Self::$default_func()
|
Ok(s)
|
||||||
} else {
|
|
||||||
s.to_owned()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -252,7 +249,11 @@ pub struct PeerConfig {
|
|||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub view_only: ViewOnly,
|
pub view_only: ViewOnly,
|
||||||
|
|
||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
deserialize_with = "deserialize_option_resolution"
|
||||||
|
)]
|
||||||
pub custom_resolution: Option<Resolution>,
|
pub custom_resolution: Option<Resolution>,
|
||||||
|
|
||||||
// The other scalar value must before this
|
// The other scalar value must before this
|
||||||
@ -1495,6 +1496,7 @@ deserialize_default!(deserialize_option_string, Option<String>);
|
|||||||
deserialize_default!(deserialize_hashmap_string_string, HashMap<String, String>);
|
deserialize_default!(deserialize_hashmap_string_string, HashMap<String, String>);
|
||||||
deserialize_default!(deserialize_hashmap_string_bool, HashMap<String, bool>);
|
deserialize_default!(deserialize_hashmap_string_bool, HashMap<String, bool>);
|
||||||
deserialize_default!(deserialize_hashmap_string_configoidcprovider, HashMap<String, ConfigOidcProvider>);
|
deserialize_default!(deserialize_hashmap_string_configoidcprovider, HashMap<String, ConfigOidcProvider>);
|
||||||
|
deserialize_default!(deserialize_option_resolution, Option<Resolution>);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
@ -1543,4 +1545,34 @@ mod tests {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_peer_config_deserialize() {
|
||||||
|
let default_peer_config = toml::from_str::<PeerConfig>("").unwrap();
|
||||||
|
// test custom_resolution
|
||||||
|
{
|
||||||
|
let wrong_type_str = r#"
|
||||||
|
view_style = "adaptive"
|
||||||
|
scroll_style = "scrollbar"
|
||||||
|
custom_resolution = true
|
||||||
|
"#;
|
||||||
|
let mut compare_config = default_peer_config.clone();
|
||||||
|
compare_config.view_style = "adaptive".to_string();
|
||||||
|
compare_config.scroll_style = "scrollbar".to_string();
|
||||||
|
let cfg = toml::from_str::<PeerConfig>(wrong_type_str);
|
||||||
|
assert_eq!(cfg, Ok(compare_config), "Failed to test wrong_type_str");
|
||||||
|
|
||||||
|
let wrong_field_str = r#"
|
||||||
|
[custom_resolution]
|
||||||
|
w = 1920
|
||||||
|
h = 1080
|
||||||
|
hello = "world"
|
||||||
|
[ui_flutter]
|
||||||
|
"#;
|
||||||
|
let mut compare_config = default_peer_config.clone();
|
||||||
|
compare_config.custom_resolution = Some(Resolution { w: 1920, h: 1080 });
|
||||||
|
let cfg = toml::from_str::<PeerConfig>(wrong_field_str);
|
||||||
|
assert_eq!(cfg, Ok(compare_config), "Failed to test wrong_field_str");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user