Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: create file then append data #173

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions tests/write_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,82 @@ fn append_file() {
volume_mgr.close_volume(volume).expect("close volume");
}

#[test]
fn create_file_then_append() {
let time_source = utils::make_time_source();
let disk = utils::make_block_device(utils::DISK_SOURCE).unwrap();
let volume_mgr: VolumeManager<utils::RamDisk<Vec<u8>>, utils::TestTimeSource, 4, 2, 1> =
VolumeManager::new_with_limits(disk, time_source, 0xAA00_0000);
let volume = volume_mgr.open_volume(VolumeIdx(0)).expect("open volume");
let root_dir = volume.open_root_dir().expect("open root dir");

// Check that the file doesn't exist yet
let files = {
let mut files = Vec::new();
root_dir
.iterate_dir(|entry| {
files.push(entry.name.clone());
})
.expect("iterate dir");
files
};
assert_eq!(
None,
files
.iter()
.find(|&x| core::str::from_utf8(x.base_name()).unwrap() == "README_2")
);

// Create it:
{
let file = root_dir
.open_file_in_dir("README_2.TXT", Mode::ReadWriteCreateOrAppend)
.expect("open file");

let test_data = vec![0xCC; 1024 * 1024];
file.write(&test_data).expect("file write");

let length = file.length();
assert_eq!(length, 1024 * 1024);

let offset = file.offset();
assert_eq!(offset, 1024 * 1024);
}

// Check that it now exists
let files = {
let mut files = Vec::new();
root_dir
.iterate_dir(|entry| {
files.push(entry.name.clone());
})
.expect("iterate dir");
files
};
assert_ne!(
None,
files
.iter()
.find(|&x| core::str::from_utf8(x.base_name()).unwrap() == "README_2")
);

// Append to it:
for i in 0..10 {
let file = root_dir
.open_file_in_dir("README_2.TXT", Mode::ReadWriteCreateOrAppend)
.expect("open file");

let test_data = vec![0xCC; 1024 * 1024];
file.write(&test_data).expect("file write");

let length = file.length();
assert_eq!(length, 1024 * 1024 * (i + 2));

let offset = file.offset();
assert_eq!(offset, 1024 * 1024 * (i + 2));
}
}

#[test]
fn flush_file() {
let time_source = utils::make_time_source();
Expand Down
Loading