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_simple() {
35 let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'/>".parse().unwrap();
36 Forwarded::try_from(elem).unwrap();
37 }
38
39 #[test]
40 fn test_invalid_child() {
41 let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'><coucou/></forwarded>".parse().unwrap();
42 let error = Forwarded::try_from(elem).unwrap_err();
43 let message = match error {
44 Error::ParseError(string) => string,
45 _ => panic!(),
46 };
47 assert_eq!(message, "Unknown child in forwarded element.");
48 }
49
50 #[test]
51 fn test_serialise() {
52 let elem: Element = "<forwarded xmlns='urn:xmpp:forward:0'/>".parse().unwrap();
53 let forwarded = Forwarded { delay: None, stanza: None };
54 let elem2 = forwarded.into();
55 assert_eq!(elem, elem2);
56 }
57}