xmpp_parsers/
attention.rs1use xso::{AsXml, FromXml};
7
8use crate::message::MessagePayload;
9use crate::ns;
10
11#[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 let xml = b"<attention xmlns='urn:xmpp:attention:0'></attention>";
65 assert_eq!(serialized, xml);
66 }
67}