easyofd_core/action/
movie.rs1use super::{OfdAction, PlayType};
6
7#[derive(Debug, Clone)]
13pub struct Movie {
14 pub media_ref: String,
18
19 pub play_type: PlayType,
23}
24
25impl Movie {
26 #[must_use]
30 pub fn new(media_ref: impl Into<String>, play_type: PlayType) -> Self {
31 Self {
32 media_ref: media_ref.into(),
33 play_type,
34 }
35 }
36}
37
38impl OfdAction for Movie {
39 fn to_xml_string(&self) -> String {
40 format!(
41 "<ofd:Movie MediaRef=\"{}\" Type=\"{}\"/>",
42 self.media_ref, self.play_type
43 )
44 }
45
46 fn clone_box(&self) -> Box<dyn OfdAction> {
47 Box::new(self.clone())
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_movie_new() {
57 let movie = Movie::new("video_001", PlayType::Play);
58 assert_eq!(movie.media_ref, "video_001");
59 assert_eq!(movie.play_type, PlayType::Play);
60 }
61
62 #[test]
63 fn test_movie_to_xml_play() {
64 let movie = Movie::new("vid_1", PlayType::Play);
65 let xml = movie.to_xml_string();
66 assert!(xml.contains("MediaRef=\"vid_1\""));
67 assert!(xml.contains("Type=\"Play\""));
68 assert!(xml.contains("<ofd:Movie"));
69 assert!(xml.ends_with("/>"));
70 }
71
72 #[test]
73 fn test_movie_to_xml_stop() {
74 let movie = Movie::new("vid_2", PlayType::Stop);
75 let xml = movie.to_xml_string();
76 assert!(xml.contains("Type=\"Stop\""));
77 }
78
79 #[test]
80 fn test_movie_clone_debug() {
81 let movie = Movie::new("m1", PlayType::Pause);
82 let movie2 = movie.clone();
83 assert_eq!(movie2.media_ref, "m1");
84 assert_eq!(movie2.play_type, PlayType::Pause);
85 let dbg = format!("{movie:?}");
86 assert!(dbg.contains("Movie"));
87 }
88}