summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-06-28 22:56:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-06-28 22:56:00 +0000
commit52ac40530506afe4c5a85d370e04ee77e523b1fa (patch)
tree38ce88f5a651548c2dbb87b7d8ef2ed3e1b1ac99 /luni/src/test/java
parentd1d7384d00c53ea7cb0fe334654d5bcc7daced79 (diff)
parent35f9da25ee063a0d0c32f7246b466cff8e57c9ee (diff)
downloadlibcore-52ac40530506afe4c5a85d370e04ee77e523b1fa.zip
libcore-52ac40530506afe4c5a85d370e04ee77e523b1fa.tar.gz
libcore-52ac40530506afe4c5a85d370e04ee77e523b1fa.tar.bz2
Merge "Add syncFlush support to GZIPOutputStream."
Diffstat (limited to 'luni/src/test/java')
-rw-r--r--luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java30
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java52
2 files changed, 61 insertions, 21 deletions
diff --git a/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java
index 37d1248..2e32f7d 100644
--- a/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java
@@ -19,6 +19,7 @@ package libcore.java.util.zip;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
+import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PipedInputStream;
@@ -30,13 +31,15 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
import java.util.zip.InflaterInputStream;
import junit.framework.TestCase;
public class DeflaterOutputStreamTest extends TestCase {
public void testSyncFlushEnabled() throws Exception {
- InflaterInputStream in = createInflaterStream(true);
+ InputStream in = createInflaterStream(DeflaterOutputStream.class, true);
assertEquals(1, in.read());
assertEquals(2, in.read());
assertEquals(3, in.read());
@@ -44,7 +47,7 @@ public class DeflaterOutputStreamTest extends TestCase {
}
public void testSyncFlushDisabled() throws Exception {
- InflaterInputStream in = createInflaterStream(false);
+ InputStream in = createInflaterStream(DeflaterOutputStream.class, false);
try {
in.read();
fail();
@@ -65,14 +68,21 @@ public class DeflaterOutputStreamTest extends TestCase {
* way demonstrate that data is unavailable. Ie. other techniques will cause
* the dry read to block indefinitely.
*/
- private InflaterInputStream createInflaterStream(final boolean flushing) throws Exception {
+ static InputStream createInflaterStream(final Class<?> c, final boolean flushing) throws Exception {
ExecutorService executor = Executors.newSingleThreadExecutor();
final PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
executor.submit(new Callable<Void>() {
public Void call() throws Exception {
- OutputStream out = new DeflaterOutputStream(pout, flushing);
+ OutputStream out;
+ if (c == DeflaterOutputStream.class) {
+ out = new DeflaterOutputStream(pout, flushing);
+ } else if (c == GZIPOutputStream.class) {
+ out = new GZIPOutputStream(pout, flushing);
+ } else {
+ throw new AssertionError();
+ }
out.write(1);
out.write(2);
out.write(3);
@@ -82,7 +92,13 @@ public class DeflaterOutputStreamTest extends TestCase {
}).get();
executor.shutdown();
- return new InflaterInputStream(pin);
+ if (c == DeflaterOutputStream.class) {
+ return new InflaterInputStream(pin);
+ } else if (c == GZIPOutputStream.class) {
+ return new GZIPInputStream(pin);
+ } else {
+ throw new AssertionError();
+ }
}
/**
@@ -146,5 +162,9 @@ public class DeflaterOutputStreamTest extends TestCase {
// during the test, since that would lead to the results being
// flushed even without SYNC_FLUSH being used
assertFalse(def.finished());
+
+ // Quieten CloseGuard.
+ def.end();
+ iis.close();
}
}
diff --git a/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
index a61880f..55e45bc 100644
--- a/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
@@ -25,26 +25,46 @@ import java.util.Arrays;
import java.util.Random;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
+import java.util.zip.InflaterInputStream;
import junit.framework.TestCase;
public final class GZIPOutputStreamTest extends TestCase {
- public void testShortMessage() throws IOException {
- byte[] data = gzip(("Hello World").getBytes("UTF-8"));
- assertEquals("[31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49, " +
- "47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0]", Arrays.toString(data));
- }
+ public void testShortMessage() throws IOException {
+ byte[] data = gzip(("Hello World").getBytes("UTF-8"));
+ assertEquals("[31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49, " +
+ "47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0]", Arrays.toString(data));
+ }
- public void testLongMessage() throws IOException {
- byte[] data = new byte[1024 * 1024];
- new Random().nextBytes(data);
- assertTrue(Arrays.equals(data, GZIPInputStreamTest.gunzip(gzip(data))));
- }
+ public void testLongMessage() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ new Random().nextBytes(data);
+ assertTrue(Arrays.equals(data, GZIPInputStreamTest.gunzip(gzip(data))));
+ }
+
+ public static byte[] gzip(byte[] bytes) throws IOException {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ OutputStream gzippedOut = new GZIPOutputStream(bytesOut);
+ gzippedOut.write(bytes);
+ gzippedOut.close();
+ return bytesOut.toByteArray();
+ }
- public static byte[] gzip(byte[] bytes) throws IOException {
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- OutputStream gzippedOut = new GZIPOutputStream(bytesOut);
- gzippedOut.write(bytes);
- gzippedOut.close();
- return bytesOut.toByteArray();
+ public void testSyncFlushEnabled() throws Exception {
+ InputStream in = DeflaterOutputStreamTest.createInflaterStream(GZIPOutputStream.class, true);
+ assertEquals(1, in.read());
+ assertEquals(2, in.read());
+ assertEquals(3, in.read());
+ in.close();
+ }
+
+ public void testSyncFlushDisabled() throws Exception {
+ InputStream in = DeflaterOutputStreamTest.createInflaterStream(GZIPOutputStream.class, false);
+ try {
+ in.read();
+ fail();
+ } catch (IOException expected) {
}
+ in.close();
+ }
+
}