Skip to content

Commit

Permalink
Update URLHandleTest to check backward seeks larger than 1 MB
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Jan 11, 2018
1 parent fd0a6a2 commit f5e4cac
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/test/java/loci/common/utests/URLHandleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

import loci.common.Constants;
import loci.common.HandleException;
Expand All @@ -58,6 +59,8 @@ public class URLHandleTest {
private URLHandle fileHandle;
private static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");

private static final int EMPTY_BUFFER_SIZE = 1024 * 1024;

// -- Setup methods --

@BeforeMethod
Expand All @@ -66,6 +69,10 @@ public void setup() throws IOException {
tmpFile.deleteOnExit();
FileOutputStream out = new FileOutputStream(tmpFile);
out.write("hello, world!\n".getBytes(Constants.ENCODING));
byte[] emptyBuffer = new byte[EMPTY_BUFFER_SIZE];
Arrays.fill(emptyBuffer, (byte) 0);
out.write(emptyBuffer);
out.write("goodbye, world!\n".getBytes(Constants.ENCODING));
out.close();
String path = tmpFile.getAbsolutePath();
fileHandle = new URLHandle((IS_WINDOWS ? "file:/" : "file://") + path);
Expand All @@ -75,7 +82,7 @@ public void setup() throws IOException {

@Test
public void testLength() throws IOException {
assertEquals(14, fileHandle.length());
assertEquals(30 + EMPTY_BUFFER_SIZE, fileHandle.length());
}

@Test
Expand Down Expand Up @@ -152,6 +159,11 @@ public void testSeekBackReadByte() throws IOException {
fileHandle.seek(13);
fileHandle.seek(7);
assertEquals(0x77, fileHandle.readByte());

fileHandle.seek(23 + EMPTY_BUFFER_SIZE);
assertEquals(0x77, fileHandle.readByte());
fileHandle.seek(7);
assertEquals(0x77, fileHandle.readByte());
}

@Test
Expand All @@ -177,7 +189,7 @@ public void testSeekBackReadLong() throws IOException {

@Test (expectedExceptions = {EOFException.class})
public void testEOF() throws IOException {
fileHandle.seek(16);
fileHandle.seek(30 + EMPTY_BUFFER_SIZE);
fileHandle.readByte();
}

Expand Down

0 comments on commit f5e4cac

Please sign in to comment.