1// Copyright (c) 2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
67use xso::{AsXml, FromXml};
89use crate::jingle::ContentId;
10use crate::ns;
1112generate_attribute!(
13/// The semantics of the grouping.
14Semantics, "semantics", {
15/// Lip synchronsation.
16Ls => "LS",
1718/// Bundle.
19Bundle => "BUNDLE",
20 }
21);
2223/// Describes a content that should be grouped with other ones.
24#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
25#[xml(namespace = ns::JINGLE_GROUPING, name = "content")]
26pub struct Content {
27/// The name of the matching [`Content`](crate::jingle::Content).
28#[xml(attribute)]
29pub name: ContentId,
30}
3132impl Content {
33/// Creates a new \<content/\> element.
34pub fn new(name: &str) -> Content {
35 Content {
36 name: ContentId(name.to_string()),
37 }
38 }
39}
4041/// A semantic group of contents.
42#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
43#[xml(namespace = ns::JINGLE_GROUPING, name = "group")]
44pub struct Group {
45/// Semantics of the grouping.
46#[xml(attribute)]
47pub semantics: Semantics,
4849/// List of contents that should be grouped with each other.
50#[xml(child(n = ..))]
51pub contents: Vec<Content>,
52}
5354#[cfg(test)]
55mod tests {
56use super::*;
57use minidom::Element;
5859#[cfg(target_pointer_width = "32")]
60 #[test]
61fn test_size() {
62assert_size!(Semantics, 1);
63assert_size!(Content, 12);
64assert_size!(Group, 16);
65 }
6667#[cfg(target_pointer_width = "64")]
68 #[test]
69fn test_size() {
70assert_size!(Semantics, 1);
71assert_size!(Content, 24);
72assert_size!(Group, 32);
73 }
7475#[test]
76fn parse_group() {
77let elem: Element = "<group xmlns='urn:xmpp:jingle:apps:grouping:0' semantics='BUNDLE'>
78 <content name='voice'/>
79 <content name='webcam'/>
80 </group>"
81.parse()
82 .unwrap();
83let group = Group::try_from(elem).unwrap();
84assert_eq!(group.semantics, Semantics::Bundle);
85assert_eq!(group.contents.len(), 2);
86assert_eq!(
87 group.contents,
88&[Content::new("voice"), Content::new("webcam")]
89 );
90 }
91}