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