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