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.
22 import java.io.IOException;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
27 import static org.junit.Assert.assertEquals;
30 * Test of DictZipInputStream.
31 * @author Hiroshi Miura
33 public class DictZipInputStreamTest {
35 private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
36 private RandomAccessInputStream in;
37 private DictZipInputStream din;
38 private DictZipHeader header;
45 public void setUp() throws Exception {
46 in = new RandomAccessInputStream(dataFile, "r");
47 din = new DictZipInputStream(in);
51 * Close output stream.
52 * @throws Exception if I/O error occured.
55 public void tearDown() throws Exception {
60 private synchronized void getDZHeader(DictZipInputStream din) throws IOException {
62 header = din.readHeader();
67 * Test of read method, of class DictZipInputStream.
70 public void testRead() throws Exception {
71 System.out.println("read");
75 int off = header.getOffset(start);
76 long pos = header.getPosition(start);
78 byte[] buf = new byte[off + len];
80 int result = din.read(buf, off, len);
81 assertEquals(expResult, result);
85 * Test of readFully method, of class DictZipInputStream.
86 * @throws java.lang.Exception
89 public void testReadFully_byteArr() throws Exception {
90 System.out.println("readFully");
94 int off = header.getOffset(start);
95 long pos = header.getPosition(start);
97 byte[] buf = new byte[off + len];
102 * Test of readFully method, of class DictZipInputStream.
103 * @throws java.lang.Exception
106 public void testReadFully_3args() throws Exception {
107 System.out.println("readFully");
111 int off = header.getOffset(start);
112 long pos = header.getPosition(start);
114 byte[] buf = new byte[off + len];
115 din.readFully(buf, off, len);
119 * Test of readHeader method, of class DictZipInputStream.
120 * @throws java.lang.Exception
123 public void testReadHeader() throws Exception {
124 System.out.println("readHeader");
125 header = din.readHeader();
126 StringBuilder sb = new StringBuilder();
127 sb.append("\nHeader length = 49");
128 sb.append("\nSubfield ID = RA");
129 sb.append("\nSubfield length = 20");
130 sb.append("\nSubfield version = 1");
131 sb.append("\nChunk length = 58315");
132 sb.append("\nNumber of chunks = 7");
133 String expResult = sb.toString();
134 assertEquals(expResult, header.toString());