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 junit.framework.TestCase;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
29 * Test of DictZipInputStream.
30 * @author Hiroshi Miura
32 public class DictZipInputStreamTest extends TestCase {
34 private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
35 private RandomAccessInputStream in;
36 private DictZipInputStream din;
37 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.
56 public void tearDown() throws Exception {
61 private synchronized void getDZHeader(DictZipInputStream din) throws IOException {
63 header = din.readHeader();
68 * Test of read method, of class DictZipInputStream.
71 public void testRead() throws Exception {
72 System.out.println("read");
76 int off = header.getOffset(start);
77 long pos = header.getPosition(start);
79 byte[] buf = new byte[off + len];
81 int result = din.read(buf, off, len);
82 assertEquals(expResult, result);
86 * Test of readFully method, of class DictZipInputStream.
87 * @throws java.lang.Exception
90 public void testReadFully_byteArr() throws Exception {
91 System.out.println("readFully");
95 int off = header.getOffset(start);
96 long pos = header.getPosition(start);
98 byte[] buf = new byte[off + len];
103 * Test of readFully method, of class DictZipInputStream.
104 * @throws java.lang.Exception
107 public void testReadFully_3args() throws Exception {
108 System.out.println("readFully");
112 int off = header.getOffset(start);
113 long pos = header.getPosition(start);
115 byte[] buf = new byte[off + len];
116 din.readFully(buf, off, len);
120 * Test of readHeader method, of class DictZipInputStream.
121 * @throws java.lang.Exception
124 public void testReadHeader() throws Exception {
125 System.out.println("readHeader");
126 header = din.readHeader();
127 StringBuilder sb = new StringBuilder();
128 sb.append("\nHeader length = 49");
129 sb.append("\nSubfield ID = RA");
130 sb.append("\nSubfield length = 20");
131 sb.append("\nSubfield version = 1");
132 sb.append("\nChunk length = 58315");
133 sb.append("\nNumber of chunks = 7");
134 String expResult = sb.toString();
135 assertEquals(expResult, header.toString());