xmpp_parsers/
jingle_thumbnails.rs1use xso::{AsXml, FromXml};
10
11use crate::ns;
12use core::num::NonZeroU16;
13
14#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
16#[xml(namespace = ns::JINGLE_THUMBNAILS, name = "thumbnail")]
17pub struct Thumbnail {
18 #[xml(attribute)]
20 pub uri: String,
21
22 #[xml(attribute(default, name = "media-type"))]
24 pub media_type: Option<String>,
25
26 #[xml(attribute(default))]
28 pub width: Option<NonZeroU16>,
29
30 #[xml(attribute(default))]
32 pub height: Option<NonZeroU16>,
33}
34
35#[cfg(test)]
36mod tests {
37 use crate::jingle_thumbnails::Thumbnail;
38 use core::num::NonZeroU16;
39 use minidom::Element;
40
41 #[cfg(target_pointer_width = "32")]
42 #[test]
43 fn test_size() {
44 assert_size!(Thumbnail, 28);
45 }
46
47 #[cfg(target_pointer_width = "64")]
48 #[test]
49 fn test_size() {
50 assert_size!(Thumbnail, 56);
51 }
52
53 #[test]
54 fn test_simple_parse() {
55 let test_xml = "<thumbnail xmlns='urn:xmpp:thumbs:1'
57 uri='cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org'
58 media-type='image/png'
59 width='128'
60 height='96'/>";
61
62 let elem: Element = test_xml.parse().unwrap();
63
64 let thumbnail = Thumbnail::try_from(elem).unwrap();
65
66 assert_eq!(
67 thumbnail.uri,
68 "cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org"
69 );
70 assert_eq!(thumbnail.media_type.unwrap(), "image/png");
71 assert_eq!(thumbnail.width, NonZeroU16::new(128));
72 assert_eq!(thumbnail.height, NonZeroU16::new(96));
73 }
74}