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