oximedia-aaf 0.1.2

Advanced Authoring Format (AAF) support for OxiMedia - SMPTE ST 377-1 compliant
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
//! `OxiMedia` AAF - Advanced Authoring Format support
//!
//! This crate provides SMPTE ST 377-1 compliant AAF (Advanced Authoring Format)
//! reading and writing for professional post-production workflows.
//!
//! # Features
//!
//! - Full SMPTE ST 377-1 (AAF Object Specification) support
//! - SMPTE ST 2001 (AAF Operational Patterns) support
//! - Microsoft Structured Storage (compound file) parsing
//! - Complete object model (Mobs, Segments, Components, Effects)
//! - Dictionary support with extensibility
//! - Essence reference handling (embedded and external)
//! - Timeline and edit rate management
//! - Metadata preservation
//! - Conversion to `OpenTimelineIO` and EDL formats
//! - Read and write capability
//! - No unsafe code
//!
//! # AAF Structure
//!
//! AAF files use Microsoft Structured Storage format (compound files) and contain:
//! - Header: File identification and version
//! - Dictionary: Class, property, and type definitions
//! - Content Storage: Mobs (Master, Source, Composition)
//! - Essence: Media data (embedded or external references)
//!
//! # Example
//!
//! ```rust,no_run
//! use oximedia_aaf::{AafFile, AafReader};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open an AAF file
//! let mut reader = AafReader::open("timeline.aaf")?;
//! let aaf = reader.read()?;
//!
//! // Access composition mobs
//! for comp_mob in aaf.composition_mobs() {
//!     println!("Composition: {}", comp_mob.name());
//!     for track in comp_mob.tracks() {
//!         println!("  Track: {}", track.name);
//!     }
//! }
//! # Ok(())
//! # }
//! ```

#![allow(
    clippy::cast_possible_truncation,
    clippy::cast_precision_loss,
    clippy::cast_sign_loss,
    clippy::cast_lossless,
    clippy::cast_possible_wrap,
    dead_code,
    clippy::pedantic
)]

pub mod aaf_export;
pub mod composition;
pub mod composition_mob;
pub mod convert;
pub mod davinci_edl;
pub mod descriptor;
pub mod dict_cache;
pub mod dictionary;
pub mod edl_export;
pub mod effect_def;
pub mod effects;
pub mod essence;
pub mod flatten;
pub mod inspector;
pub mod interchange;
pub mod media_data;
pub mod media_file_ref;
pub mod merge;
pub mod metadata;
pub mod mob_slot;
pub mod mob_traversal;
pub mod object_model;
pub mod operation_group;
pub mod parameter;
pub mod property_value;
pub mod scope;
pub mod search;
pub mod selector;
pub mod smpte_metadata;
pub mod source_clip;
pub mod streaming;
pub mod structured_storage;
pub mod timeline;
pub mod timeline_export;
pub mod timeline_mob;
pub mod track_group;
pub mod transition_def;
pub mod validate;
pub mod writer;
pub mod xml_bridge;

use std::collections::HashMap;
use std::io::{Read, Seek};
use std::path::Path;
use thiserror::Error;
use uuid::Uuid;

pub use composition::{
    CompositionMob, Effect, EffectParameter, FadeType, Filler, Sequence, SequenceComponent,
    SourceClip, Track, TrackType, Transition, UsageCode,
};
pub use convert::{
    EdlExporter, Timeline, TimelineClip, TimelineConverter, TimelineTrack, XmlExporter,
};
pub use dictionary::{Auid, DataDefinition, Dictionary};
pub use essence::{EssenceAccess, EssenceDescriptor, EssenceReference};
pub use metadata::{Comment, KlvData, TaggedValue, Timecode as AafTimecode};
pub use object_model::{Component, Header, Mob, MobSlot, Segment};
pub use search::{AafQuery, AafSearcher, MobRef, MobTypeKind};
pub use structured_storage::{StorageReader, StorageWriter};
pub use timeline::{EditRate, Position};
pub use validate::{AafValidator, IssueSeverity, ValidationIssue, ValidationReport};
pub use writer::AafWriter;

/// AAF error types
#[derive(Error, Debug)]
pub enum AafError {
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Invalid AAF file: {0}")]
    InvalidFile(String),

    #[error("Unsupported AAF version: {0}.{1}")]
    UnsupportedVersion(u16, u16),

    #[error("Invalid structured storage: {0}")]
    InvalidStructuredStorage(String),

    #[error("Object not found: {0}")]
    ObjectNotFound(String),

    #[error("Property not found: {0}")]
    PropertyNotFound(String),

    #[error("Invalid class: {0}")]
    InvalidClass(String),

    #[error("Invalid property type: {0}")]
    InvalidPropertyType(String),

    #[error("Reference resolution failed: {0}")]
    ReferenceResolutionFailed(String),

    #[error("Dictionary error: {0}")]
    DictionaryError(String),

    #[error("Essence error: {0}")]
    EssenceError(String),

    #[error("Timeline error: {0}")]
    TimelineError(String),

    #[error("Conversion error: {0}")]
    ConversionError(String),

    #[error("Write error: {0}")]
    WriteError(String),

    #[error("Parse error: {0}")]
    ParseError(String),
}

pub type Result<T> = std::result::Result<T, AafError>;

/// Main AAF file structure
///
/// Represents a complete AAF file with header, dictionary, and content.
#[derive(Debug, Clone)]
pub struct AafFile {
    pub(crate) header: Header,
    pub(crate) dictionary: Dictionary,
    pub(crate) content_storage: ContentStorage,
    pub(crate) essence_data: Vec<EssenceData>,
}

impl AafFile {
    /// Create a new empty AAF file
    #[must_use]
    pub fn new() -> Self {
        Self {
            header: Header::new(),
            dictionary: Dictionary::new(),
            content_storage: ContentStorage::new(),
            essence_data: Vec::new(),
        }
    }

    /// Get the file header
    #[must_use]
    pub fn header(&self) -> &Header {
        &self.header
    }

    /// Get the dictionary
    #[must_use]
    pub fn dictionary(&self) -> &Dictionary {
        &self.dictionary
    }

    /// Get the content storage
    #[must_use]
    pub fn content_storage(&self) -> &ContentStorage {
        &self.content_storage
    }

    /// Get all composition mobs
    #[must_use]
    pub fn composition_mobs(&self) -> Vec<&CompositionMob> {
        self.content_storage.composition_mobs()
    }

    /// Get all master mobs
    #[must_use]
    pub fn master_mobs(&self) -> Vec<&Mob> {
        self.content_storage.master_mobs()
    }

    /// Get all source mobs
    #[must_use]
    pub fn source_mobs(&self) -> Vec<&Mob> {
        self.content_storage.source_mobs()
    }

    /// Find a mob by ID
    #[must_use]
    pub fn find_mob(&self, mob_id: &Uuid) -> Option<&Mob> {
        self.content_storage.find_mob(mob_id)
    }

    /// Get all essence data
    #[must_use]
    pub fn essence_data(&self) -> &[EssenceData] {
        &self.essence_data
    }

    /// Get the file's edit rate (from first composition mob)
    #[must_use]
    pub fn edit_rate(&self) -> Option<EditRate> {
        self.composition_mobs()
            .first()
            .and_then(|mob| mob.edit_rate())
    }

    /// Get file duration in edit units
    #[must_use]
    pub fn duration(&self) -> Option<i64> {
        self.composition_mobs()
            .first()
            .and_then(|mob| mob.duration())
    }
}

impl Default for AafFile {
    fn default() -> Self {
        Self::new()
    }
}

/// Content storage containing all mobs
#[derive(Debug, Clone)]
pub struct ContentStorage {
    mobs: HashMap<Uuid, Mob>,
    composition_mobs: HashMap<Uuid, CompositionMob>,
}

impl ContentStorage {
    /// Create new empty content storage
    #[must_use]
    pub fn new() -> Self {
        Self {
            mobs: HashMap::new(),
            composition_mobs: HashMap::new(),
        }
    }

    /// Add a mob
    pub fn add_mob(&mut self, mob: Mob) {
        let id = mob.mob_id();
        self.mobs.insert(id, mob);
    }

    /// Add a composition mob
    pub fn add_composition_mob(&mut self, comp_mob: CompositionMob) {
        let id = comp_mob.mob_id();
        self.composition_mobs.insert(id, comp_mob);
    }

    /// Get all composition mobs
    #[must_use]
    pub fn composition_mobs(&self) -> Vec<&CompositionMob> {
        self.composition_mobs.values().collect()
    }

    /// Get all master mobs
    #[must_use]
    pub fn master_mobs(&self) -> Vec<&Mob> {
        self.mobs.values().filter(|m| m.is_master_mob()).collect()
    }

    /// Get all source mobs
    #[must_use]
    pub fn source_mobs(&self) -> Vec<&Mob> {
        self.mobs.values().filter(|m| m.is_source_mob()).collect()
    }

    /// Find a mob by ID
    #[must_use]
    pub fn find_mob(&self, mob_id: &Uuid) -> Option<&Mob> {
        self.mobs.get(mob_id)
    }

    /// Find a composition mob by ID
    #[must_use]
    pub fn find_composition_mob(&self, mob_id: &Uuid) -> Option<&CompositionMob> {
        self.composition_mobs.get(mob_id)
    }

    /// Find a composition mob by name (first match).
    ///
    /// Performs a linear scan over all composition mobs comparing names.
    /// Returns `None` if no mob with that name exists.
    #[must_use]
    pub fn find_composition_mob_by_name(&self, name: &str) -> Option<&CompositionMob> {
        self.composition_mobs.values().find(|m| m.name() == name)
    }

    /// Deep-clone a composition mob with a fresh UUID.
    ///
    /// The cloned mob is an independent copy of the original; all tracks, sequences,
    /// and clips are preserved but the top-level `mob_id` is replaced with a new
    /// randomly-generated UUID so the clone does not conflict with the original.
    ///
    /// # Errors
    ///
    /// Returns `AafError::ObjectNotFound` if no composition mob with `id` exists.
    pub fn clone_mob(&self, id: Uuid) -> Result<CompositionMob> {
        let original = self
            .composition_mobs
            .get(&id)
            .ok_or_else(|| AafError::ObjectNotFound(format!("Composition mob {id} not found")))?;

        // Clone the whole structure and assign a fresh UUID
        let mut cloned = original.clone();
        let new_id = Uuid::new_v4();
        *cloned.mob_mut().mob_id_mut() = new_id;
        Ok(cloned)
    }

    /// Validate the content storage and return a report.
    ///
    /// Convenience wrapper around `AafValidator::validate`.
    /// Returns errors and warnings about structural integrity of the stored mobs.
    #[must_use]
    pub fn validate(&self) -> validate::ValidationReport {
        validate::AafValidator::validate(self)
    }
}

impl Default for ContentStorage {
    fn default() -> Self {
        Self::new()
    }
}

/// Essence data stored in the AAF file
#[derive(Debug, Clone)]
pub struct EssenceData {
    mob_id: Uuid,
    data: Vec<u8>,
}

impl EssenceData {
    /// Create new essence data
    #[must_use]
    pub fn new(mob_id: Uuid, data: Vec<u8>) -> Self {
        Self { mob_id, data }
    }

    /// Get the mob ID
    #[must_use]
    pub fn mob_id(&self) -> Uuid {
        self.mob_id
    }

    /// Get the essence data
    #[must_use]
    pub fn data(&self) -> &[u8] {
        &self.data
    }
}

/// AAF file reader
pub struct AafReader<R: Read + Seek> {
    storage: StorageReader<R>,
}

impl<R: Read + Seek> AafReader<R> {
    /// Create a new AAF reader from a readable source
    pub fn new(reader: R) -> Result<Self> {
        let storage = StorageReader::new(reader)?;
        Ok(Self { storage })
    }

    /// Read the complete AAF file
    pub fn read(&mut self) -> Result<AafFile> {
        // Read header from root entry
        let header = self.read_header()?;

        // Read dictionary
        let dictionary = self.read_dictionary()?;

        // Read content storage
        let content_storage = self.read_content_storage(&dictionary)?;

        // Read essence data
        let essence_data = self.read_essence_data()?;

        Ok(AafFile {
            header,
            dictionary,
            content_storage,
            essence_data,
        })
    }

    fn read_header(&mut self) -> Result<Header> {
        // Implementation in object_model module
        object_model::read_header(&mut self.storage)
    }

    fn read_dictionary(&mut self) -> Result<Dictionary> {
        // Implementation in dictionary module
        dictionary::read_dictionary(&mut self.storage)
    }

    fn read_content_storage(&mut self, dictionary: &Dictionary) -> Result<ContentStorage> {
        // Implementation in object_model module
        object_model::read_content_storage(&mut self.storage, dictionary)
    }

    fn read_essence_data(&mut self) -> Result<Vec<EssenceData>> {
        // Implementation in essence module
        essence::read_essence_data(&mut self.storage)
    }
}

impl AafReader<std::fs::File> {
    /// Open an AAF file from a path
    pub fn open<P: AsRef<Path>>(path: P) -> Result<Self> {
        let file = std::fs::File::open(path)?;
        Self::new(file)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use composition::{Filler, Sequence, SequenceComponent, SourceClip, Track, TrackType};
    use dictionary::Auid;
    use object_model::{Mob, MobType};
    use timeline::{EditRate, Position};

    #[test]
    fn test_aaf_file_creation() {
        let aaf = AafFile::new();
        assert!(aaf.composition_mobs().is_empty());
        assert!(aaf.master_mobs().is_empty());
        assert!(aaf.source_mobs().is_empty());
    }

    #[test]
    fn test_content_storage() {
        let storage = ContentStorage::new();
        assert!(storage.composition_mobs().is_empty());
        assert!(storage.master_mobs().is_empty());
    }

    #[test]
    fn test_essence_data() {
        let mob_id = Uuid::new_v4();
        let data = vec![1, 2, 3, 4];
        let essence = EssenceData::new(mob_id, data.clone());
        assert_eq!(essence.mob_id(), mob_id);
        assert_eq!(essence.data(), &data);
    }

    // --- Task 1: find_composition_mob_by_name ---

    #[test]
    fn test_find_composition_mob_by_name_found() {
        let mut storage = ContentStorage::new();
        let mob_id = Uuid::new_v4();
        storage.add_composition_mob(CompositionMob::new(mob_id, "My Comp"));

        let found = storage.find_composition_mob_by_name("My Comp");
        assert!(found.is_some(), "should find mob by name");
        assert_eq!(found.map(|m| m.mob_id()), Some(mob_id));
    }

    #[test]
    fn test_find_composition_mob_by_name_not_found() {
        let mut storage = ContentStorage::new();
        storage.add_composition_mob(CompositionMob::new(Uuid::new_v4(), "Other"));
        let found = storage.find_composition_mob_by_name("Missing");
        assert!(found.is_none());
    }

    // --- Task 2: Display for EditRate, Position, TimelineRange ---

    #[test]
    fn test_display_edit_rate_integer() {
        let rate = EditRate::new(25, 1);
        assert_eq!(rate.to_string(), "25");
    }

    #[test]
    fn test_display_edit_rate_fractional() {
        let rate = EditRate::new(30000, 1001);
        assert_eq!(rate.to_string(), "30000/1001");
    }

    #[test]
    fn test_display_position() {
        let pos = Position::new(42);
        assert_eq!(pos.to_string(), "42");
    }

    #[test]
    fn test_display_timeline_range() {
        use timeline::TimelineRange;
        let range = TimelineRange::new(Position::new(10), 50);
        // [10..60)
        assert_eq!(range.to_string(), "[10..60)");
    }

    // --- Task 3: Validation pass ---

    #[test]
    fn test_validate_valid_storage() {
        let mut storage = ContentStorage::new();
        let source_id = Uuid::new_v4();
        storage.add_mob(Mob::new(
            source_id,
            "Source.mov".to_string(),
            MobType::Source,
        ));

        let mut comp = CompositionMob::new(Uuid::new_v4(), "Edit");
        let mut seq = Sequence::new(Auid::PICTURE);
        seq.add_component(SequenceComponent::SourceClip(SourceClip::new(
            100,
            Position::zero(),
            source_id,
            1,
        )));
        let mut track = Track::new(1, "V", EditRate::PAL_25, TrackType::Picture);
        track.set_sequence(seq);
        comp.add_track(track);
        storage.add_composition_mob(comp);

        let report = storage.validate();
        assert!(
            report.is_valid(),
            "Expected valid storage; errors: {:?}",
            report.errors
        );
    }

    #[test]
    fn test_validate_missing_name_is_error() {
        let mut storage = ContentStorage::new();
        storage.add_composition_mob(CompositionMob::new(Uuid::new_v4(), ""));
        let report = storage.validate();
        assert!(!report.is_valid());
    }

    #[test]
    fn test_validate_unresolved_ref_is_error() {
        let mut storage = ContentStorage::new();
        let bogus = Uuid::new_v4(); // never registered

        let mut comp = CompositionMob::new(Uuid::new_v4(), "Broken");
        let mut seq = Sequence::new(Auid::PICTURE);
        seq.add_component(SequenceComponent::SourceClip(SourceClip::new(
            50,
            Position::zero(),
            bogus,
            1,
        )));
        let mut track = Track::new(1, "V", EditRate::PAL_25, TrackType::Picture);
        track.set_sequence(seq);
        comp.add_track(track);
        storage.add_composition_mob(comp);

        let report = storage.validate();
        assert!(!report.is_valid());
        assert!(report
            .errors
            .iter()
            .any(|e| e.message.contains("unknown mob")));
    }

    // --- Task 4: Round-trip test ---

    #[test]
    fn test_round_trip_build_verify() {
        // Programmatic round-trip: build structure → add to ContentStorage → read back.
        // (No binary serialisation in this simplified implementation, but the logical
        //  structure is fully preserved in memory.)
        let source_mob_id = Uuid::new_v4();
        let source_slot_id = 1u32;
        let clip_length: i64 = 200;
        let clip_start = Position::new(10);
        let edit_rate = EditRate::FILM_24;
        let comp_name = "RoundTripComp";

        // Build
        let mut storage = ContentStorage::new();
        storage.add_mob(Mob::new(
            source_mob_id,
            "source.mov".to_string(),
            MobType::Source,
        ));

        let comp_id = Uuid::new_v4();
        let mut comp = CompositionMob::new(comp_id, comp_name);
        let mut seq = Sequence::new(Auid::PICTURE);
        seq.add_component(SequenceComponent::SourceClip(SourceClip::new(
            clip_length,
            clip_start,
            source_mob_id,
            source_slot_id,
        )));
        let mut track = Track::new(1, "Video", edit_rate, TrackType::Picture);
        track.set_sequence(seq);
        comp.add_track(track);
        storage.add_composition_mob(comp);

        // Verify round-trip: all fields accessible after storage
        let found = storage
            .find_composition_mob(&comp_id)
            .expect("comp mob must be in storage");
        assert_eq!(found.name(), comp_name);
        assert_eq!(found.mob_id(), comp_id);

        let tracks = found.tracks();
        assert_eq!(tracks.len(), 1);
        let track = &tracks[0];
        assert_eq!(track.edit_rate, edit_rate);

        let clips = track.source_clips();
        assert_eq!(clips.len(), 1);
        let clip = clips[0];
        assert_eq!(clip.length, clip_length);
        assert_eq!(clip.start_time, clip_start);
        assert_eq!(clip.source_mob_id, source_mob_id);
        assert_eq!(clip.source_mob_slot_id, source_slot_id);

        // Validation must pass
        let report = storage.validate();
        assert!(
            report.is_valid(),
            "Round-trip storage must be valid; errors: {:?}",
            report.errors
        );
    }

    // --- Task 4: Filler and Transition in round-trip ---

    #[test]
    fn test_round_trip_with_filler() {
        let mut storage = ContentStorage::new();
        let comp_id = Uuid::new_v4();
        let mut comp = CompositionMob::new(comp_id, "FillerComp");
        let mut seq = Sequence::new(Auid::PICTURE);
        seq.add_component(SequenceComponent::Filler(Filler::new(50)));
        let mut track = Track::new(1, "V", EditRate::PAL_25, TrackType::Picture);
        track.set_sequence(seq);
        comp.add_track(track);
        storage.add_composition_mob(comp);

        let found = storage
            .find_composition_mob(&comp_id)
            .expect("comp mob must exist");
        let duration = found.duration();
        assert_eq!(
            duration,
            Some(50),
            "Duration should equal the filler length"
        );
    }

    // --- Task 5: Mob cloning ---

    #[test]
    fn test_clone_mob_creates_fresh_uuid() {
        let mut storage = ContentStorage::new();
        let original_id = Uuid::new_v4();
        let comp = CompositionMob::new(original_id, "Original");
        storage.add_composition_mob(comp);

        let cloned = storage
            .clone_mob(original_id)
            .expect("clone should succeed");

        assert_ne!(
            cloned.mob_id(),
            original_id,
            "Cloned mob must have a different UUID"
        );
        assert_eq!(cloned.name(), "Original", "Name should be preserved");
    }

    #[test]
    fn test_clone_mob_deep_copies_tracks() {
        let mut storage = ContentStorage::new();
        let original_id = Uuid::new_v4();

        let mut comp = CompositionMob::new(original_id, "WithTracks");
        let seq = Sequence::new(Auid::PICTURE);
        let mut track = Track::new(1, "V", EditRate::PAL_25, TrackType::Picture);
        track.set_sequence(seq);
        comp.add_track(track);
        storage.add_composition_mob(comp);

        let cloned = storage
            .clone_mob(original_id)
            .expect("clone should succeed");

        // Clone has same tracks
        assert_eq!(cloned.tracks().len(), 1);
        // Original still intact
        let original = storage
            .find_composition_mob(&original_id)
            .expect("original still there");
        assert_eq!(original.tracks().len(), 1);
    }

    #[test]
    fn test_clone_mob_not_found_returns_error() {
        let storage = ContentStorage::new();
        let bogus_id = Uuid::new_v4();
        let result = storage.clone_mob(bogus_id);
        assert!(result.is_err());
    }
}