use crate::iq::{IqGetPayload, IqResultPayload};
use crate::util::text_node_codecs::{Codec, JidCodec, Text};
generate_element!(
JidPrepQuery, "jid", JID_PREP,
text: (
data: Text
)
);
impl IqGetPayload for JidPrepQuery {}
impl JidPrepQuery {
pub fn new<J: Into<String>>(jid: J) -> JidPrepQuery {
JidPrepQuery { data: jid.into() }
}
}
generate_element!(
JidPrepResponse, "jid", JID_PREP,
text: (
jid: JidCodec
)
);
impl IqResultPayload for JidPrepResponse {}
#[cfg(test)]
mod tests {
use super::*;
use crate::Element;
use jid::FullJid;
#[cfg(target_pointer_width = "32")]
#[test]
fn test_size() {
assert_size!(JidPrepQuery, 12);
assert_size!(JidPrepResponse, 16);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_size() {
assert_size!(JidPrepQuery, 24);
assert_size!(JidPrepResponse, 32);
}
#[test]
fn simple() {
let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>ROMeo@montague.lit/orchard</jid>"
.parse()
.unwrap();
let query = JidPrepQuery::try_from(elem).unwrap();
assert_eq!(query.data, "ROMeo@montague.lit/orchard");
let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>romeo@montague.lit/orchard</jid>"
.parse()
.unwrap();
let response = JidPrepResponse::try_from(elem).unwrap();
assert_eq!(
response.jid,
FullJid::new("romeo@montague.lit/orchard").unwrap()
);
}
}