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
8#![deny(missing_docs)]
9
10use iq::IqGetPayload;
11
12generate_empty_element!(
13 /// Represents a ping to the recipient, which must be answered with an
14 /// empty `<iq/>` or with an error.
15 Ping, "ping", PING
16);
17
18impl IqGetPayload for Ping {}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use try_from::TryFrom;
24 use minidom::Element;
25 use error::Error;
26
27 #[test]
28 fn test_simple() {
29 let elem: Element = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
30 Ping::try_from(elem).unwrap();
31 }
32
33 #[test]
34 fn test_serialise() {
35 let elem1 = Element::from(Ping);
36 let elem2: Element = "<ping xmlns='urn:xmpp:ping'/>".parse().unwrap();
37 assert_eq!(elem1, elem2);
38 }
39
40 #[test]
41 fn test_invalid() {
42 let elem: Element = "<ping xmlns='urn:xmpp:ping'><coucou/></ping>".parse().unwrap();
43 let error = Ping::try_from(elem).unwrap_err();
44 let message = match error {
45 Error::ParseError(string) => string,
46 _ => panic!(),
47 };
48 assert_eq!(message, "Unknown child in ping element.");
49 }
50
51 #[test]
52 fn test_invalid_attribute() {
53 let elem: Element = "<ping xmlns='urn:xmpp:ping' coucou=''/>".parse().unwrap();
54 let error = Ping::try_from(elem).unwrap_err();
55 let message = match error {
56 Error::ParseError(string) => string,
57 _ => panic!(),
58 };
59 assert_eq!(message, "Unknown attribute in ping element.");
60 }
61}