audio_decoder_test_lib/
test_suite.rs
1#![allow(clippy::large_futures)]
6
7use fidl_fuchsia_media::*;
8use fidl_fuchsia_sysmem2::{BufferCollectionConstraints, BufferMemoryConstraints};
9use std::rc::Rc;
10use stream_processor_decoder_factory::*;
11use stream_processor_test::*;
12
13pub struct AudioDecoderTestCase {
14 pub output_tests: Vec<AudioDecoderOutputTest>,
15}
16
17pub struct AudioDecoderOutputTest {
20 pub output_file: Option<&'static str>,
23 pub stream: Rc<dyn ElementaryStream>,
24 pub expected_output_size: OutputSize,
25 pub expected_digests: Option<Vec<ExpectedDigest>>,
26 pub expected_output_format: FormatDetails,
27}
28
29fn test_buffer_collection_constraints() -> BufferCollectionConstraints {
30 BufferCollectionConstraints {
31 buffer_memory_constraints: Some(BufferMemoryConstraints {
32 min_size_bytes: Some(10001),
35 ..Default::default()
36 }),
37 ..buffer_collection_constraints_default()
38 }
39}
40
41impl AudioDecoderTestCase {
42 pub async fn run(self) -> Result<()> {
43 self.test_hashes().await
44 }
45
46 async fn test_hashes(self) -> Result<()> {
47 let mut cases = vec![];
48 for (output_test, stream_lifetime_ordinal) in
49 self.output_tests.into_iter().zip(OrdinalPattern::Odd.into_iter())
50 {
51 let mut validators: Vec<Rc<dyn OutputValidator>> =
52 vec![Rc::new(TerminatesWithValidator {
53 expected_terminal_output: Output::Eos { stream_lifetime_ordinal },
54 })];
55 match output_test.expected_output_size {
56 OutputSize::PacketCount(v) => {
57 validators.push(Rc::new(OutputPacketCountValidator {
58 expected_output_packet_count: v,
59 }));
60 }
61 OutputSize::RawBytesCount(v) => {
62 validators
63 .push(Rc::new(OutputDataSizeValidator { expected_output_data_size: v }));
64 }
65 };
66 validators.push(Rc::new(FormatValidator {
67 expected_format: output_test.expected_output_format,
68 }));
69 if let Some(digests) = output_test.expected_digests {
70 validators.push(Rc::new(BytesValidator {
71 output_file: output_test.output_file,
72 expected_digests: digests,
73 }));
74 }
75 cases.push(TestCase {
76 name: "Audio decoder output test",
77 stream: output_test.stream,
78 validators,
79 stream_options: Some(StreamOptions {
80 queue_format_details: false,
81 output_buffer_collection_constraints: Some(test_buffer_collection_constraints()),
83 ..StreamOptions::default()
84 }),
85 });
86 }
87
88 let spec = TestSpec {
89 cases,
90 relation: CaseRelation::Serial,
91 stream_processor_factory: Rc::new(DecoderFactory),
92 };
93
94 spec.run().await.map(|_| ())
95 }
96}