1use xso::{AsXml, FromXml};
8
9use jid::Jid;
10
11use crate::iq::{IqGetPayload, IqResultPayload};
12use crate::ns;
13
14#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
16#[xml(namespace = ns::JID_PREP, name = "jid")]
17pub struct JidPrepQuery {
18 #[xml(text)]
20 pub data: String,
21}
22
23impl IqGetPayload for JidPrepQuery {}
24
25impl JidPrepQuery {
26 pub fn new<J: Into<String>>(jid: J) -> JidPrepQuery {
28 JidPrepQuery { data: jid.into() }
29 }
30}
31
32#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
34#[xml(namespace = ns::JID_PREP, name = "jid")]
35pub struct JidPrepResponse {
36 #[xml(text)]
38 pub jid: Jid,
39}
40
41impl IqResultPayload for JidPrepResponse {}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46 use jid::FullJid;
47 use minidom::Element;
48
49 #[cfg(target_pointer_width = "32")]
50 #[test]
51 fn test_size() {
52 assert_size!(JidPrepQuery, 12);
53 assert_size!(JidPrepResponse, 16);
54 }
55
56 #[cfg(target_pointer_width = "64")]
57 #[test]
58 fn test_size() {
59 assert_size!(JidPrepQuery, 24);
60 assert_size!(JidPrepResponse, 32);
61 }
62
63 #[test]
64 fn simple() {
65 let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>ROMeo@montague.lit/orchard</jid>"
66 .parse()
67 .unwrap();
68 let query = JidPrepQuery::try_from(elem).unwrap();
69 assert_eq!(query.data, "ROMeo@montague.lit/orchard");
70
71 let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>romeo@montague.lit/orchard</jid>"
72 .parse()
73 .unwrap();
74 let response = JidPrepResponse::try_from(elem).unwrap();
75 assert_eq!(
76 response.jid,
77 FullJid::new("romeo@montague.lit/orchard").unwrap()
78 );
79 }
80}