mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Fix FileAccessCompressed
claiming one byte more than it actually has.
Add a unit test for fastlz compressed file access.
This commit is contained in:
parent
af2c713971
commit
68f4502a5b
3 changed files with 23 additions and 1 deletions
|
@ -283,7 +283,7 @@ uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) con
|
|||
if (dst_idx + 1 < p_length) {
|
||||
read_eof = true;
|
||||
}
|
||||
return dst_idx + 1;
|
||||
return dst_idx;
|
||||
}
|
||||
|
||||
// Read the next block of compressed data.
|
||||
|
|
|
@ -196,6 +196,28 @@ TEST_CASE("[FileAccess] Get/Store floating point half precision values") {
|
|||
|
||||
DirAccess::remove_file_or_error(file_path_new);
|
||||
}
|
||||
|
||||
SUBCASE("4096 bytes fastlz compressed") {
|
||||
const String file_path = TestUtils::get_data_path("exactly_4096_bytes_fastlz.bin");
|
||||
|
||||
Ref<FileAccess> f = FileAccess::open_compressed(file_path, FileAccess::READ, FileAccess::COMPRESSION_FASTLZ);
|
||||
const Vector<uint8_t> full_data = f->get_buffer(4096 * 2);
|
||||
CHECK(full_data.size() == 4096);
|
||||
CHECK(f->eof_reached());
|
||||
|
||||
// Data should be empty.
|
||||
PackedByteArray reference;
|
||||
reference.resize_zeroed(4096);
|
||||
CHECK(reference == full_data);
|
||||
|
||||
f->seek(0);
|
||||
const Vector<uint8_t> partial_data = f->get_buffer(4095);
|
||||
CHECK(partial_data.size() == 4095);
|
||||
CHECK(!f->eof_reached());
|
||||
|
||||
reference.resize_zeroed(4095);
|
||||
CHECK(reference == partial_data);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace TestFileAccess
|
||||
|
|
BIN
tests/data/exactly_4096_bytes_fastlz.bin
Normal file
BIN
tests/data/exactly_4096_bytes_fastlz.bin
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue