xmpp_parsers/
jingle_thumbnails.rsuse xso::{AsXml, FromXml};
use crate::ns;
use core::num::NonZeroU16;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::JINGLE_THUMBNAILS, name = "thumbnail")]
pub struct Thumbnail {
#[xml(attribute)]
pub uri: String,
#[xml(attribute(default, name = "media-type"))]
pub media_type: Option<String>,
#[xml(attribute(default))]
pub width: Option<NonZeroU16>,
#[xml(attribute(default))]
pub height: Option<NonZeroU16>,
}
#[cfg(test)]
mod tests {
use crate::jingle_thumbnails::Thumbnail;
use core::num::NonZeroU16;
use minidom::Element;
#[cfg(target_pointer_width = "32")]
#[test]
fn test_size() {
assert_size!(Thumbnail, 28);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_size() {
assert_size!(Thumbnail, 56);
}
#[test]
fn test_simple_parse() {
let test_xml = "<thumbnail xmlns='urn:xmpp:thumbs:1'
uri='cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org'
media-type='image/png'
width='128'
height='96'/>";
let elem: Element = test_xml.parse().unwrap();
let thumbnail = Thumbnail::try_from(elem).unwrap();
assert_eq!(
thumbnail.uri,
"cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org"
);
assert_eq!(thumbnail.media_type.unwrap(), "image/png");
assert_eq!(thumbnail.width, NonZeroU16::new(128));
assert_eq!(thumbnail.height, NonZeroU16::new(96));
}
}