1// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2// Copyright (c) 2017 Maxime “pep” Buquet <pep+code@bouah.net>
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8use try_from::TryFrom;
9
10use minidom::Element;
11
12use error::Error;
13
14use ns;
15
16generate_empty_element!(Ping, "ping", ns::PING);
17
18#[cfg(test)]
19mod tests {
20 use super::*;
21
22 #[test]
23 fn test_simple() {
24 let elem: Element = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
25 Ping::try_from(elem).unwrap();
26 }
27
28 #[test]
29 fn test_serialise() {
30 let elem1 = Element::from(Ping);
31 let elem2: Element = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
32 assert_eq!(elem1, elem2);
33 }
34
35 #[test]
36 fn test_invalid() {
37 let elem: Element = "<ping xmlns='urn:xmpp:ping'><coucou/></ping>".parse().unwrap();
38 let error = Ping::try_from(elem).unwrap_err();
39 let message = match error {
40 Error::ParseError(string) => string,
41 _ => panic!(),
42 };
43 assert_eq!(message, "Unknown child in ping element.");
44 }
45
46 #[test]
47 fn test_invalid_attribute() {
48 let elem: Element = "<ping xmlns='urn:xmpp:ping' coucou=''/>".parse().unwrap();
49 let error = Ping::try_from(elem).unwrap_err();
50 let message = match error {
51 Error::ParseError(string) => string,
52 _ => panic!(),
53 };
54 assert_eq!(message, "Unknown attribute in ping element.");
55 }
56}