1// Copyright (c) 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7use crate::iq::{IqGetPayload, IqResultPayload};
8use crate::util::helpers::{PlainText, JidCodec};
9use jid::Jid;
10
11generate_element!(
12 /// TODO
13 JidPrepQuery, "jid", JID_PREP,
14 text: (
15 /// TODO
16 data: PlainText<Option<String>>
17 )
18);
19
20impl IqGetPayload for JidPrepQuery {}
21
22generate_element!(
23 /// TODO
24 JidPrepResponse, "jid", JID_PREP,
25 text: (
26 /// TODO
27 jid: JidCodec<Jid>
28 )
29);
30
31impl IqResultPayload for JidPrepResponse {}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36 use minidom::Element;
37 use std::convert::TryFrom;
38 use std::str::FromStr;
39
40 #[test]
41 fn test_size() {
42 assert_size!(JidPrepQuery, 24);
43 assert_size!(JidPrepResponse, 80);
44 }
45
46 #[test]
47 fn simple() {
48 let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>ROMeo@montague.lit/orchard</jid>".parse().unwrap();
49 let query = JidPrepQuery::try_from(elem).unwrap();
50 assert_eq!(query.data.unwrap(), "ROMeo@montague.lit/orchard");
51
52 let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>romeo@montague.lit/orchard</jid>".parse().unwrap();
53 let response = JidPrepResponse::try_from(elem).unwrap();
54 assert_eq!(response.jid, Jid::from_str("romeo@montague.lit/orchard").unwrap());
55 }
56}