Coverage Report

Created: 2026-06-02 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/adhd/audio_processor/src/buffer/debug.rs
Line
Count
Source
1
// Copyright 2022 The ChromiumOS Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
use std::fmt::Debug;
6
use std::iter::Iterator;
7
8
use crate::MultiBuffer;
9
use crate::MultiSlice;
10
11
0
fn debug_format<T>(struct_: &str, element: &str, lengths: T) -> String
12
0
where
13
0
    T: Iterator<Item = usize>,
14
{
15
0
    format!(
16
0
        "{} {{ <{} of lengths [{}]> }}",
17
        struct_,
18
        element,
19
0
        lengths
20
0
            .map(|x| x.to_string())
21
0
            .collect::<Vec<_>>()
22
0
            .join(", ")
23
    )
24
0
}
25
26
impl<T> Debug for MultiBuffer<T> {
27
0
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28
0
        write!(f, "MultiBuffer {{ shape: {:?} }}", self.shape)
29
0
    }
30
}
31
32
impl<T> Debug for MultiSlice<'_, T> {
33
0
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34
0
        let debug = debug_format("MultiSlice", "slices", self.data.iter().map(|x| x.len()));
35
0
        f.write_str(&debug)
36
0
    }
37
}
38
39
#[cfg(test)]
40
mod tests {
41
    use crate::MultiBuffer;
42
    use crate::MultiSlice;
43
44
    #[test]
45
    fn multi_buffer() {
46
        let buf = MultiBuffer::from(vec![vec![1i32, 2], vec![3, 4], vec![5, 6]]);
47
        assert_eq!(
48
            format!("{:?}", buf),
49
            "MultiBuffer { shape: Shape { channels: 3, frames: 2 } }"
50
        );
51
    }
52
53
    #[test]
54
    fn multi_slice() {
55
        let mut buf = vec![vec![1i32], vec![2, 3], vec![4, 5, 6]];
56
        assert_eq!(
57
            format!("{:?}", MultiSlice::from_vecs(&mut buf)),
58
            "MultiSlice { <slices of lengths [1, 2, 3]> }"
59
        );
60
    }
61
}