Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix java/util/zip/DeflateIn_InflateOut.skipBytes Test #559

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions test/jdk/java/util/zip/DeflateIn_InflateOut.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ public class DeflateIn_InflateOut {
private static ByteArrayOutputStream baos;
private static InflaterOutputStream ios;

private static void reset() {
new Random(new Date().getTime()).nextBytes(data);

private static void resetStreams() {
bais = new ByteArrayInputStream(data);
dis = new DeflaterInputStream(bais);

baos = new ByteArrayOutputStream();
ios = new InflaterOutputStream(baos);
}

private static void resetAll() {
new Random(new Date().getTime()).nextBytes(data);
resetStreams();
}

/** Check byte arrays read/write. */
private static void ArrayReadWrite() throws Throwable {
byte[] buf = new byte[512];

reset();
resetAll();
check(dis.available() == 1);
for (;;) {
int len = dis.read(buf, 0, buf.length);
Expand All @@ -74,7 +77,7 @@ private static void ArrayReadWrite() throws Throwable {
private static void ArrayReadByteWrite() throws Throwable {
byte[] buf = new byte[512];

reset();
resetAll();
for (;;) {
int len = dis.read(buf, 0, buf.length);
if (len <= 0) {
Expand All @@ -100,7 +103,7 @@ private static void ByteReadArrayWrite() throws Throwable {
byte[] buf = new byte[8192];
int off = 0;

reset();
resetAll();
int datum = dis.read();
while (datum != -1) {
if (off == 8192) {
Expand All @@ -126,7 +129,7 @@ private static void ByteReadByteWrite() throws Throwable {
byte[] buf = new byte[512];
boolean reachEOF = false;

reset();
resetAll();
while (dis.available() == 1) {
int datum = dis.read();
if (datum == -1) {
Expand All @@ -149,7 +152,8 @@ private static void SkipBytes() throws Throwable {
int numReadable = 0;

// Count number of bytes that are read
reset();

resetAll();
check(dis.available() == 1);
for (;;) {
int count = dis.read(buf, 0, buf.length);
Expand All @@ -162,7 +166,13 @@ private static void SkipBytes() throws Throwable {
check(dis.available() == 0);

// Verify that skipping the first several bytes works.
reset();

// Different input data even though is of fixed size would lead to
// different compressed output. The main intention of this method to
// test DeflaterInputStream.skipBytes so keeping the input data fixed
// while testing out skipping of different bytes and only need to reset
// the input streams.
resetStreams();
int numNotSkipped = 0;
int numSkipBytes = 2053; // arbitrarily chosen prime
check(dis.skip(numSkipBytes) == numSkipBytes);
Expand All @@ -177,7 +187,7 @@ private static void SkipBytes() throws Throwable {
check(numNotSkipped + numSkipBytes == numReadable);

// Verify that skipping some bytes mid-stream works.
reset();
resetStreams();
numNotSkipped = 0;
numSkipBytes = 8887; // arbitrarily chosen prime
for (int i = 0; ; i++) {
Expand All @@ -195,7 +205,7 @@ private static void SkipBytes() throws Throwable {
check(numNotSkipped + numSkipBytes == numReadable);

// Verify that skipping the last N bytes works.
reset();
resetStreams();
numNotSkipped = 0;
numSkipBytes = 6449; // arbitrarily chosen prime
for (int i = 0; ; i++) {
Expand Down