2 * DictZip library test.
4 * Copyright (C) 2016 Hiroshi Miura
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 import static org.testng.Assert.*;
24 import org.testng.annotations.AfterTest;
25 import org.testng.annotations.BeforeTest;
26 import org.testng.annotations.Test;
28 import java.io.EOFException;
29 import java.io.IOException;
30 import java.util.Arrays;
34 * Test of DictZipInputStream.
35 * @author Hiroshi Miura
37 public class DictZipInputStreamTest {
39 private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
40 private RandomAccessInputStream in;
41 private DictZipInputStream din;
42 private DictZipHeader header;
49 public void setUp() throws Exception {
50 in = new RandomAccessInputStream(dataFile, "r");
51 din = new DictZipInputStream(in);
55 * Close output stream.
56 * @throws Exception if I/O error occured.
59 public void tearDown() throws Exception {
64 private synchronized void getDZHeader(DictZipInputStream din) throws IOException {
65 header = din.readHeader();
69 * Test of read method, of class DictZipInputStream.
72 public void testRead() throws Exception {
73 System.out.println("read");
76 byte[] buf = new byte[len];
77 byte[] expResult = {0x70, 0x72, (byte) 0xc3, (byte) 0xa9, 0x70, 0x2e, 0x20, 0x3a, 0x20, 0x2b};
78 din.read(buf, 0, len);
79 assertTrue(Arrays.equals(expResult, buf));
83 * Test of read method, of class DictZipInputStream.
86 public void testRead_with_seek() throws Exception {
87 System.out.println("read with seek");
92 byte[] buf = new byte[len];
94 0x61, 0x70, 0x72, (byte) 0xc3, (byte) 0xa8, 0x73, 0x20, 0x75, 0x6e, 0x20
96 din.read(buf, 0, len);
97 assertTrue(Arrays.equals(buf, expResult));
101 * Test of readFully method, of class DictZipInputStream.
102 * @throws java.lang.Exception
105 public void testReadFully_byteArr() throws Exception {
106 System.out.println("readFully");
110 int off = header.getOffset(start);
111 long pos = header.getPosition(start);
113 byte[] buf = new byte[off + len];
118 * Test of readFully method, of class DictZipInputStream.
119 * @throws java.lang.Exception
122 public void testReadFully_3args() throws Exception {
123 System.out.println("readFully");
127 int off = header.getOffset(start);
128 long pos = header.getPosition(start);
130 byte[] buf = new byte[off + len];
131 din.readFully(buf, off, len);
136 * Test of readFully method, of class DictZipInputStream.
137 * @throws java.lang.Exception
140 public void testReadFully_checkTrailer() throws Exception {
141 System.out.println("readFully and checkTrailer");
143 byte[] buf = new byte[512];
146 } catch (RuntimeException e) {
148 } catch (EOFException e) {
154 } catch (RuntimeException e) {
157 assertEquals(din.getCrc(), 0x024d1f37);
158 assertEquals(din.getLength(), 383783);
162 * Test of readHeader method, of class DictZipInputStream.
163 * @throws java.lang.Exception
166 public void testReadHeader() throws Exception {
167 System.out.println("readHeader");
168 header = din.readHeader();
169 StringBuilder sb = new StringBuilder();
170 sb.append("\nHeader length = 49");
171 sb.append("\nSubfield ID = RA");
172 sb.append("\nSubfield length = 20");
173 sb.append("\nSubfield version = 1");
174 sb.append("\nChunk length = 58315");
175 sb.append("\nNumber of chunks = 7");
176 String expResult = sb.toString();
177 assertEquals(header.toString(), expResult);