mirror of
https://github.com/arampoire/nut-rs.git
synced 2025-11-30 16:20:25 -05:00
Implement decode tests for serverbound
This commit is contained in:
parent
e937899f8a
commit
779d279681
1 changed files with 152 additions and 7 deletions
|
|
@ -191,6 +191,18 @@ macro_rules! impl_sentences {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
macro_rules! test_decode {
|
||||||
|
([$($word:expr$(,)?)+] => $expected:expr) => {
|
||||||
|
assert_eq!(
|
||||||
|
Sentences::decode(vec![
|
||||||
|
$($word.into(),)*
|
||||||
|
]),
|
||||||
|
$expected
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Messages decoded by the server.
|
/// Messages decoded by the server.
|
||||||
pub mod server_bound {
|
pub mod server_bound {
|
||||||
impl_sentences! {
|
impl_sentences! {
|
||||||
|
|
@ -362,8 +374,8 @@ pub mod server_bound {
|
||||||
{
|
{
|
||||||
0: List,
|
0: List,
|
||||||
1: Client,
|
1: Client,
|
||||||
3: Arg,
|
2: Arg,
|
||||||
4: EOL,
|
3: EOL,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
/// The name of the UPS device.
|
/// The name of the UPS device.
|
||||||
|
|
@ -511,16 +523,149 @@ pub mod server_bound {
|
||||||
use super::*;
|
use super::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_decode() {
|
fn test_decode() {
|
||||||
assert_eq!(
|
test_decode!(
|
||||||
Sentences::decode(vec!["VERSION".into()]),
|
["GET", "NUMLOGINS", "nutdev"] =>
|
||||||
Some(Sentences::QueryVersion {})
|
Some(Sentences::QueryNumLogins {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(
|
test_decode!(
|
||||||
Sentences::decode(vec!["LIST".into(), "VAR".into(), "nutdev".into()]),
|
["GET", "UPSDESC", "nutdev"] =>
|
||||||
|
Some(Sentences::QueryUpsDesc {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["GET", "VAR", "nutdev", "test.var"] =>
|
||||||
|
Some(Sentences::QueryVar {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
var_name: "test.var".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["GET", "TYPE", "nutdev", "test.var"] =>
|
||||||
|
Some(Sentences::QueryType {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
var_name: "test.var".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["GET", "DESC", "nutdev", "test.var"] =>
|
||||||
|
Some(Sentences::QueryDesc {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
var_name: "test.var".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["GET", "CMDDESC", "nutdev", "test.cmd"] =>
|
||||||
|
Some(Sentences::QueryCmdDesc {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
cmd_name: "test.cmd".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LIST", "VAR", "nutdev"] =>
|
||||||
Some(Sentences::QueryListVar {
|
Some(Sentences::QueryListVar {
|
||||||
ups_name: "nutdev".into(),
|
ups_name: "nutdev".into(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LIST", "RW", "nutdev"] =>
|
||||||
|
Some(Sentences::QueryListRw {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LIST", "CMD", "nutdev"] =>
|
||||||
|
Some(Sentences::QueryListCmd {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LIST", "ENUM", "nutdev", "test.var"] =>
|
||||||
|
Some(Sentences::QueryListEnum {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
var_name: "test.var".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LIST", "RANGE", "nutdev", "test.var"] =>
|
||||||
|
Some(Sentences::QueryListRange {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
var_name: "test.var".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LIST", "CLIENT", "nutdev"] =>
|
||||||
|
Some(Sentences::QueryListClient {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["SET", "VAR", "nutdev", "test.var", "something"] =>
|
||||||
|
Some(Sentences::ExecSetVar {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
var_name: "test.var".into(),
|
||||||
|
value: "something".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["INSTCMD", "nutdev", "test.cmd"] =>
|
||||||
|
Some(Sentences::ExecInstCmd {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
cmd_name: "test.cmd".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LOGOUT"] =>
|
||||||
|
Some(Sentences::ExecLogout {})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["LOGIN", "nutdev"] =>
|
||||||
|
Some(Sentences::ExecLogin {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["MASTER", "nutdev"] =>
|
||||||
|
Some(Sentences::ExecMaster {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["FSD", "nutdev"] =>
|
||||||
|
Some(Sentences::ExecForcedShutDown {
|
||||||
|
ups_name: "nutdev".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["PASSWORD", "topsecret"] =>
|
||||||
|
Some(Sentences::SetPassword {
|
||||||
|
password: "topsecret".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["USERNAME", "john"] =>
|
||||||
|
Some(Sentences::SetUsername {
|
||||||
|
username: "john".into(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["STARTTLS"] =>
|
||||||
|
Some(Sentences::ExecStartTLS {})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["HELP"] =>
|
||||||
|
Some(Sentences::QueryHelp {})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["VERSION"] =>
|
||||||
|
Some(Sentences::QueryVersion {})
|
||||||
|
);
|
||||||
|
test_decode!(
|
||||||
|
["NETVER"] =>
|
||||||
|
Some(Sentences::QueryNetworkVersion {})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue