use xso::{AsXml, FromXml};
use crate::ns;
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::JINGLE_THUMBNAILS, name = "thumbnail")]
pub struct Thumbnail {
#[xml(attribute)]
pub uri: String,
#[xml(attribute = "media-type")]
pub media_type: String,
#[xml(attribute)]
pub width: u32,
#[xml(attribute)]
pub height: u32,
}
#[cfg(test)]
mod tests {
use crate::jingle_thumbnails::Thumbnail;
use minidom::Element;
#[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, "image/png");
assert_eq!(thumbnail.width, 128);
assert_eq!(thumbnail.height, 96);
}
}