1 use super::*;
2 use bytes::Bytes;
3 
4 #[test]
test_rapid_resynchronization_request_unmarshal()5 fn test_rapid_resynchronization_request_unmarshal() {
6     let tests = vec![
7         (
8             "valid",
9             Bytes::from_static(&[
10                 0x85, 0xcd, 0x0, 0x2, // RapidResynchronizationRequest
11                 0x90, 0x2f, 0x9e, 0x2e, // sender=0x902f9e2e
12                 0x90, 0x2f, 0x9e, 0x2e, // media=0x902f9e2e
13             ]),
14             RapidResynchronizationRequest {
15                 sender_ssrc: 0x902f9e2e,
16                 media_ssrc: 0x902f9e2e,
17             },
18             None,
19         ),
20         (
21             "short report",
22             Bytes::from_static(&[
23                 0x85, 0xcd, 0x0, 0x2, // ssrc=0x902f9e2e
24                 0x90, 0x2f, 0x9e, 0x2e,
25                 // report ends early
26             ]),
27             RapidResynchronizationRequest::default(),
28             Some(Error::PacketTooShort),
29         ),
30         (
31             "wrong type",
32             Bytes::from_static(&[
33                 0x81, 0xc8, 0x0, 0x7, // v=2, p=0, count=1, SR, len=7
34                 0x90, 0x2f, 0x9e, 0x2e, // ssrc=0x902f9e2e
35                 0xbc, 0x5e, 0x9a, 0x40, // ssrc=0xbc5e9a40
36                 0x0, 0x0, 0x0, 0x0, // fracLost=0, totalLost=0
37                 0x0, 0x0, 0x46, 0xe1, // lastSeq=0x46e1
38                 0x0, 0x0, 0x1, 0x11, // jitter=273
39                 0x9, 0xf3, 0x64, 0x32, // lsr=0x9f36432
40                 0x0, 0x2, 0x4a, 0x79, // delay=150137
41             ]),
42             RapidResynchronizationRequest::default(),
43             Some(Error::WrongType),
44         ),
45         (
46             "nil",
47             Bytes::from_static(&[]),
48             RapidResynchronizationRequest::default(),
49             Some(Error::PacketTooShort),
50         ),
51     ];
52 
53     for (name, mut data, want, want_error) in tests {
54         let got = RapidResynchronizationRequest::unmarshal(&mut data);
55 
56         assert_eq!(
57             got.is_err(),
58             want_error.is_some(),
59             "Unmarshal {name} rr: err = {got:?}, want {want_error:?}"
60         );
61 
62         if let Some(err) = want_error {
63             let got_err = got.err().unwrap();
64             assert_eq!(
65                 err, got_err,
66                 "Unmarshal {name} rr: err = {got_err:?}, want {err:?}",
67             );
68         } else {
69             let actual = got.unwrap();
70             assert_eq!(
71                 actual, want,
72                 "Unmarshal {name} rr: got {actual:?}, want {want:?}"
73             );
74         }
75     }
76 }
77 
78 #[test]
test_rapid_resynchronization_request_roundtrip()79 fn test_rapid_resynchronization_request_roundtrip() {
80     let tests: Vec<(&str, RapidResynchronizationRequest, Option<Error>)> = vec![(
81         "valid",
82         RapidResynchronizationRequest {
83             sender_ssrc: 0x902f9e2e,
84             media_ssrc: 0x902f9e2e,
85         },
86         None,
87     )];
88 
89     for (name, want, want_error) in tests {
90         let got = want.marshal();
91 
92         assert_eq!(
93             got.is_ok(),
94             want_error.is_none(),
95             "Marshal {name}: err = {got:?}, want {want_error:?}"
96         );
97 
98         if let Some(err) = want_error {
99             let got_err = got.err().unwrap();
100             assert_eq!(
101                 err, got_err,
102                 "Unmarshal {name} rr: err = {got_err:?}, want {err:?}",
103             );
104         } else {
105             let mut data = got.ok().unwrap();
106             let actual = RapidResynchronizationRequest::unmarshal(&mut data)
107                 .unwrap_or_else(|_| panic!("Unmarshal {name}"));
108 
109             assert_eq!(
110                 actual, want,
111                 "{name} round trip: got {actual:?}, want {want:?}"
112             )
113         }
114     }
115 }
116