Преглед изворни кода

Fix `FileAccessCompressed` claiming one byte more than it actually has.
Add a unit test for fastlz compressed file access.

Lukas Tenbrink пре 3 месеци
родитељ
комит
68f4502a5b

+ 1 - 1
core/io/file_access_compressed.cpp

@@ -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.

+ 22 - 0
tests/core/io/test_file_access.h

@@ -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