Skip to content

Commit 2a7c958

Browse files
committed
Add determine_fs_layout tests with fat type constraint
1 parent 0623978 commit 2a7c958

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/boot_sector.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,4 +987,42 @@ mod tests {
987987
boot.validate::<()>().expect("validate");
988988
}
989989
}
990+
991+
fn test_determine_fs_layout(fat_type: FatType, min_size: u64, max_size: u64) {
992+
init();
993+
994+
let bytes_per_sector = 512_u16;
995+
// test all partition sizes from 24 KB to 127 MB
996+
let mut total_sectors_vec = Vec::new();
997+
let mut size = min_size;
998+
while size < max_size {
999+
total_sectors_vec.push((size / u64::from(bytes_per_sector)).try_into().unwrap());
1000+
size += size / 7;
1001+
}
1002+
total_sectors_vec.push((max_size / u64::from(bytes_per_sector)).try_into().unwrap());
1003+
for total_sectors in total_sectors_vec {
1004+
let options = FormatVolumeOptions::new().fat_type(fat_type);
1005+
let layout = determine_fs_layout::<()>(&options, total_sectors)
1006+
.unwrap_or_else(|e| panic!("determine_fs_layout(total_sectors={}): {:?}", total_sectors, e));
1007+
assert_eq!(layout.fat_type, fat_type);
1008+
}
1009+
}
1010+
1011+
#[test]
1012+
fn test_determine_fs_layout_fat12() {
1013+
// approximately: 21 KB - 127 MB
1014+
test_determine_fs_layout(FatType::Fat12, 21 * KB_64, 127 * MB_64);
1015+
}
1016+
1017+
#[test]
1018+
fn test_determine_fs_layout_fat16() {
1019+
// approximately: 4.1 MB - 1.9 GB
1020+
test_determine_fs_layout(FatType::Fat16, 4120 * KB_64, 2047 * MB_64);
1021+
}
1022+
1023+
#[test]
1024+
fn test_determine_fs_layout_fat32() {
1025+
// approximately: 33 MB - 1.9 TB
1026+
test_determine_fs_layout(FatType::Fat32, 33 * MB_64, 2048 * GB_64 - 1);
1027+
}
9901028
}

0 commit comments

Comments
 (0)