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