1/* -*-mode:scala; c-basic-offset:2; indent-tabs-mode:nil -*- */
2package com.jcraft.jzlib
3
4import org.scalatest._
5import org.scalatest.matchers.ShouldMatchers
6
7import java.io._
8import java.util.zip.CheckedOutputStream
9import java.util.zip.CheckedInputStream
10import java.util.zip.{GZIPInputStream => juzGZIPInputStream}
11import java.util.zip.{CRC32 => juzCRC32}
12
13import JZlib._
14
15class GZIPIOStreamTest extends FlatSpec with BeforeAndAfter with ShouldMatchers {
16
17 before {
18 }
19
20 after {
21 }
22
23 behavior of "GZIPOutputStream and GZIPInputStream"
24
25 it can "deflate and infate data." in {
26
27 val comment = "hi"
28 val name = "/tmp/foo"
29
…lines 30–54 unchanged (25 lines)
55 val crc32 = new CRC32
56 crc32.update(content, 0, content.length)
57
58 crc32.getValue should equal(gis.getCRC.asInstanceOf[Long])
59 }
60
61 behavior of "GZIPOutputStream"
62
63 // https://github.com/ymnk/jzlib/issues/9
64 // https://github.com/jglick/jzlib-9-demo
65 it can "deflate some file without AIOOBE." in {
66 val pos = new PipedOutputStream()
67 val pis = new PipedInputStream(pos)
68 val csOut = new juzCRC32()
69 val gos = new GZIPOutputStream(pos)
70 val cos = new CheckedOutputStream(gos, csOut)
71
72 val t = new Thread() {
73 override def run = {
74 val fail = "/jzlib.fail.gz".fromResource
75 val fis = new juzGZIPInputStream(new ByteArrayInputStream(fail))
76 fis -> cos
77 cos.close()
78 }
79 }
80 t.start();
81
82 val gis = new GZIPInputStream(pis)
83 val csIn = new juzCRC32();
84 new CheckedInputStream(gis, csIn) -> new ByteArrayOutputStream()
85
86 t.join()
87
88 csIn.getValue() should equal(csOut.getValue)
89 }
90}
91