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