Skip to content

Commit

Permalink
It actually worked for win-server. So expanding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mart-Bogdan committed Nov 18, 2022
1 parent 9a8c477 commit ba0b162
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ serde_json = "1.0.73"

[dev-dependencies]
const_format = "0.2.23"
# TODO update to 0.16 when it is released.
# It fixes https://github.com/la10736/rstest/issues/158, which is not showtopper, but minor annoyance.
rstest = "0.15.0"
once_cell = "1.16.0"

Expand Down
5 changes: 5 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ pub fn set_file_compression<P: AsRef<Path>>(path: P, compress: bool) -> Result<(
let handle = Handle::from_file(File::options().write(true).read(true).open(path)?);

// mut, coz WinAPI rquires mut pointer
// documentation states that Windows supports only LZNT1, and it is also used by DEFAULT
// but practical tests show that on windows-server-22 DEFAULT doesn't compress a thing.
// Perhaps if we were doing compression manager or wothever -- more research would be required,
// but for tests hardcoding LZNT1 would suffice.
// We don't need be as future-proof for new algorithms in new windows releases.
let mut compression_format: USHORT = if compress {
COMPRESSION_FORMAT_LZNT1
} else {
Expand Down
37 changes: 19 additions & 18 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,28 @@ fn test_files_physical_size() {
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "text1.txt"), true, 4096);
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "text2.txt"), true, 12288);
}
#[test]

#[cfg(windows)] // isn't supported on Unix (Theoretically possible on btrfs)
fn test_compressed_files_physical_size() {
#[rstest]
#[case("b23_rand_c", 24)]
#[case("b23_zero_c", 24)]
#[case("b512_rand_c", 512)]
#[case("b512_zero_c", 512)]
#[case("b4000_rand_c", 8192)]
#[case("b4000_zero_c", 0)]
#[case("b4096_rand_c", 8192)]
#[case("b4096_zero_c", 0)]
#[case("b8000_rand_c", 12288)]
#[case("b8192_rand_c", 12288)]
#[case("b8192_zero_c", 0)]
#[case("rand_1000_c", 4096)]
#[case("text1_c.txt", 4096)]
#[case("text2_c.txt", 4096)]
fn test_compressed_files_physical_size(#[case] file: &str, #[case] size: u64) {
PREPARE_COMPRESSION_SAMPLES.as_ref().unwrap();
let file = String::from(TEST_PRE_CREATED_DIR) + file;

assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b23_rand_c"), true, 24);
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b23_zero_c"), true, 24);
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b512_rand_c"), true, 512);
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b512_zero_c"), true, 512);

// Unreproducible: my Win10 -- 8192; WinServer(github) -- 4096
//assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b4000_rand_c"), true, 8192);
//assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b4000_zero_c"), true, 0);
// CI assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b4096_rand_c"), true, 8192);
// CI assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b4096_zero_c"), true, 0);
// assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b8000_rand_c"), true, 12288);
// assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b8192_rand_c"), true, 12288);
// CI assert_size(concatcp!(TEST_PRE_CREATED_DIR, "b8192_zero_c"), true, 0);
// assert_size(concatcp!(TEST_PRE_CREATED_DIR, "rand_1000_c"), true, 4096);
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "text1_c.txt"), true, 4096);
assert_size(concatcp!(TEST_PRE_CREATED_DIR, "text2_c.txt"), true, 4096);
assert_size(&file, true, size);
}

#[allow(non_snake_case)]
Expand Down

0 comments on commit ba0b162

Please sign in to comment.