1
#[allow(unused_imports)]
2
pub use super::*;
3
#[cfg(test)]
4
mod tests {
5
    use super::*;
6

            
7
3
    fn img(w: u32, h: u32) -> TrayIconImage {
8
3
        TrayIconImage::new(w, h, vec![0u8; (w * h * 4) as usize].into())
9
3
            .into_option()
10
3
            .expect("w*h*4 buffer must be accepted")
11
3
    }
12

            
13
    #[test]
14
1
    fn new_rejects_a_buffer_that_is_not_w_times_h_times_4() {
15
1
        assert!(TrayIconImage::new(2, 2, vec![0u8; 16].into()).is_some());
16
1
        assert!(TrayIconImage::new(2, 2, vec![0u8; 15].into()).is_none());
17
1
        assert!(TrayIconImage::new(2, 2, vec![0u8; 17].into()).is_none());
18
        // A zero dimension would make `expected` 0 and let an empty buffer
19
        // through, which every backend would then read as a valid icon.
20
1
        assert!(TrayIconImage::new(0, 4, U8Vec::from_const_slice(&[])).is_none());
21
1
        assert!(TrayIconImage::new(4, 0, U8Vec::from_const_slice(&[])).is_none());
22
1
    }
23

            
24
    #[test]
25
1
    fn argb32_be_reorders_rgba_to_a_r_g_b() {
26
        // One pixel: R=1 G=2 B=3 A=4  ->  A=4 R=1 G=2 B=3
27
1
        let i = TrayIconImage::new(1, 1, vec![1, 2, 3, 4].into())
28
1
            .into_option()
29
1
            .expect("1x1 RGBA is 4 bytes");
30
1
        assert_eq!(i.to_argb32_be().as_ref(), &[4u8, 1, 2, 3]);
31
1
    }
32

            
33
    #[test]
34
1
    fn best_icon_prefers_the_smallest_that_still_covers_the_target() {
35
1
        let d = TrayIconData {
36
1
            icon: TrayIconSource::Rgba(TrayIconImageVec::from_vec(vec![
37
1
                img(16, 16),
38
1
                img(32, 32),
39
1
                img(64, 64),
40
1
            ])),
41
1
            ..Default::default()
42
1
        };
43
        // Exact match wins.
44
1
        assert_eq!(d.best_icon(32).into_option().unwrap().width, 32);
45
        // Between sizes: scale DOWN from 32, never up from 16.
46
1
        assert_eq!(d.best_icon(20).into_option().unwrap().width, 32);
47
        // Larger than everything we have: take the biggest.
48
1
        assert_eq!(d.best_icon(256).into_option().unwrap().width, 64);
49
        // No icons at all is not a panic.
50
1
        assert!(TrayIconData::default().best_icon(16).is_none());
51
        // A named icon has no bitmap to pick from — it is rasterized at the
52
        // exact size instead, so best_icon must not invent one.
53
1
        assert!(TrayIconData::default()
54
1
            .with_named_icon(AzString::from_const_str("settings"))
55
1
            .best_icon(16)
56
1
            .is_none());
57
1
    }
58

            
59
    #[test]
60
1
    fn named_icon_stores_the_spec_verbatim() {
61
        // The spec is passed through untouched: parsing pack-qualification and
62
        // fallback lists is the icon registry's job, not the tray's, so that
63
        // `<icon>` and a tray icon can never disagree about what a spec means.
64
3
        for spec in ["settings", "mypack:logo", "missing:x, settings"] {
65
3
            let d = TrayIconData::new(
66
3
                AzString::from_const_str("org.example.app"),
67
3
                AzString::from_const_str("App"),
68
            )
69
3
            .with_named_icon(AzString::from(String::from(spec)));
70
3
            let TrayIconSource::Named(ref s) = d.icon else {
71
                panic!("expected a named icon source");
72
            };
73
3
            assert_eq!(s.as_str(), spec);
74
        }
75
1
    }
76

            
77
    #[test]
78
1
    fn sni_names_match_the_spec_spelling_exactly() {
79
        // These strings go on the wire; a typo silently breaks the item.
80
1
        assert_eq!(
81
1
            TrayCategory::ApplicationStatus.sni_name(),
82
            "ApplicationStatus"
83
        );
84
1
        assert_eq!(TrayCategory::SystemServices.sni_name(), "SystemServices");
85
1
        assert_eq!(TrayStatus::NeedsAttention.sni_name(), "NeedsAttention");
86
1
        assert_eq!(TrayStatus::Passive.sni_name(), "Passive");
87
1
    }
88
}