1use xso::{AsXml, FromXml};
8
9use crate::iq::{IqGetPayload, IqResultPayload};
10use crate::ns;
11
12#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
17#[xml(namespace = ns::VERSION, name = "query")]
18pub struct VersionQuery;
19
20impl IqGetPayload for VersionQuery {}
21
22#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
27#[xml(namespace = ns::VERSION, name = "query")]
28pub struct VersionResult {
29 #[xml(extract(fields(text)))]
31 pub name: String,
32
33 #[xml(extract(fields(text)))]
35 pub version: String,
36
37 #[xml(extract(default, fields(text(type_ = String))))]
39 pub os: Option<String>,
40}
41
42impl IqResultPayload for VersionResult {}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47 use minidom::Element;
48
49 #[cfg(target_pointer_width = "32")]
50 #[test]
51 fn test_size() {
52 assert_size!(VersionQuery, 0);
53 assert_size!(VersionResult, 36);
54 }
55
56 #[cfg(target_pointer_width = "64")]
57 #[test]
58 fn test_size() {
59 assert_size!(VersionQuery, 0);
60 assert_size!(VersionResult, 72);
61 }
62
63 #[test]
64 fn simple() {
65 let elem: Element =
66 "<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>"
67 .parse()
68 .unwrap();
69 let version = VersionResult::try_from(elem).unwrap();
70 assert_eq!(version.name, String::from("xmpp-rs"));
71 assert_eq!(version.version, String::from("0.3.0"));
72 assert_eq!(version.os, None);
73 }
74
75 #[test]
76 fn serialisation() {
77 let version = VersionResult {
78 name: String::from("xmpp-rs"),
79 version: String::from("0.3.0"),
80 os: None,
81 };
82 let elem1 = Element::from(version);
83 let elem2: Element =
84 "<query xmlns='jabber:iq:version'><name>xmpp-rs</name><version>0.3.0</version></query>"
85 .parse()
86 .unwrap();
87 println!("{:?}", elem1);
88 assert_eq!(elem1, elem2);
89 }
90}