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_invalid() {
30 let elem: Element = "<ping xmlns='urn:xmpp:ping'><coucou/></ping>".parse().unwrap();
31 let error = Ping::try_from(elem).unwrap_err();
32 let message = match error {
33 Error::ParseError(string) => string,
34 _ => panic!(),
35 };
36 assert_eq!(message, "Unknown child in ping element.");
37 }
38
39 #[test]
40 fn test_invalid_attribute() {
41 let elem: Element = "<ping xmlns='urn:xmpp:ping' coucou=''/>".parse().unwrap();
42 let error = Ping::try_from(elem).unwrap_err();
43 let message = match error {
44 Error::ParseError(string) => string,
45 _ => panic!(),
46 };
47 assert_eq!(message, "Unknown attribute in ping element.");
48 }
49}