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

            
7
    #[test]
8
1
    fn the_preview_id_is_reserved_and_zero_sizes_are_invalid() {
9
1
        assert_eq!(FrameConsumer::PREVIEW_ID, 0);
10
1
        assert!(
11
1
            !FrameConsumer::new(0, 100, 100).is_valid(),
12
            "id 0 is the preview"
13
        );
14
1
        assert!(!FrameConsumer::new(7, 0, 100).is_valid());
15
1
        assert!(!FrameConsumer::new(7, 100, 0).is_valid());
16
1
        assert!(FrameConsumer::new(7, 500, 200).is_valid());
17
1
        assert_eq!(FrameConsumer::default(), FrameConsumer::new(0, 0, 0));
18
1
    }
19

            
20
    #[test]
21
1
    fn consumers_round_trip_through_the_ffi_vec() {
22
1
        let bob = FrameConsumer::new(7, 500, 200);
23
1
        let rec = FrameConsumer::new(8, 1280, 720);
24
1
        let v: FrameConsumerVec = alloc::vec![bob, rec].into();
25
1
        assert_eq!(v.as_ref(), &[bob, rec]);
26
1
        let cloned = v.clone();
27
1
        assert_eq!(cloned, v);
28
1
        let cut = ConsumerFrame::new(
29
1
            bob,
30
1
            VideoFrame::new(500, 200, U8Vec::from_vec(alloc::vec![0; 500 * 200 * 4])),
31
        );
32
1
        assert_eq!(cut.consumer.id, 7);
33
1
        assert_eq!(cut.frame.bytes.as_ref().len(), 500 * 200 * 4);
34
1
    }
35
}
36

            
37
#[cfg(test)]
38
mod autotest_generated {
39
    use alloc::{string::String, vec, vec::Vec};
40

            
41
    use super::*;
42

            
43
    // --- helpers ---------------------------------------------------------
44

            
45
    /// Owned (`DefaultRust`-destructor) `U8Vec` — the shape a real decode
46
    /// worker hands back, so clone/drop actually exercise the allocator.
47
    fn u8v(bytes: Vec<u8>) -> U8Vec {
48
        U8Vec::from_vec(bytes)
49
    }
50

            
51
    fn frame(width: u32, height: u32, bytes: Vec<u8>) -> VideoFrame {
52
        VideoFrame::new(width, height, u8v(bytes))
53
    }
54

            
55
    /// The `bytes` of a `VideoSource::Bytes`; test-only, the other variants
56
    /// are never passed here.
57
    fn source_bytes(source: &VideoSource) -> &U8Vec {
58
        match source {
59
            VideoSource::Bytes(b) => b,
60
            other => panic!("expected VideoSource::Bytes, got {other:?}"),
61
        }
62
    }
63

            
64
    /// The documented `VideoFrame` size invariant, computed in u128 so that the
65
    /// expectation itself cannot overflow (u64 does, at max dimensions).
66
    fn declared_len(width: u32, height: u32) -> u128 {
67
        u128::from(width) * u128::from(height) * 4
68
    }
69

            
70
    // --- VideoConfig::new (constructor) ----------------------------------
71

            
72
    /// invariants_hold: every non-source field is the documented default
73
    /// (autoplay on, no loop, BGRA8, t=0) and `source` is stored verbatim.
74
    #[test]
75
    fn config_new_fields_match_args() {
76
        let url = Url::from_parts("https", "example.com", 443, "/movie.mp4");
77
        let c = VideoConfig::new(VideoSource::Url(url.clone()));
78

            
79
        assert_eq!(c.source, VideoSource::Url(url));
80
        assert!((c.timestamp - 0.0).abs() < f32::EPSILON);
81
        assert!(c.autoplay);
82
        assert!(!c.looping);
83
        assert_eq!(c.output_format, RawImageFormat::BGRA8);
84
    }
85

            
86
    /// invariants_hold: `new` sets ONLY `source` — every other field stays
87
    /// bit-for-bit identical to `Default`, for each of the three variants.
88
    #[test]
89
    fn config_new_only_overrides_source() {
90
        let d = VideoConfig::default();
91

            
92
        for source in [
93
            VideoSource::Url(Url::from_parts("http", "a.tld", 8080, "/v")),
94
            VideoSource::File(AzString::from_const_str("/tmp/clip.mp4")),
95
            VideoSource::Bytes(u8v(vec![0xFF; 8])),
96
        ] {
97
            let c = VideoConfig::new(source.clone());
98
            assert_eq!(c.source, source, "source must round-trip unchanged");
99
            assert_eq!(c.timestamp.to_bits(), d.timestamp.to_bits());
100
            assert_eq!(c.autoplay, d.autoplay);
101
            assert_eq!(c.looping, d.looping);
102
            assert_eq!(c.output_format, d.output_format);
103
        }
104
    }
105

            
106
    /// invariants_hold: the default source funnels back to the plain `Default`.
107
    #[test]
108
    fn config_new_with_default_source_equals_default() {
109
        assert_eq!(
110
            VideoConfig::new(VideoSource::default()),
111
            VideoConfig::default()
112
        );
113
        assert_eq!(VideoSource::default(), VideoSource::Url(Url::default()));
114
    }
115

            
116
    /// unicode: a non-ASCII file path (emoji, CJK, RTL, combining marks) must
117
    /// survive the `AzString` round-trip byte-for-byte — no truncation at a
118
    /// multi-byte boundary, no re-encoding.
119
    #[test]
120
    fn config_new_unicode_file_path_roundtrip() {
121
        let path = String::from("/tmp/vídeos/𝔘𝔫𝔦/影片 🎬/مقطع/e\u{0301}.mp4");
122
        let c = VideoConfig::new(VideoSource::File(AzString::from(path.clone())));
123

            
124
        match &c.source {
125
            VideoSource::File(s) => {
126
                assert_eq!(s.as_str(), path.as_str());
127
                assert_eq!(s.as_str().len(), path.len(), "byte length preserved");
128
                assert_eq!(s.as_str().chars().count(), path.chars().count());
129
            }
130
            other => panic!("expected File, got {other:?}"),
131
        }
132
    }
133

            
134
    /// malformed: an interior NUL and control bytes are legal in a Rust `str`
135
    /// and must be preserved verbatim (any C-side truncation is the FFI layer's
136
    /// problem, not this constructor's).
137
    #[test]
138
    fn config_new_file_path_with_interior_nul_preserved() {
139
        let path = String::from("/tmp/a\0b\r\n\t.mp4");
140
        let c = VideoConfig::new(VideoSource::File(AzString::from(path.clone())));
141

            
142
        match &c.source {
143
            VideoSource::File(s) => {
144
                assert_eq!(s.as_str(), path.as_str());
145
                assert_eq!(s.as_str().len(), 15);
146
                assert!(s.as_str().contains('\0'));
147
            }
148
            other => panic!("expected File, got {other:?}"),
149
        }
150
    }
151

            
152
    /// boundary: an empty path / empty byte source must not panic and must stay empty.
153
    #[test]
154
    fn config_new_empty_sources_no_panic() {
155
        let empty_file = VideoConfig::new(VideoSource::File(AzString::from(String::new())));
156
        match &empty_file.source {
157
            VideoSource::File(s) => assert_eq!(s.as_str(), ""),
158
            other => panic!("expected File, got {other:?}"),
159
        }
160

            
161
        let empty_bytes = VideoConfig::new(VideoSource::Bytes(u8v(Vec::new())));
162
        let b = source_bytes(&empty_bytes.source);
163
        assert!(b.is_empty());
164
        assert_eq!(b.len(), 0);
165
        assert_eq!(b.as_ref(), &[] as &[u8]);
166
    }
167

            
168
    /// huge: a 1 MiB in-memory MP4 must move into the config with no copy loss —
169
    /// check both ends of the buffer, not just the length.
170
    #[test]
171
    fn config_new_huge_bytes_source_preserved() {
172
        const N: usize = 1 << 20;
173
        let data: Vec<u8> = (0..N).map(|i| (i % 251) as u8).collect();
174

            
175
        let c = VideoConfig::new(VideoSource::Bytes(u8v(data.clone())));
176
        let b = source_bytes(&c.source);
177

            
178
        let last = ((N - 1) % 251) as u8;
179
        assert_eq!(b.len(), N);
180
        assert_eq!(b.as_ref(), data.as_slice());
181
        assert_eq!(b.get(0), Some(&0));
182
        assert_eq!(b.get(N - 1), Some(&last));
183
        assert_eq!(b.get(N), None, "one past the end must be None, not UB");
184
    }
185

            
186
    /// invariants_hold: `Clone` of a `Bytes` config is a DEEP copy — the clone
187
    /// owns its own allocation and stays readable after the original is dropped
188
    /// (a shallow copy here would be a double-free at the second drop).
189
    #[test]
190
    fn config_clone_of_bytes_is_deep_and_survives_original_drop() {
191
        let original = VideoConfig::new(VideoSource::Bytes(u8v(vec![1, 2, 3, 4, 5])));
192
        let original_ptr = source_bytes(&original.source).as_ptr();
193

            
194
        let cloned = original.clone();
195
        let cloned_ptr = source_bytes(&cloned.source).as_ptr();
196
        assert_ne!(
197
            original_ptr, cloned_ptr,
198
            "clone must not alias the original buffer"
199
        );
200

            
201
        drop(original);
202

            
203
        assert_eq!(source_bytes(&cloned.source).as_ref(), &[1, 2, 3, 4, 5]);
204
    }
205

            
206
    /// invariants_hold: the variants are genuinely distinct — a `File` path and
207
    /// a `Url` with the same text are NOT equal, so the decode worker's match
208
    /// can't be spoofed.
209
    #[test]
210
    fn config_source_variants_are_distinct() {
211
        let text = "https://example.com/v.mp4";
212
        let as_file = VideoConfig::new(VideoSource::File(AzString::from_const_str(text)));
213
        let as_url = VideoConfig::new(VideoSource::Url(Url::from_parts(
214
            "https",
215
            "example.com",
216
            443,
217
            "/v.mp4",
218
        )));
219

            
220
        assert_ne!(as_file, as_url);
221
        assert_ne!(as_file.source, as_url.source);
222
        assert_eq!(as_url.source, as_url.source.clone());
223
    }
224

            
225
    /// numeric/limits: extreme scrub positions are stored verbatim (the POD does
226
    /// no clamping) — infinities, subnormals and f32::MAX must not panic.
227
    #[test]
228
    fn config_extreme_timestamps_stored_verbatim() {
229
        let base = VideoConfig::new(VideoSource::default());
230

            
231
        for t in [
232
            f32::INFINITY,
233
            f32::NEG_INFINITY,
234
            f32::MAX,
235
            f32::MIN,
236
            f32::MIN_POSITIVE,
237
            f32::MIN_POSITIVE / 2.0, // subnormal
238
            -1.0,
239
            1e30,
240
        ] {
241
            let c = VideoConfig {
242
                timestamp: t,
243
                ..base.clone()
244
            };
245
            assert_eq!(
246
                c.timestamp.to_bits(),
247
                t.to_bits(),
248
                "timestamp {t} was altered"
249
            );
250
            assert_eq!(c, c.clone(), "non-NaN config must be self-equal");
251
        }
252
    }
253

            
254
    /// numeric/NaN: derived `PartialEq` over an f32 field means a NaN timestamp
255
    /// makes a config unequal to an identical config (reflexivity is broken).
256
    /// Callers must not use `VideoConfig` equality to decide "did the seek
257
    /// change?" if a NaN can reach `timestamp` — assert the hazard explicitly.
258
    #[test]
259
    fn config_nan_timestamp_breaks_reflexive_equality() {
260
        let nan_a = VideoConfig {
261
            timestamp: f32::NAN,
262
            ..VideoConfig::new(VideoSource::default())
263
        };
264
        let nan_b = nan_a.clone();
265

            
266
        assert!(nan_a.timestamp.is_nan());
267
        assert_ne!(
268
            nan_a, nan_b,
269
            "NaN timestamp: derived PartialEq is not reflexive"
270
        );
271

            
272
        // ...and `new` itself never produces such a config.
273
        let fresh = VideoConfig::new(VideoSource::default());
274
        assert!(!fresh.timestamp.is_nan());
275
        assert_eq!(fresh, fresh.clone());
276
    }
277

            
278
    /// numeric: -0.0 compares EQUAL to +0.0 (IEEE), even though the bits differ —
279
    /// so a config scrubbed to -0.0 is `==` to a freshly constructed one.
280
    #[test]
281
    fn config_negative_zero_timestamp_equals_default() {
282
        let fresh = VideoConfig::new(VideoSource::default());
283
        let neg_zero = VideoConfig {
284
            timestamp: -0.0,
285
            ..VideoConfig::new(VideoSource::default())
286
        };
287

            
288
        assert!(neg_zero.timestamp.is_sign_negative());
289
        assert_ne!(neg_zero.timestamp.to_bits(), fresh.timestamp.to_bits());
290
        assert_eq!(neg_zero, fresh, "IEEE: -0.0 == +0.0");
291
    }
292

            
293
    // --- VideoFrame::new (constructor) -----------------------------------
294

            
295
    /// invariants_hold: fields match the exact args and the byte buffer round-trips.
296
    #[test]
297
    fn frame_new_fields_match_args() {
298
        let pixels: Vec<u8> = (0..(3 * 2 * 4)).map(|i| i as u8).collect();
299
        let f = frame(3, 2, pixels.clone());
300

            
301
        assert_eq!(f.width, 3);
302
        assert_eq!(f.height, 2);
303
        assert_eq!(f.bytes.as_ref(), pixels.as_slice());
304
        assert_eq!(u128::from(f.bytes.len() as u64), declared_len(3, 2));
305
    }
306

            
307
    /// round-trip: all 256 byte values survive `Vec -> U8Vec -> slice` unchanged
308
    /// (no sign-extension / no UTF-8 sanitisation on the pixel path).
309
    #[test]
310
    fn frame_bytes_roundtrip_all_byte_values() {
311
        let pixels: Vec<u8> = (0..=255u8).collect(); // 256 B == 8x8 RGBA
312
        let f = frame(8, 8, pixels.clone());
313

            
314
        assert_eq!(f.bytes.as_ref(), pixels.as_slice());
315
        assert_eq!(f.bytes.len(), 256);
316
        assert_eq!(u128::from(f.bytes.len() as u64), declared_len(8, 8));
317
        assert_eq!(f.bytes.get(0), Some(&0));
318
        assert_eq!(f.bytes.get(255), Some(&255));
319
        assert_eq!(f.bytes.get(256), None);
320
        assert!(f.bytes.iter().copied().eq(pixels.iter().copied()));
321
    }
322

            
323
    /// boundary: a 0x0 frame with no bytes is legal and must not panic.
324
    #[test]
325
    fn frame_new_zero_dimensions_empty_bytes() {
326
        let f = frame(0, 0, Vec::new());
327

            
328
        assert_eq!(f.width, 0);
329
        assert_eq!(f.height, 0);
330
        assert!(f.bytes.is_empty());
331
        assert_eq!(f.bytes.as_ref(), &[] as &[u8]);
332
        assert_eq!(declared_len(0, 0), 0);
333
    }
334

            
335
    /// boundary: a degenerate strip (n x 0 / 0 x n) keeps its nonzero dimension.
336
    #[test]
337
    fn frame_new_degenerate_strips() {
338
        let wide = frame(1920, 0, Vec::new());
339
        assert_eq!((wide.width, wide.height), (1920, 0));
340
        assert!(wide.bytes.is_empty());
341

            
342
        let tall = frame(0, 1080, Vec::new());
343
        assert_eq!((tall.width, tall.height), (0, 1080));
344
        assert!(tall.bytes.is_empty());
345
    }
346

            
347
    /// numeric/overflow: `new` accepts u32::MAX dimensions without panicking or
348
    /// touching `bytes` — it never computes `w * h * 4`. It is therefore the
349
    /// CALLER that must do the size math in u128: at these dimensions the
350
    /// declared buffer size overflows even u64.
351
    #[test]
352
    fn frame_new_max_dimensions_no_panic_and_size_math_overflows() {
353
        let f = VideoFrame::new(u32::MAX, u32::MAX, U8Vec::from_vec(Vec::new()));
354

            
355
        assert_eq!(f.width, u32::MAX);
356
        assert_eq!(f.height, u32::MAX);
357
        assert!(f.bytes.is_empty(), "new does no allocation of its own");
358

            
359
        // The documented `width * height * 4` is unrepresentable here...
360
        assert_eq!(u32::MAX.checked_mul(u32::MAX), None);
361
        assert_eq!(
362
            u64::from(u32::MAX)
363
                .checked_mul(u64::from(u32::MAX))
364
                .and_then(|px| px.checked_mul(4)),
365
            None,
366
            "even u64 overflows: callers must size-check before allocating"
367
        );
368
        // ...but u128 holds it, and that is what `declared_len` uses.
369
        assert_eq!(
370
            declared_len(u32::MAX, u32::MAX),
371
            4 * (u128::from(u32::MAX)).pow(2)
372
        );
373
    }
374

            
375
    /// numeric/boundary: 32768x32768 is the smallest square frame whose RGBA byte
376
    /// count (2^32) no longer fits in u32 — the constructor still accepts it.
377
    #[test]
378
    fn frame_new_u32_pixel_size_overflow_boundary() {
379
        let f = VideoFrame::new(32_768, 32_768, U8Vec::from_vec(Vec::new()));
380
        assert_eq!((f.width, f.height), (32_768, 32_768));
381

            
382
        assert_eq!(
383
            32_768u32
384
                .checked_mul(32_768)
385
                .and_then(|px| px.checked_mul(4)),
386
            None,
387
            "2^30 px * 4 == 2^32 overflows u32"
388
        );
389
        assert_eq!(declared_len(32_768, 32_768), 1u128 << 32);
390
        // One row narrower still fits.
391
        assert_eq!(
392
            32_767u32
393
                .checked_mul(32_768)
394
                .and_then(|px| px.checked_mul(4)),
395
            Some(4_294_836_224)
396
        );
397
    }
398

            
399
    /// invariants_hold: `new` is a pure wrapper — it does NOT enforce
400
    /// `bytes.len() == width * height * 4`. A short buffer is accepted as-is, so
401
    /// consumers must validate before indexing (this is the documented contract,
402
    /// pinned here so a future "validating" rewrite can't land silently).
403
    #[test]
404
    fn frame_new_does_not_validate_buffer_length() {
405
        let short = frame(1, 1, vec![0xAA, 0xBB, 0xCC]); // 3 B, needs 4
406
        assert_eq!(short.bytes.len(), 3);
407
        assert_ne!(u128::from(short.bytes.len() as u64), declared_len(1, 1));
408

            
409
        let long = frame(1, 1, vec![0; 64]); // 64 B, needs 4
410
        assert_eq!(long.bytes.len(), 64);
411

            
412
        // A frame claiming 4K but carrying nothing is likewise constructible.
413
        let lying = frame(3840, 2160, Vec::new());
414
        assert!(lying.bytes.is_empty());
415
        assert_eq!(declared_len(3840, 2160), 33_177_600);
416
    }
417

            
418
    /// invariants_hold: `const fn new` really is usable in a const context.
419
    #[test]
420
    fn frame_new_is_const_evaluable() {
421
        const F: VideoFrame = VideoFrame::new(1, 1, U8Vec::from_const_slice(&[1, 2, 3, 4]));
422

            
423
        assert_eq!(F.width, 1);
424
        assert_eq!(F.height, 1);
425
        assert_eq!(F.bytes.as_ref(), &[1, 2, 3, 4]);
426
        assert_eq!(u128::from(F.bytes.len() as u64), declared_len(1, 1));
427
    }
428

            
429
    /// invariants_hold: equality is field-wise — differing width, height or a
430
    /// single differing pixel byte all compare unequal.
431
    #[test]
432
    fn frame_equality_is_fieldwise() {
433
        let base = frame(2, 1, vec![1, 2, 3, 4, 5, 6, 7, 8]);
434

            
435
        assert_eq!(base, frame(2, 1, vec![1, 2, 3, 4, 5, 6, 7, 8]));
436
        assert_ne!(
437
            base,
438
            frame(1, 2, vec![1, 2, 3, 4, 5, 6, 7, 8]),
439
            "w/h swap differs"
440
        );
441
        assert_ne!(
442
            base,
443
            frame(2, 1, vec![1, 2, 3, 4, 5, 6, 7, 9]),
444
            "last byte differs"
445
        );
446
        assert_ne!(
447
            base,
448
            frame(2, 1, vec![1, 2, 3, 4]),
449
            "truncated buffer differs"
450
        );
451
    }
452

            
453
    /// invariants_hold: `Clone` deep-copies the pixels — the clone outlives the
454
    /// original's drop and owns a distinct allocation.
455
    #[test]
456
    fn frame_clone_is_deep_and_survives_original_drop() {
457
        let original = frame(2, 2, (0..16).collect());
458
        let original_ptr = original.bytes.as_ptr();
459

            
460
        let cloned = original.clone();
461
        assert_ne!(original_ptr, cloned.bytes.as_ptr(), "clone must not alias");
462
        assert_eq!(cloned, original);
463

            
464
        drop(original);
465

            
466
        assert_eq!(
467
            cloned.bytes.as_ref(),
468
            (0..16u8).collect::<Vec<_>>().as_slice()
469
        );
470
        assert_eq!(cloned.width, 2);
471
        assert_eq!(cloned.height, 2);
472
    }
473

            
474
    // --- OptionVideoFrame / VideoFrameVec (FFI wrappers) ------------------
475

            
476
    /// round-trip: `Option<VideoFrame> -> OptionVideoFrame -> Option<VideoFrame>`
477
    /// is the identity for both `Some` and `None`.
478
    #[test]
479
    fn option_video_frame_roundtrip() {
480
        let f = frame(1, 1, vec![9, 8, 7, 6]);
481

            
482
        let some: OptionVideoFrame = Some(f.clone()).into();
483
        assert!(some.is_some());
484
        assert!(!some.is_none());
485
        assert_eq!(some.as_ref(), Some(&f));
486
        assert_eq!(Option::<VideoFrame>::from(some.clone()), Some(f.clone()));
487
        assert_eq!(some.into_option(), Some(f));
488

            
489
        let none: OptionVideoFrame = Option::<VideoFrame>::None.into();
490
        assert!(none.is_none());
491
        assert_eq!(none.as_ref(), None);
492
        assert_eq!(Option::<VideoFrame>::from(none), None);
493
        assert_eq!(OptionVideoFrame::default().into_option(), None);
494
    }
495

            
496
    /// invariants_hold: `replace` returns the PREVIOUS value (mem::replace semantics).
497
    #[test]
498
    fn option_video_frame_replace_returns_previous() {
499
        let first = frame(1, 1, vec![1, 1, 1, 1]);
500
        let second = frame(1, 1, vec![2, 2, 2, 2]);
501

            
502
        let mut slot = OptionVideoFrame::None;
503
        assert_eq!(slot.replace(first.clone()).into_option(), None);
504
        assert_eq!(slot.replace(second.clone()).into_option(), Some(first));
505
        assert_eq!(slot.into_option(), Some(second));
506
    }
507

            
508
    /// round-trip: `Vec<VideoFrame> -> VideoFrameVec -> slice` preserves order,
509
    /// length and every frame, and out-of-bounds access returns None (not UB).
510
    #[test]
511
    fn frame_vec_roundtrip_and_bounds() {
512
        let frames = vec![
513
            frame(1, 1, vec![0, 0, 0, 255]),
514
            frame(2, 1, vec![1; 8]),
515
            frame(0, 0, Vec::new()),
516
        ];
517

            
518
        let v = VideoFrameVec::from_vec(frames.clone());
519

            
520
        assert_eq!(v.len(), 3);
521
        assert!(!v.is_empty());
522
        assert_eq!(v.as_ref(), frames.as_slice());
523
        assert_eq!(v.get(0), Some(&frames[0]));
524
        assert_eq!(v.get(2), Some(&frames[2]));
525
        assert_eq!(v.get(3), None, "out of bounds must be None");
526
        assert_eq!(v.get(usize::MAX), None, "usize::MAX index must be None");
527
        assert!(v.iter().eq(frames.iter()), "iteration order preserved");
528

            
529
        // C-API accessor mirrors the Rust one.
530
        assert_eq!(v.c_get(1).into_option(), Some(frames[1].clone()));
531
        assert!(v.c_get(3).is_none());
532

            
533
        // Deep clone: equal contents, distinct backing allocation.
534
        let cloned = v.clone();
535
        assert_eq!(cloned, v);
536
        assert_ne!(cloned.as_ptr(), v.as_ptr());
537
    }
538

            
539
    /// boundary: the empty frame list is well-formed (empty slice, no panic).
540
    #[test]
541
    fn frame_vec_empty_is_well_formed() {
542
        let v = VideoFrameVec::from_vec(Vec::new());
543

            
544
        assert!(v.is_empty());
545
        assert_eq!(v.len(), 0);
546
        assert_eq!(v.as_ref(), &[] as &[VideoFrame]);
547
        assert_eq!(v.get(0), None);
548
        assert_eq!(v.clone(), v);
549
        assert_eq!(VideoFrameVec::new(), v);
550
    }
551

            
552
    /// invariants_hold: a `'static`-backed (`NoDestructor`) frame list — the
553
    /// const-data path across the FFI — reads back identically and its drop must
554
    /// not free the static memory.
555
    #[test]
556
    fn frame_vec_from_const_slice_no_destructor() {
557
        static FRAMES: [VideoFrame; 2] = [
558
            VideoFrame::new(1, 1, U8Vec::from_const_slice(&[1, 2, 3, 4])),
559
            VideoFrame::new(1, 1, U8Vec::from_const_slice(&[5, 6, 7, 8])),
560
        ];
561

            
562
        let v = VideoFrameVec::from_const_slice(&FRAMES);
563
        assert_eq!(v.len(), 2);
564
        assert_eq!(v.as_ref(), &FRAMES[..]);
565
        assert_eq!(v.get(1).map(|f| f.bytes.as_ref()), Some(&[5, 6, 7, 8][..]));
566

            
567
        // Cloning a const-slice vec yields an owned copy; both drop cleanly here.
568
        let cloned = v.clone();
569
        assert_eq!(cloned, v);
570
        drop(v);
571
        assert_eq!(cloned.len(), 2);
572
    }
573
}