use xso::{AsXml, FromXml};
use crate::iq::{IqGetPayload, IqResultPayload};
use crate::ns;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::VERSION, name = "query")]
pub struct VersionQuery;
impl IqGetPayload for VersionQuery {}
generate_element!(
VersionResult, "query", VERSION,
children: [
name: Required<String> = ("name", VERSION) => String,
version: Required<String> = ("version", VERSION) => String,
os: Option<String> = ("os", VERSION) => String
]
);
impl IqResultPayload for VersionResult {}
#[cfg(test)]
mod tests {
use super::*;
use crate::Element;
#[cfg(target_pointer_width = "32")]
#[test]
fn test_size() {
assert_size!(VersionQuery, 0);
assert_size!(VersionResult, 36);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_size() {
assert_size!(VersionQuery, 0);
assert_size!(VersionResult, 72);
}
#[test]
fn simple() {
let elem: Element =
"<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>"
.parse()
.unwrap();
let version = VersionResult::try_from(elem).unwrap();
assert_eq!(version.name, String::from("xmpp-rs"));
assert_eq!(version.version, String::from("0.3.0"));
assert_eq!(version.os, None);
}
#[test]
fn serialisation() {
let version = VersionResult {
name: String::from("xmpp-rs"),
version: String::from("0.3.0"),
os: None,
};
let elem1 = Element::from(version);
let elem2: Element =
"<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>"
.parse()
.unwrap();
println!("{:?}", elem1);
assert_eq!(elem1, elem2);
}
}