xmpp_parsers/
attention.rs

1// Copyright (c) 2017 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6use xso::{AsXml, FromXml};
7
8use crate::message::MessagePayload;
9use crate::ns;
10
11/// Requests the attention of the recipient.
12#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
13#[xml(namespace = ns::ATTENTION, name = "attention")]
14pub struct Attention;
15
16impl MessagePayload for Attention {}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    #[cfg(not(feature = "disable-validation"))]
22    use xso::error::Error;
23
24    #[test]
25    fn test_size() {
26        assert_size!(Attention, 0);
27    }
28
29    #[test]
30    fn test_simple() {
31        let xml = b"<attention xmlns='urn:xmpp:attention:0'/>";
32        let attention: Attention = xso::from_bytes(xml).unwrap();
33        assert_eq!(attention, Attention);
34    }
35
36    #[cfg(not(feature = "disable-validation"))]
37    #[test]
38    fn test_invalid_child() {
39        let xml = b"<attention xmlns='urn:xmpp:attention:0'><coucou/></attention>";
40        let error = xso::from_bytes::<Attention>(xml).unwrap_err();
41        let message = match error {
42            Error::Other(string) => string,
43            _ => panic!(),
44        };
45        assert_eq!(message, "Unknown child in Attention element.");
46    }
47
48    #[cfg(not(feature = "disable-validation"))]
49    #[test]
50    fn test_invalid_attribute() {
51        let xml = b"<attention xmlns='urn:xmpp:attention:0' coucou=''/>";
52        let error = xso::from_bytes::<Attention>(xml).unwrap_err();
53        let message = match error {
54            Error::Other(string) => string,
55            _ => panic!(),
56        };
57        assert_eq!(message, "Unknown attribute in Attention element.");
58    }
59
60    #[test]
61    fn test_serialise() {
62        let serialized = xso::to_vec(&Attention).unwrap();
63        // TODO: Figure out how to make xso serialize to a self-closing tag.
64        let xml = b"<attention xmlns='urn:xmpp:attention:0'></attention>";
65        assert_eq!(serialized, xml);
66    }
67}