gstreamer_rtsp_server/
flag_serde.rs
1use glib::{
4 prelude::*,
5 translate::{from_glib, ToGlibPtr},
6 FlagsClass,
7};
8use gst::bitflags_serde_impl;
9
10bitflags_serde_impl!(crate::RTSPTransportMode);
11
12#[cfg(test)]
13mod tests {
14 macro_rules! check_serialize {
15 ($flags:expr, $expected:expr) => {
16 let actual = serde_json::to_string(&$flags).unwrap();
17 assert_eq!(actual, $expected);
18 };
19 }
20
21 macro_rules! check_deserialize {
22 ($ty:ty, $expected:expr, $json:expr) => {
23 let actual: $ty = serde_json::from_str(&$json).unwrap();
24 assert_eq!(actual, $expected);
25 };
26 }
27
28 macro_rules! check_roundtrip {
29 ($ty:ty, $flags:expr) => {
30 let json = serde_json::to_string(&$flags).unwrap();
31 let deserialized: $ty = serde_json::from_str(&json).unwrap();
32 assert_eq!(deserialized, $flags);
33 };
34 }
35
36 #[test]
37 fn test_serialize() {
38 gst::init().unwrap();
39
40 check_serialize!(crate::RTSPTransportMode::all(), "\"play+record\"");
41 }
42
43 #[test]
44 fn test_deserialize() {
45 gst::init().unwrap();
46
47 check_deserialize!(
48 crate::RTSPTransportMode,
49 crate::RTSPTransportMode::all(),
50 "\"play+record\""
51 );
52 }
53
54 #[test]
55 fn test_serde_roundtrip() {
56 gst::init().unwrap();
57
58 check_roundtrip!(crate::RTSPTransportMode, crate::RTSPTransportMode::all());
59 }
60}