1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2package com.jcraft.jzlib
3
4import org.junit.runner.RunWith
5import org.junit.runners.JUnit4
6import org.junit.{Test, Before}
7import org.junit.Assert._
8import org.hamcrest.CoreMatchers._
9
10import java.io._
11
12import JZlib._
13
14@RunWith(classOf[JUnit4])
15class GZIPIOStreamTest {
16
17  @Before
18  def setUp = {
19  }
20
21  @Test
22  def outstream = {
23
24    val comment = "hi"
25    val name = "/tmp/foo"
26
27    val content = "hello".getBytes
28
29    val baos = new ByteArrayOutputStream
30    val gos = new GZIPOutputStream(baos)
31
32    gos.setComment(comment)
33    gos.setName(name)
34
35    gos.write(content)
36    gos.close
37
38    val bais = new ByteArrayInputStream(baos.toByteArray)
39    val gis = new GZIPInputStream(bais)
40
41    val buf = new Array[Byte](1024)
42    val i = gis.read(buf)
43
44    assertThat(content.length, is(i))
45    (0 until i) foreach { i =>
46      assertThat(content(i).asInstanceOf[Byte], is(buf(i).asInstanceOf[Byte]))
47    }
48
49    assertThat(comment, is(gis.getComment))
50    assertThat(name, is(gis.getName))
51
52    val crc32 = new CRC32
53    crc32.update(content, 0, content.length)
54
55    assertThat(crc32.getValue, is(gis.getCRC.asInstanceOf[Long]))
56  }
57}
58