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 message::MessagePayload;
8
9generate_empty_element!(
10 /// Requests the attention of the recipient.
11 Attention, "attention", ATTENTION
12);
13
14impl MessagePayload for Attention {}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19 use try_from::TryFrom;
20 use minidom::Element;
21 use error::Error;
22
23 #[test]
24 fn test_size() {
25 assert_size!(Attention, 0);
26 }
27
28 #[test]
29 fn test_simple() {
30 let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
31 Attention::try_from(elem).unwrap();
32 }
33
34 #[test]
35 fn test_invalid_child() {
36 let elem: Element = "<attention xmlns='urn:xmpp:attention:0'><coucou/></attention>".parse().unwrap();
37 let error = Attention::try_from(elem).unwrap_err();
38 let message = match error {
39 Error::ParseError(string) => string,
40 _ => panic!(),
41 };
42 assert_eq!(message, "Unknown child in attention element.");
43 }
44
45 #[test]
46 fn test_invalid_attribute() {
47 let elem: Element = "<attention xmlns='urn:xmpp:attention:0' coucou=''/>".parse().unwrap();
48 let error = Attention::try_from(elem).unwrap_err();
49 let message = match error {
50 Error::ParseError(string) => string,
51 _ => panic!(),
52 };
53 assert_eq!(message, "Unknown attribute in attention element.");
54 }
55
56 #[test]
57 fn test_serialise() {
58 let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
59 let attention = Attention;
60 let elem2: Element = attention.into();
61 assert_eq!(elem, elem2);
62 }
63}