use xso::{AsXml, FromXml};
use crate::jingle::ContentId;
use crate::ns;
generate_attribute!(
Semantics, "semantics", {
Ls => "LS",
Bundle => "BUNDLE",
}
);
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::JINGLE_GROUPING, name = "content")]
pub struct Content {
#[xml(attribute)]
pub name: ContentId,
}
impl Content {
pub fn new(name: &str) -> Content {
Content {
name: ContentId(name.to_string()),
}
}
}
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
#[xml(namespace = ns::JINGLE_GROUPING, name = "group")]
pub struct Group {
#[xml(attribute)]
pub semantics: Semantics,
#[xml(child(n = ..))]
pub contents: Vec<Content>,
}
#[cfg(test)]
mod tests {
use super::*;
use minidom::Element;
#[cfg(target_pointer_width = "32")]
#[test]
fn test_size() {
assert_size!(Semantics, 1);
assert_size!(Content, 12);
assert_size!(Group, 16);
}
#[cfg(target_pointer_width = "64")]
#[test]
fn test_size() {
assert_size!(Semantics, 1);
assert_size!(Content, 24);
assert_size!(Group, 32);
}
#[test]
fn parse_group() {
let elem: Element = "<group xmlns='urn:xmpp:jingle:apps:grouping:0' semantics='BUNDLE'>
<content name='voice'/>
<content name='webcam'/>
</group>"
.parse()
.unwrap();
let group = Group::try_from(elem).unwrap();
assert_eq!(group.semantics, Semantics::Bundle);
assert_eq!(group.contents.len(), 2);
assert_eq!(
group.contents,
&[Content::new("voice"), Content::new("webcam")]
);
}
}