|
| 1 | +#[cfg(test)] |
| 2 | +mod tests { |
| 3 | + use re_chunk::{Chunk, ChunkId}; |
| 4 | + use re_data_loader::{DataLoaderSettings, LoadedData, loader_mcap::load_mcap}; |
| 5 | + use re_mcap::layers::SelectedLayers; |
| 6 | + |
| 7 | + // Load an MCAP file into a list of chunks. |
| 8 | + fn load_mcap_chunks(path: &std::path::Path) -> Vec<Chunk> { |
| 9 | + println!("Loading MCAP file: {}", path.display()); |
| 10 | + let mcap_data = std::fs::read(path).unwrap(); |
| 11 | + let (tx, rx) = std::sync::mpsc::channel(); |
| 12 | + let settings = DataLoaderSettings::recommended("test"); |
| 13 | + load_mcap(&mcap_data, &settings, &tx, &SelectedLayers::All, false).unwrap(); |
| 14 | + drop(tx); |
| 15 | + |
| 16 | + // Collect chunks |
| 17 | + rx.iter() |
| 18 | + .filter_map(|res| { |
| 19 | + if let LoadedData::Chunk(_, _, chunk) = res { |
| 20 | + Some(chunk) |
| 21 | + } else { |
| 22 | + None |
| 23 | + } |
| 24 | + }) |
| 25 | + .collect() |
| 26 | + } |
| 27 | + |
| 28 | + // Compare chunks based on their debug representation. |
| 29 | + // Chunks are sorted by entity path and row ids are cleared to make comparison stable. |
| 30 | + fn assert_chunk_snapshot(mut chunks: Vec<Chunk>) { |
| 31 | + chunks.sort_by_key(|chunk| chunk.entity_path().to_string()); |
| 32 | + let clean_chunks: Vec<Chunk> = chunks |
| 33 | + .into_iter() |
| 34 | + .map(|chunk| { |
| 35 | + chunk |
| 36 | + .with_id(ChunkId::from_u128(123_456_789_123_456_789_123_456_789)) |
| 37 | + .zeroed() |
| 38 | + }) |
| 39 | + .collect(); |
| 40 | + insta::assert_debug_snapshot!(clean_chunks); |
| 41 | + } |
| 42 | + |
| 43 | + #[test] |
| 44 | + fn test_mcap_loader() { |
| 45 | + insta::glob!("assets/*.mcap", |path| { |
| 46 | + let chunks = load_mcap_chunks(path); |
| 47 | + assert_chunk_snapshot(chunks); |
| 48 | + }); |
| 49 | + } |
| 50 | +} |
0 commit comments