Skip to content

Commit 06aa28b

Browse files
committed
Update part test to showcase difference between updated JVM and std handling
1 parent 1642b4c commit 06aa28b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/test/java/software/coley/llzip/PartParseTests.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import software.coley.llzip.format.model.LocalFileHeader;
88
import software.coley.llzip.format.model.ZipArchive;
99
import software.coley.llzip.format.model.ZipPart;
10+
import software.coley.llzip.format.read.ForwardScanZipReaderStrategy;
1011
import software.coley.llzip.format.read.JvmZipReaderStrategy;
1112
import software.coley.llzip.util.ByteDataUtil;
1213

@@ -107,23 +108,30 @@ public void testLocalHeaderDetectMismatch() {
107108
Path path = Paths.get("src/test/resources/hello-secret-0-length-locals.jar");
108109

109110
try {
110-
ZipArchive zipJvm = ZipIO.readJvm(path);
111-
assertNotNull(zipJvm);
111+
// The 'standard' strategy does not adopt CEN values when reading local entries.
112+
// The 'jvm' strategy does.
113+
ZipArchive zipStd = ZipIO.readStandard(path);
114+
assertNotNull(zipStd);
112115

113-
LocalFileHeader hello = zipJvm.getLocalFileByName("Hello.class");
116+
LocalFileHeader hello = zipStd.getLocalFileByName("Hello.class");
114117
assertNotNull(hello);
115118

116119
// The local file header says the contents are 0 bytes, but the central header has the real length
117120
assertTrue(hello.hasDifferentValuesThanCentralDirectoryHeader());
118121

119122
// The solution to differing values is to adopt values in the reader strategy
120-
ZipArchive zipJvmAndAdopt = ZipIO.read(path, new JvmZipReaderStrategy() {
123+
ZipArchive zipStdAndAdopt = ZipIO.read(path, new ForwardScanZipReaderStrategy() {
121124
@Override
122125
public void postProcessLocalFileHeader(LocalFileHeader file) {
123126
file.adoptLinkedCentralDirectoryValues();
124127
}
125128
});
126-
LocalFileHeader helloAdopted = zipJvmAndAdopt.getLocalFileByName("Hello.class");
129+
LocalFileHeader helloAdopted = zipStdAndAdopt.getLocalFileByName("Hello.class");
130+
assertFalse(helloAdopted.hasDifferentValuesThanCentralDirectoryHeader());
131+
132+
// Alternatively, just use the JVM strategy
133+
ZipArchive zipJvm = ZipIO.readJvm(path);
134+
helloAdopted = zipJvm.getLocalFileByName("Hello.class");
127135
assertFalse(helloAdopted.hasDifferentValuesThanCentralDirectoryHeader());
128136
} catch (IOException ex) {
129137
fail(ex);

0 commit comments

Comments
 (0)