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

            
7
    use super::*;
8

            
9
    /// Representative + extreme sources: both payload boundaries (0, MAX) for
10
    /// each carrying variant, so a truncating/aliasing constructor cannot pass.
11
    const ALL_SOURCES: [ScreenCaptureSource; 7] = [
12
        ScreenCaptureSource::PrimaryDisplay,
13
        ScreenCaptureSource::Display(0),
14
        ScreenCaptureSource::Display(1),
15
        ScreenCaptureSource::Display(u32::MAX),
16
        ScreenCaptureSource::Window(0),
17
        ScreenCaptureSource::Window(1),
18
        ScreenCaptureSource::Window(u64::MAX),
19
    ];
20

            
21
    // ---- ScreenCaptureConfig::new — constructor: no_panic ----
22

            
23
    #[test]
24
    fn new_does_not_panic_for_representative_or_extreme_sources() {
25
        for &source in &ALL_SOURCES {
26
            let _ = ScreenCaptureConfig::new(source);
27
        }
28
    }
29

            
30
    #[test]
31
    fn new_is_deterministic() {
32
        // Same argument twice => observably identical configs (no hidden state,
33
        // no backend probing at construction time).
34
        for &source in &ALL_SOURCES {
35
            assert_eq!(
36
                ScreenCaptureConfig::new(source),
37
                ScreenCaptureConfig::new(source)
38
            );
39
        }
40
    }
41

            
42
    // ---- ScreenCaptureConfig::new — constructor: invariants_hold ----
43

            
44
    #[test]
45
    fn new_sets_source_and_leaves_everything_else_at_default() {
46
        // Documented contract: "a default config for the given `source`
47
        // (backend-chosen fps, BGRA8)" — so new(s) may differ from Default
48
        // only in `source`.
49
        let def = ScreenCaptureConfig::default();
50
        for &source in &ALL_SOURCES {
51
            let cfg = ScreenCaptureConfig::new(source);
52
            assert_eq!(cfg.source, source, "source must equal the argument");
53
            assert_eq!(cfg.fps, def.fps);
54
            assert_eq!(cfg.output_format, def.output_format);
55
            // Absolute invariants, not merely "== whatever Default says":
56
            assert_eq!(cfg.fps, 0, "0 => backend picks the frame rate");
57
            assert_eq!(
58
                cfg.output_format,
59
                RawImageFormat::BGRA8,
60
                "BGRA8 is the documented portable default"
61
            );
62
        }
63
    }
64

            
65
    #[test]
66
    fn new_equals_struct_update_syntax() {
67
        for &source in &ALL_SOURCES {
68
            let via_new = ScreenCaptureConfig::new(source);
69
            let via_update = ScreenCaptureConfig {
70
                source,
71
                ..ScreenCaptureConfig::default()
72
            };
73
            assert_eq!(via_new, via_update);
74
        }
75
    }
76

            
77
    #[test]
78
    fn default_config_is_new_of_default_source() {
79
        // The two `Default` impls (derived on the enum, hand-written on the
80
        // struct) must not drift apart.
81
        assert_eq!(
82
            ScreenCaptureConfig::default(),
83
            ScreenCaptureConfig::new(ScreenCaptureSource::default())
84
        );
85
        assert_eq!(
86
            ScreenCaptureSource::default(),
87
            ScreenCaptureSource::PrimaryDisplay
88
        );
89
        assert_eq!(
90
            ScreenCaptureConfig::default().source,
91
            ScreenCaptureSource::PrimaryDisplay
92
        );
93
    }
94

            
95
    // ---- source payload: round-trip through the constructor ----
96

            
97
    #[test]
98
    fn new_preserves_full_payload_width() {
99
        // A u64 window handle must survive intact: a `as u32` anywhere in the
100
        // pipeline would collapse u64::MAX to u32::MAX-in-a-u64.
101
        let cfg = ScreenCaptureConfig::new(ScreenCaptureSource::Window(u64::MAX));
102
        match cfg.source {
103
            ScreenCaptureSource::Window(h) => assert_eq!(h, u64::MAX),
104
            other => panic!("expected Window(u64::MAX), got {other:?}"),
105
        }
106

            
107
        let cfg = ScreenCaptureConfig::new(ScreenCaptureSource::Display(u32::MAX));
108
        match cfg.source {
109
            ScreenCaptureSource::Display(i) => assert_eq!(i, u32::MAX),
110
            other => panic!("expected Display(u32::MAX), got {other:?}"),
111
        }
112

            
113
        // Enough room for the widest payload; guards against a narrowed repr.
114
        assert!(size_of::<ScreenCaptureSource>() >= size_of::<u64>());
115
    }
116

            
117
    #[test]
118
    fn distinct_sources_stay_distinct() {
119
        // Equality must compare the tag too, not just the payload bits.
120
        assert_ne!(
121
            ScreenCaptureSource::Display(1),
122
            ScreenCaptureSource::Window(1)
123
        );
124
        // `PrimaryDisplay` is its own variant, NOT a spelling of `Display(0)`.
125
        assert_ne!(
126
            ScreenCaptureSource::PrimaryDisplay,
127
            ScreenCaptureSource::Display(0)
128
        );
129
        assert_ne!(
130
            ScreenCaptureConfig::new(ScreenCaptureSource::PrimaryDisplay),
131
            ScreenCaptureConfig::new(ScreenCaptureSource::Display(0))
132
        );
133

            
134
        // Pairwise: no two entries of ALL_SOURCES may collide.
135
        for (i, a) in ALL_SOURCES.iter().enumerate() {
136
            for (j, b) in ALL_SOURCES.iter().enumerate() {
137
                let cfg_a = ScreenCaptureConfig::new(*a);
138
                let cfg_b = ScreenCaptureConfig::new(*b);
139
                if i == j {
140
                    assert_eq!(cfg_a, cfg_b, "Eq must be reflexive for {a:?}");
141
                } else {
142
                    assert_ne!(cfg_a, cfg_b, "{a:?} and {b:?} must not compare equal");
143
                }
144
            }
145
        }
146
    }
147

            
148
    #[test]
149
    fn config_is_copy_and_fields_are_independently_settable() {
150
        // The struct is a POD crossing the FFI: mutating a copy must not
151
        // disturb the original, and overwriting `fps`/`output_format` must not
152
        // corrupt the (differently aligned) `source` payload next to it.
153
        let original = ScreenCaptureConfig::new(ScreenCaptureSource::Window(u64::MAX));
154
        let mut copy = original;
155
        copy.fps = u32::MAX;
156
        copy.output_format = RawImageFormat::RGBAF32;
157

            
158
        assert_eq!(original.fps, 0, "original must be untouched (Copy)");
159
        assert_eq!(original.output_format, RawImageFormat::BGRA8);
160
        assert_eq!(
161
            copy.source, original.source,
162
            "source must survive the writes"
163
        );
164
        assert_eq!(copy.fps, u32::MAX);
165
        assert_eq!(copy.output_format, RawImageFormat::RGBAF32);
166
    }
167
}