You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This test checks if files are the same after reading & writing:
use ilda_opt::writer::SectionWriter;use std::io::Cursor;use std::io::Read;use std::io::Write;#[test]fntest_read_write_compare(){let test_files_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("test_files");assert!(test_files_path.exists());assert!(test_files_path.is_dir());letmut total_files = 0;letmut unequal_files = 0;for entry in walkdir::WalkDir::new(test_files_path){let entry = entry.unwrap();let path = entry.path();let ext = path.extension().and_then(|s| s.to_str());if ext != Some("ild") && ext != Some("ILD"){continue;}// Read the entire file into a bufferletmut in_file = std::fs::File::open(path).unwrap();letmut read_buffer = Vec::new();
in_file.read_to_end(&mut read_buffer).unwrap();// Create a cursor for the buffer to use with SectionReaderlet cursor = Cursor::new(&read_buffer);letmut reader = ilda_idtf::SectionReader::new(cursor);/* println!( "Reading \"{}\"", path.file_stem().unwrap().to_str().unwrap() ); */// Create a new buffer for writingletmut write_buffer = Vec::new();letmut writer = SectionWriter::new(Cursor::new(&mut write_buffer));loop{let section = match reader.read_next(){Err(err) => panic!(" failed to read section header: {}", err),Ok(None) => break,Ok(Some(section)) => section,};// Write the header
writer.write_header(section.header).unwrap();match section.reader{
ilda_idtf::SubsectionReaderKind::Coords3dIndexedColor(mut r) => {whileletSome(t) = r.read_next().unwrap(){
writer.write_coords_3d_indexed_color(t).unwrap();}}
ilda_idtf::SubsectionReaderKind::Coords2dIndexedColor(mut r) => {whileletSome(t) = r.read_next().unwrap(){
writer.write_coords_2d_indexed_color(t).unwrap();}}
ilda_idtf::SubsectionReaderKind::ColorPalette(mut r) => {whileletSome(t) = r.read_next().unwrap(){
writer.write_color_palette(t).unwrap();}}
ilda_idtf::SubsectionReaderKind::Coords3dTrueColor(mut r) => {whileletSome(t) = r.read_next().unwrap(){
writer.write_coords_3d_true_color(t).unwrap();}}
ilda_idtf::SubsectionReaderKind::Coords2dTrueColor(mut r) => {whileletSome(t) = r.read_next().unwrap(){
writer.write_coords_2d_true_color(t).unwrap();}}}}// Write to file <original_file_name>.out.ildletmut out_file = std::fs::File::create(path.with_extension("out.ild")).unwrap();
out_file.write_all(&write_buffer).unwrap();
total_files += 1;// Compare the original buffer with the written buffer/* assert_eq!( buffer, write_buffer, "Buffers do not match for file: {:?}", path ); */if read_buffer != write_buffer {println!("Buffers do not match for file: {:?}", path);
unequal_files += 1;}}println!("Total files: {}", total_files);println!("Unequal files: {}", unequal_files);assert_eq!(unequal_files, 0);}
I ran the test on all the test_files.
There are 86 files.
The test succeeds for all except 2:
running 1 test
Buffers do not match for file: "test_files\shownet\ILDA_Files_ShowNET_SD-Card_1_0\033.ild"
Buffers do not match for file: "test_files\shownet\ILDA_Files_ShowNET_SD-Card_1_0\059.ild"
Total files: 86
Unequal files: 2
Maybe it's worth investigating why those 2 files fail, but the writer is a direct "port" of the reader and seems to work for normal files :)
The text was updated successfully, but these errors were encountered:
I wrote this ILDA writer based on your ILDA reader:
This test checks if files are the same after reading & writing:
I ran the test on all the
test_files
.There are 86 files.
The test succeeds for all except 2:
Maybe it's worth investigating why those 2 files fail, but the writer is a direct "port" of the reader and seems to work for normal files :)
The text was updated successfully, but these errors were encountered: