1
#[allow(unused_imports)]
2
pub use super::*;
3
#[cfg(test)]
4
mod autotest_generated {
5
    use alloc::{vec, vec::Vec};
6

            
7
    use super::*;
8

            
9
    // --- helpers ---------------------------------------------------------
10

            
11
    /// Build an `AudioFrame` from a channel count + owned sample vec.
12
    /// `AudioFrame` derives no `Default`, so each test constructs explicitly.
13
    fn frame(sample_rate: u32, channels: u16, samples: Vec<f32>) -> AudioFrame {
14
        AudioFrame {
15
            sample_rate,
16
            channels,
17
            samples: F32Vec::from_vec(samples),
18
        }
19
    }
20

            
21
    // --- AudioConfig::new (constructor) ----------------------------------
22

            
23
    /// invariants_hold: fields match the exact args, for representative input.
24
    #[test]
25
    fn config_new_fields_match_args() {
26
        let c = AudioConfig::new(48_000, 2);
27
        assert_eq!(c.sample_rate, 48_000);
28
        assert_eq!(c.channels, 2);
29
    }
30

            
31
    /// no_panic: extreme integer bounds must not panic or wrap; fields are stored verbatim.
32
    #[test]
33
    fn config_new_extreme_args_no_panic() {
34
        let zero = AudioConfig::new(0, 0);
35
        assert_eq!(zero.sample_rate, 0);
36
        assert_eq!(zero.channels, 0);
37

            
38
        let max = AudioConfig::new(u32::MAX, u16::MAX);
39
        assert_eq!(max.sample_rate, u32::MAX);
40
        assert_eq!(max.channels, u16::MAX);
41

            
42
        // A sample_rate of 1 with a very large channel count is nonsensical but legal POD.
43
        let odd = AudioConfig::new(1, u16::MAX);
44
        assert_eq!(odd.sample_rate, 1);
45
        assert_eq!(odd.channels, u16::MAX);
46
    }
47

            
48
    /// invariants_hold: `const fn` is usable in a const context (compile-time evaluation).
49
    #[test]
50
    fn config_new_is_const_evaluable() {
51
        const C: AudioConfig = AudioConfig::new(44_100, 1);
52
        assert_eq!(C.sample_rate, 44_100);
53
        assert_eq!(C.channels, 1);
54
    }
55

            
56
    /// invariants_hold: the documented default equals the equivalent explicit construction.
57
    #[test]
58
    fn config_default_matches_new() {
59
        assert_eq!(AudioConfig::default(), AudioConfig::new(48_000, 1));
60
    }
61

            
62
    /// invariants_hold: `Copy`/`Eq`/`Hash` are mutually consistent (equal values hash equal).
63
    #[test]
64
    fn config_eq_hash_consistent() {
65
        use core::hash::{Hash, Hasher};
66
        use std::collections::hash_map::DefaultHasher;
67

            
68
        let a = AudioConfig::new(96_000, 2);
69
        let b = a; // Copy
70
        assert_eq!(a, b);
71

            
72
        let mut ha = DefaultHasher::new();
73
        let mut hb = DefaultHasher::new();
74
        a.hash(&mut ha);
75
        b.hash(&mut hb);
76
        assert_eq!(ha.finish(), hb.finish());
77

            
78
        // Differing fields compare unequal.
79
        assert_ne!(AudioConfig::new(96_000, 2), AudioConfig::new(96_000, 1));
80
        assert_ne!(AudioConfig::new(96_000, 2), AudioConfig::new(48_000, 2));
81
    }
82

            
83
    // --- AudioFrame::frame_count (getter) --------------------------------
84

            
85
    /// basic_access: mono => frame_count == sample count.
86
    #[test]
87
    fn frame_count_mono_known_value() {
88
        let f = frame(48_000, 1, vec![0.0, 0.5, -0.5, 1.0]);
89
        assert_eq!(f.frame_count(), 4);
90
    }
91

            
92
    /// basic_access: stereo => frame_count == samples / 2.
93
    #[test]
94
    fn frame_count_stereo_known_value() {
95
        let f = frame(48_000, 2, vec![0.0, 0.5, -0.5, 1.0]);
96
        assert_eq!(f.frame_count(), 2);
97
    }
98

            
99
    /// edge_access: channels == 0 must hit the guard and return 0, NOT divide by zero.
100
    #[test]
101
    fn frame_count_zero_channels_no_div_by_zero() {
102
        let f = frame(48_000, 0, vec![0.0, 0.1, 0.2, 0.3, 0.4]);
103
        assert_eq!(f.frame_count(), 0);
104
    }
105

            
106
    /// edge_access: zero channels with zero samples is still 0 (guard short-circuits first).
107
    #[test]
108
    fn frame_count_zero_channels_empty_samples() {
109
        let f = frame(0, 0, Vec::new());
110
        assert_eq!(f.frame_count(), 0);
111
    }
112

            
113
    /// edge_access: empty sample buffer yields 0 frames for any nonzero channel count.
114
    #[test]
115
    fn frame_count_empty_samples() {
116
        assert_eq!(frame(48_000, 1, Vec::new()).frame_count(), 0);
117
        assert_eq!(frame(48_000, 2, Vec::new()).frame_count(), 0);
118
        assert_eq!(frame(48_000, u16::MAX, Vec::new()).frame_count(), 0);
119
    }
120

            
121
    /// edge_access: a partial trailing frame is truncated by integer division (5 / 2 == 2).
122
    #[test]
123
    fn frame_count_truncates_partial_frame() {
124
        let f = frame(48_000, 2, vec![0.0, 0.1, 0.2, 0.3, 0.4]);
125
        assert_eq!(f.frame_count(), 2);
126
    }
127

            
128
    /// edge_access: channel count far exceeding the sample count yields 0, never underflow/panic.
129
    #[test]
130
    fn frame_count_channels_exceed_samples() {
131
        let f = frame(48_000, u16::MAX, vec![0.0, 1.0, -1.0]);
132
        assert_eq!(f.frame_count(), 0);
133
    }
134

            
135
    /// edge_access: exactly one full frame across the maximum channel count.
136
    #[test]
137
    fn frame_count_one_full_max_channel_frame() {
138
        let samples = vec![0.25_f32; u16::MAX as usize];
139
        let f = frame(48_000, u16::MAX, samples);
140
        assert_eq!(f.frame_count(), 1);
141
    }
142

            
143
    /// edge_access: non-finite sample values (NaN / +-inf) do not affect the length-only math.
144
    #[test]
145
    fn frame_count_ignores_non_finite_samples() {
146
        let f = frame(
147
            48_000,
148
            2,
149
            vec![f32::NAN, f32::INFINITY, f32::NEG_INFINITY, 0.0],
150
        );
151
        assert_eq!(f.frame_count(), 2);
152
    }
153

            
154
    /// edge_access: a large buffer computes without overflow and matches the plain division.
155
    #[test]
156
    fn frame_count_large_buffer() {
157
        let n = 100_000usize;
158
        let f = frame(48_000, 2, vec![0.0_f32; n]);
159
        assert_eq!(f.frame_count(), n / 2);
160
    }
161

            
162
    // --- round-trip / trait invariants -----------------------------------
163

            
164
    /// round-trip: cloning an `AudioFrame` reproduces an equal value (finite samples).
165
    #[test]
166
    fn frame_clone_round_trip_eq() {
167
        let original = frame(44_100, 2, vec![0.0, 0.5, -0.5, 1.0, -1.0, 0.25]);
168
        let cloned = original.clone();
169
        assert_eq!(original, cloned);
170
        assert_eq!(original.frame_count(), cloned.frame_count());
171
        assert_eq!(original.samples.as_ref(), cloned.samples.as_ref());
172
    }
173

            
174
    /// round-trip: `Option<AudioFrame>` <-> `OptionAudioFrame` preserves the payload both ways.
175
    #[test]
176
    fn option_audio_frame_round_trip() {
177
        let f = frame(48_000, 1, vec![0.1, 0.2, 0.3]);
178

            
179
        let wrapped: OptionAudioFrame = Some(f.clone()).into();
180
        let unwrapped: Option<AudioFrame> = wrapped.into();
181
        assert_eq!(unwrapped, Some(f));
182

            
183
        let none_wrapped: OptionAudioFrame = None.into();
184
        let none_unwrapped: Option<AudioFrame> = none_wrapped.into();
185
        assert_eq!(none_unwrapped, None);
186
    }
187

            
188
    /// numeric edge: `PartialEq` follows IEEE-754 — a NaN sample makes a frame unequal to its
189
    /// clone.
190
    #[test]
191
    fn frame_with_nan_is_not_self_equal() {
192
        let f = frame(48_000, 1, vec![f32::NAN]);
193
        // NaN != NaN, so PartialEq on the sample vec must report inequality.
194
        assert_ne!(f, f.clone());
195
        // ...yet the length-based getter is unaffected.
196
        assert_eq!(f.frame_count(), 1);
197
    }
198

            
199
    // --- AudioConfig: FFI / POD layout + numeric invariants --------------
200

            
201
    /// invariants_hold: `#[repr(C)]` layout is the one the FFI headers assume
202
    /// (u32 + u16 + 2 bytes tail padding, 4-byte aligned). A silent layout
203
    /// change here would corrupt every cross-language `AudioConfig`.
204
    #[test]
205
    fn config_repr_c_layout_is_stable() {
206
        assert_eq!(core::mem::size_of::<AudioConfig>(), 8);
207
        assert_eq!(core::mem::align_of::<AudioConfig>(), 4);
208
    }
209

            
210
    /// numeric: no field is truncated, sign-extended or swapped for any
211
    /// boundary combination — `new` must store both args verbatim.
212
    #[test]
213
    fn config_new_no_field_truncation_sweep() {
214
        const RATES: [u32; 8] = [
215
            0,
216
            1,
217
            8_000,
218
            44_100,
219
            48_000,
220
            192_000,
221
            u16::MAX as u32, // would alias `channels` if the fields were swapped
222
            u32::MAX,
223
        ];
224
        const CHANNELS: [u16; 6] = [0, 1, 2, 8, 255, u16::MAX];
225

            
226
        for &rate in &RATES {
227
            for &ch in &CHANNELS {
228
                let c = AudioConfig::new(rate, ch);
229
                assert_eq!(c.sample_rate, rate, "rate {rate} ch {ch}");
230
                assert_eq!(c.channels, ch, "rate {rate} ch {ch}");
231
                // Round-trip through the struct must be lossless.
232
                assert_eq!(c, AudioConfig::new(c.sample_rate, c.channels));
233
            }
234
        }
235
    }
236

            
237
    /// invariants_hold: `new` performs no normalization — a nonsense config is
238
    /// stored as given and is NOT silently coerced to the default.
239
    #[test]
240
    fn config_new_does_not_normalize() {
241
        let c = AudioConfig::new(0, 0);
242
        assert_ne!(c, AudioConfig::default());
243
        assert_eq!(c.sample_rate, 0);
244
        assert_eq!(c.channels, 0);
245
    }
246

            
247
    /// invariants_hold: `Copy` gives an independent value — mutating the copy
248
    /// must not write through to the original.
249
    #[test]
250
    fn config_copy_is_independent() {
251
        let original = AudioConfig::new(48_000, 2);
252
        let mut copy = original;
253
        copy.sample_rate = 8_000;
254
        copy.channels = 1;
255
        assert_eq!(original.sample_rate, 48_000);
256
        assert_eq!(original.channels, 2);
257
        assert_eq!(copy, AudioConfig::new(8_000, 1));
258
    }
259

            
260
    /// invariants_hold: equal configs dedup in a hash set, distinct ones do not
261
    /// (Eq/Hash agreement under a real hasher, not just `DefaultHasher`).
262
    #[test]
263
    fn config_hash_set_dedup() {
264
        use std::collections::HashSet;
265

            
266
        let mut set = HashSet::new();
267
        assert!(set.insert(AudioConfig::new(48_000, 2)));
268
        assert!(!set.insert(AudioConfig::new(48_000, 2))); // equal -> dedup
269
        assert!(set.insert(AudioConfig::new(48_000, 1))); // channels differ
270
        assert!(set.insert(AudioConfig::new(44_100, 2))); // rate differs
271
        assert!(set.insert(AudioConfig::new(u32::MAX, u16::MAX)));
272
        assert_eq!(set.len(), 4);
273
        assert!(set.contains(&AudioConfig::new(48_000, 2)));
274
    }
275

            
276
    // --- AudioFrame::frame_count: exhaustive invariant sweep --------------
277

            
278
    /// invariants_hold: for every (channels, sample-count) pair,
279
    /// `frame_count()` equals the integer division, never panics, and satisfies
280
    /// `frame_count * channels <= len` with `len - frame_count * channels < channels`.
281
    #[test]
282
    fn frame_count_division_invariant_sweep() {
283
        const CHANNELS: [u16; 9] = [0, 1, 2, 3, 5, 7, 8, 255, u16::MAX];
284

            
285
        for &ch in &CHANNELS {
286
            for len in 0..24usize {
287
                let f = frame(48_000, ch, vec![0.5_f32; len]);
288
                let fc = f.frame_count();
289

            
290
                if ch == 0 {
291
                    // Guarded: must return 0 rather than divide by zero.
292
                    assert_eq!(fc, 0, "ch=0 len={len}");
293
                    continue;
294
                }
295

            
296
                let ch_us = ch as usize;
297
                assert_eq!(fc, len / ch_us, "ch={ch} len={len}");
298
                // No over-counting: the reported frames must fit in the buffer.
299
                let consumed = fc
300
                    .checked_mul(ch_us)
301
                    .expect("frame_count * channels overflowed");
302
                assert!(consumed <= len, "ch={ch} len={len} consumed={consumed}");
303
                // ...and at most one partial frame may be left over.
304
                assert!(len - consumed < ch_us, "ch={ch} len={len}");
305
            }
306
        }
307
    }
308

            
309
    /// edge_access: the boundary around one full max-channel frame —
310
    /// one sample short is 0 frames, one sample over is still 1 (truncation).
311
    #[test]
312
    fn frame_count_max_channel_boundaries() {
313
        let n = u16::MAX as usize;
314
        assert_eq!(frame(48_000, u16::MAX, vec![0.0; n - 1]).frame_count(), 0);
315
        assert_eq!(frame(48_000, u16::MAX, vec![0.0; n]).frame_count(), 1);
316
        assert_eq!(frame(48_000, u16::MAX, vec![0.0; n + 1]).frame_count(), 1);
317
        assert_eq!(frame(48_000, u16::MAX, vec![0.0; 2 * n]).frame_count(), 2);
318
        assert_eq!(
319
            frame(48_000, u16::MAX, vec![0.0; 2 * n - 1]).frame_count(),
320
            1
321
        );
322
    }
323

            
324
    /// invariants_hold: `sample_rate` is not an input to `frame_count` — the
325
    /// extremes must not change the result.
326
    #[test]
327
    fn frame_count_ignores_sample_rate() {
328
        let samples = vec![0.0, 0.1, 0.2, 0.3];
329
        for &rate in &[0u32, 1, 48_000, u32::MAX] {
330
            assert_eq!(
331
                frame(rate, 2, samples.clone()).frame_count(),
332
                2,
333
                "rate={rate}"
334
            );
335
        }
336
    }
337

            
338
    /// invariants_hold: `frame_count` is a pure read — repeated calls agree and
339
    /// the sample buffer is untouched.
340
    #[test]
341
    fn frame_count_is_pure() {
342
        let f = frame(48_000, 2, vec![0.0, 0.1, 0.2, 0.3, 0.4, 0.5]);
343
        let before: Vec<f32> = f.samples.as_ref().to_vec();
344
        let first = f.frame_count();
345
        let second = f.frame_count();
346
        let third = f.frame_count();
347
        assert_eq!(first, 3);
348
        assert_eq!(first, second);
349
        assert_eq!(second, third);
350
        assert_eq!(f.samples.as_ref(), before.as_slice());
351
        assert_eq!(f.samples.len(), 6);
352
    }
353

            
354
    /// edge_access: a frame whose `F32Vec` is backed by a `'static` slice
355
    /// (no heap allocation, `NoDestructor`) must count + drop cleanly.
356
    #[test]
357
    fn frame_count_static_backed_samples() {
358
        static SAMPLES: [f32; 6] = [0.0, 0.5, -0.5, 1.0, -1.0, 0.25];
359

            
360
        let f = AudioFrame {
361
            sample_rate: 48_000,
362
            channels: 2,
363
            samples: F32Vec::from_const_slice(&SAMPLES),
364
        };
365
        assert_eq!(f.frame_count(), 3);
366
        assert_eq!(f.samples.as_ref(), &SAMPLES[..]);
367

            
368
        // Cloning a static-backed vec must not alias the static into a heap free.
369
        let cloned = f.clone();
370
        assert_eq!(cloned, f);
371
        drop(f);
372
        assert_eq!(cloned.frame_count(), 3);
373
    }
374

            
375
    /// edge_access: an empty `F32Vec::new()` (null-ptr, zero-cap vec) is a valid
376
    /// zero-frame buffer and must not panic on read, clone or drop.
377
    #[test]
378
    fn frame_count_default_f32vec_is_empty() {
379
        let f = AudioFrame {
380
            sample_rate: 48_000,
381
            channels: 2,
382
            samples: F32Vec::new(),
383
        };
384
        assert_eq!(f.frame_count(), 0);
385
        assert!(f.samples.is_empty());
386
        assert_eq!(f.samples.len(), 0);
387
        assert_eq!(f.samples.as_ref(), &[] as &[f32]);
388
        assert_eq!(f.clone(), f);
389
    }
390

            
391
    /// invariants_hold: building the sample vec through `FromIterator` yields the
392
    /// same frame count as `from_vec`.
393
    #[test]
394
    fn frame_count_from_iterator_matches_from_vec() {
395
        let via_iter = AudioFrame {
396
            sample_rate: 48_000,
397
            channels: 2,
398
            samples: (0..10).map(|i| i as f32).collect::<F32Vec>(),
399
        };
400
        let via_vec = frame(48_000, 2, (0..10).map(|i| i as f32).collect::<Vec<f32>>());
401
        assert_eq!(via_iter, via_vec);
402
        assert_eq!(via_iter.frame_count(), 5);
403
        assert_eq!(via_iter.frame_count(), via_vec.frame_count());
404
    }
405

            
406
    /// edge_access: out-of-bounds sample reads return `None` rather than panicking,
407
    /// including on the last valid index of the final counted frame.
408
    #[test]
409
    fn frame_sample_access_is_bounds_checked() {
410
        let f = frame(48_000, 2, vec![0.0, 0.1, 0.2, 0.3]);
411
        let last = f.frame_count() * f.channels as usize - 1;
412
        assert_eq!(f.samples.get(last), Some(&0.3));
413
        assert_eq!(f.samples.get(f.samples.len()), None);
414
        assert_eq!(f.samples.get(usize::MAX), None);
415
    }
416

            
417
    /// numeric: extreme / non-finite / signed-zero samples survive a clone
418
    /// bit-for-bit, and none of them perturb the length-only getter.
419
    #[test]
420
    fn frame_extreme_sample_values_preserved_bitwise() {
421
        let raw = vec![
422
            f32::MIN,
423
            f32::MAX,
424
            f32::MIN_POSITIVE,
425
            -f32::MIN_POSITIVE,
426
            0.0,
427
            -0.0,
428
            f32::EPSILON,
429
            1e-45, // subnormal
430
        ];
431
        let f = frame(48_000, 2, raw.clone());
432
        assert_eq!(f.frame_count(), 4);
433

            
434
        let cloned = f.clone();
435
        let got: Vec<u32> = cloned
436
            .samples
437
            .as_ref()
438
            .iter()
439
            .map(|s| s.to_bits())
440
            .collect();
441
        let want: Vec<u32> = raw.iter().map(|s| s.to_bits()).collect();
442
        assert_eq!(
443
            got, want,
444
            "clone must be bit-exact (incl. -0.0 and subnormals)"
445
        );
446

            
447
        // Sanity: -0.0 == 0.0 under PartialEq but their bits differ, so a
448
        // value-level compare still says equal while the bit compare above is strict.
449
        assert_eq!(cloned, f);
450
        assert_ne!(0.0_f32.to_bits(), (-0.0_f32).to_bits());
451
    }
452

            
453
    /// invariants_hold: `PartialEq` on `AudioFrame` discriminates the header
454
    /// fields, not just the samples.
455
    #[test]
456
    fn frame_eq_discriminates_header_fields() {
457
        let samples = vec![0.0, 0.5, -0.5, 1.0];
458
        let base = frame(48_000, 2, samples.clone());
459
        assert_eq!(base, frame(48_000, 2, samples.clone()));
460
        assert_ne!(base, frame(44_100, 2, samples.clone()));
461
        assert_ne!(base, frame(48_000, 1, samples.clone()));
462
        assert_ne!(base, frame(48_000, 2, vec![0.0, 0.5, -0.5]));
463
        // Same frame_count (2) via different (channels, len) pairs is still not equal.
464
        assert_eq!(frame(48_000, 1, vec![0.0, 0.5]).frame_count(), 2);
465
        assert_ne!(base, frame(48_000, 1, vec![0.0, 0.5]));
466
    }
467

            
468
    /// edge_access: repeated clone/drop cycles of a heap-backed frame must not
469
    /// double-free or corrupt the buffer (FFI vec destructor regression guard).
470
    #[test]
471
    fn frame_repeated_clone_drop_is_stable() {
472
        let original = frame(48_000, 2, (0..64).map(|i| i as f32).collect::<Vec<f32>>());
473
        for _ in 0..64 {
474
            let c = original.clone();
475
            assert_eq!(c.frame_count(), 32);
476
            assert_eq!(c.samples.as_ref(), original.samples.as_ref());
477
            drop(c);
478
        }
479
        // The original survived every clone + drop.
480
        assert_eq!(original.frame_count(), 32);
481
        assert_eq!(original.samples.len(), 64);
482
    }
483

            
484
    // --- OptionAudioFrame (FFI option wrapper) ----------------------------
485

            
486
    /// invariants_hold: the FFI option defaults to `None` and its predicates agree.
487
    #[test]
488
    fn option_audio_frame_predicates() {
489
        let none = OptionAudioFrame::default();
490
        assert!(none.is_none());
491
        assert!(!none.is_some());
492
        assert!(none.as_ref().is_none());
493
        assert!(none.as_option().is_none());
494

            
495
        let some: OptionAudioFrame = Some(frame(48_000, 2, vec![0.0, 1.0])).into();
496
        assert!(some.is_some());
497
        assert!(!some.is_none());
498
        assert_eq!(some.as_ref().map(AudioFrame::frame_count), Some(1));
499
    }
500

            
501
    /// edge_access: `into_option` clones out of a `&self`, so calling it twice must
502
    /// yield two equal, independently-owned frames (no move-out / double-free).
503
    #[test]
504
    fn option_audio_frame_into_option_twice() {
505
        let wrapped: OptionAudioFrame = Some(frame(48_000, 2, vec![0.0, 0.5, -0.5, 1.0])).into();
506
        let a = wrapped.into_option().expect("some");
507
        let b = wrapped.into_option().expect("some");
508
        assert_eq!(a, b);
509
        assert_eq!(a.frame_count(), 2);
510
        drop(a);
511
        // `b` and `wrapped` must still be intact after `a` is dropped.
512
        assert_eq!(b.frame_count(), 2);
513
        assert!(wrapped.is_some());
514
    }
515

            
516
    /// invariants_hold: `replace` returns the previous value (mem::replace semantics)
517
    /// and installs the new one.
518
    #[test]
519
    fn option_audio_frame_replace_returns_previous() {
520
        let mut slot = OptionAudioFrame::None;
521
        let prev = slot.replace(frame(48_000, 1, vec![0.0, 0.1]));
522
        assert!(prev.is_none());
523
        assert_eq!(slot.as_ref().map(AudioFrame::frame_count), Some(2));
524

            
525
        let prev = slot.replace(frame(48_000, 2, vec![0.0, 0.1, 0.2, 0.3]));
526
        assert_eq!(prev.as_ref().map(AudioFrame::frame_count), Some(2));
527
        assert_eq!(slot.as_ref().map(AudioFrame::frame_count), Some(2));
528
        assert_eq!(slot.as_ref().map(|f| f.channels), Some(2));
529
    }
530

            
531
    /// edge_access: `as_mut` hands out a live borrow — mutating the samples through it
532
    /// must be visible in the wrapper's `frame_count`.
533
    #[test]
534
    fn option_audio_frame_as_mut_mutation_visible() {
535
        let mut slot: OptionAudioFrame = Some(frame(48_000, 2, vec![0.0, 0.1, 0.2, 0.3])).into();
536
        assert_eq!(slot.as_ref().map(AudioFrame::frame_count), Some(2));
537

            
538
        if let Some(f) = slot.as_mut() {
539
            f.channels = 0; // divide-by-zero guard must engage through the wrapper too
540
        }
541
        assert_eq!(slot.as_ref().map(AudioFrame::frame_count), Some(0));
542

            
543
        if let Some(f) = slot.as_mut() {
544
            f.channels = 1;
545
        }
546
        assert_eq!(slot.as_ref().map(AudioFrame::frame_count), Some(4));
547
    }
548

            
549
    /// round-trip: an empty-sample frame survives the `Option` <-> FFI-option
550
    /// round-trip (the zero-length vec is the likeliest null-ptr edge).
551
    #[test]
552
    fn option_audio_frame_round_trip_empty_samples() {
553
        let f = frame(48_000, 2, Vec::new());
554
        let wrapped: OptionAudioFrame = Some(f.clone()).into();
555
        let back: Option<AudioFrame> = wrapped.into();
556
        let back = back.expect("some");
557
        assert_eq!(back, f);
558
        assert_eq!(back.frame_count(), 0);
559
        assert!(back.samples.is_empty());
560
    }
561
}