1// Copyright (c) 2017 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 delay::Delay;
8use message::Message;
9
10generate_element!(
11 /// Contains a forwarded stanza, either standalone or part of another
12 /// extension (such as carbons).
13 Forwarded, "forwarded", FORWARD,
14 children: [
15 /// When the stanza originally got sent.
16 delay: Option<Delay> = ("delay", DELAY) => Delay,
17
18 // XXX: really? Option?
19 /// The stanza being forwarded.
20 stanza: Option<Message> = ("message", DEFAULT_NS) => Message
21
22 // TODO: also handle the two other stanza possibilities.
23 ]
24);
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29 use try_from::TryFrom;
30 use minidom::Element;
31 use error::Error;
32
33 #[test]
34 fn test_size() {
35 assert_size!(Forwarded, 392);
36 }
37
38 #[test]
39 fn test_simple() {
40 let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'/>".parse().unwrap();
41 Forwarded::try_from(elem).unwrap();
42 }
43
44 #[test]
45 fn test_invalid_child() {
46 let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><coucou/></forwarded>".parse().unwrap();
47 let error = Forwarded::try_from(elem).unwrap_err();
48 let message = match error {
49 Error::ParseError(string) => string,
50 _ => panic!(),
51 };
52 assert_eq!(message, "Unknown child in forwarded element.");
53 }
54
55 #[test]
56 fn test_serialise() {
57 let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'/>".parse().unwrap();
58 let forwarded = Forwarded { delay: None, stanza: None };
59 let elem2 = forwarded.into();
60 assert_eq!(elem, elem2);
61 }
62}