diff --git a/examples/sample.rs b/examples/sample.rs index 603c48b..dcbb5cf 100644 --- a/examples/sample.rs +++ b/examples/sample.rs @@ -7,7 +7,7 @@ use std::str; use rustfat::FatFileSystem; fn main() { - let file = File::open("resources/floppy.img").unwrap(); + let file = File::open("resources/fat12.img").unwrap(); let buf_rdr = BufReader::new(file); let mut fs = FatFileSystem::new(Box::new(buf_rdr)).unwrap(); let mut root_dir = fs.root_dir(); diff --git a/resources/fat12.img b/resources/fat12.img new file mode 100644 index 0000000..6ae8a19 Binary files /dev/null and b/resources/fat12.img differ diff --git a/resources/fat16.img b/resources/fat16.img new file mode 100644 index 0000000..a66d617 Binary files /dev/null and b/resources/fat16.img differ diff --git a/resources/fat32.img b/resources/fat32.img new file mode 100644 index 0000000..00c5e73 Binary files /dev/null and b/resources/fat32.img differ diff --git a/resources/floppy.img b/resources/floppy.img deleted file mode 100755 index 968794b..0000000 Binary files a/resources/floppy.img and /dev/null differ diff --git a/scripts/create-test-img.sh b/scripts/create-test-img.sh new file mode 100755 index 0000000..2581c41 --- /dev/null +++ b/scripts/create-test-img.sh @@ -0,0 +1,24 @@ +#!/bin/bash +OUT_DIR=../resources +set -e + +create_test_img() { + local name=$1 + local blkcount=$2 + local fatSize=$3 + dd if=/dev/zero of="$name" bs=1024 count=$blkcount + mkfs.vfat -s 1 -F $fatSize "$name" + mkdir -p mnt + sudo mount -o loop "$name" mnt -o rw,uid=$USER,gid=$USER + for i in {1..1000}; do + echo "Rust is cool!" >>"mnt/long.txt" + done + echo "Rust is cool!" >>"mnt/short.txt" + mkdir -p mnt/very/long/path + echo "Rust is cool!" >>"mnt/very/long/path/test.txt" + sudo umount mnt +} + +create_test_img "$OUT_DIR/fat12.img" 1000 12 +create_test_img "$OUT_DIR/fat16.img" 2500 16 +create_test_img "$OUT_DIR/fat32.img" 34000 32 diff --git a/tests/integration-test.rs b/tests/integration-test.rs index 5f19e5e..0a0d47a 100644 --- a/tests/integration-test.rs +++ b/tests/integration-test.rs @@ -6,14 +6,29 @@ use std::str; use rustfat::FatFileSystem; -#[test] -fn fat12_test() { - let file = File::open("resources/floppy.img").unwrap(); +fn test_img(name: &str) { + let file = File::open(name).unwrap(); let buf_rdr = BufReader::new(file); let mut fs = FatFileSystem::new(Box::new(buf_rdr)).unwrap(); let mut root_dir = fs.root_dir(); let entries = root_dir.list().unwrap(); - assert_eq!(entries.len(), 2); - assert_eq!(entries[0].get_name(), "RAFOS"); - assert_eq!(entries[1].get_name(), "GRUB"); + assert_eq!(entries.len(), 3); + assert_eq!(entries[0].get_name(), "LONG.TXT"); + assert_eq!(entries[1].get_name(), "SHORT.TXT"); + assert_eq!(entries[2].get_name(), "VERY"); +} + +#[test] +fn fat12() { + test_img("resources/fat12.img"); +} + +#[test] +fn fat16() { + test_img("resources/fat16.img"); +} + +#[test] +fn fat32() { + test_img("resources/fat32.img"); }