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.IOException;
29 import java.util.Arrays;
33 * Test of DictZipInputStream.
34 * @author Hiroshi Miura
36 public class DictZipInputStreamTest {
38 private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
39 private RandomAccessInputStream in;
40 private DictZipInputStream din;
41 private DictZipHeader header;
48 public void setUp() throws Exception {
49 in = new RandomAccessInputStream(dataFile, "r");
50 din = new DictZipInputStream(in);
54 * Close output stream.
55 * @throws Exception if I/O error occured.
58 public void tearDown() throws Exception {
63 private synchronized void getDZHeader(DictZipInputStream din) throws IOException {
64 header = din.readHeader();
68 * Test of read method, of class DictZipInputStream.
71 public void testRead() throws Exception {
72 System.out.println("read");
75 byte[] buf = new byte[len];
76 byte[] expResult = {0x70, 0x72, (byte) 0xc3, (byte) 0xa9, 0x70, 0x2e, 0x20, 0x3a, 0x20, 0x2b};
77 din.read(buf, 0, len);
78 assertTrue(Arrays.equals(expResult, buf));
82 * Test of read method, of class DictZipInputStream.
85 public void testRead_with_seek() throws Exception {
86 System.out.println("read with seek");
91 byte[] buf = new byte[len];
93 0x61, 0x70, 0x72, (byte) 0xc3, (byte) 0xa8, 0x73, 0x20, 0x75, 0x6e, 0x20
95 din.read(buf, 0, len);
96 assertTrue(Arrays.equals(buf, expResult));
100 * Test of readFully method, of class DictZipInputStream.
101 * @throws java.lang.Exception
104 public void testReadFully_byteArr() throws Exception {
105 System.out.println("readFully");
109 int off = header.getOffset(start);
110 long pos = header.getPosition(start);
112 byte[] buf = new byte[off + len];
117 * Test of readFully method, of class DictZipInputStream.
118 * @throws java.lang.Exception
121 public void testReadFully_3args() throws Exception {
122 System.out.println("readFully");
126 int off = header.getOffset(start);
127 long pos = header.getPosition(start);
129 byte[] buf = new byte[off + len];
130 din.readFully(buf, off, len);
134 * Test of readHeader method, of class DictZipInputStream.
135 * @throws java.lang.Exception
138 public void testReadHeader() throws Exception {
139 System.out.println("readHeader");
140 header = din.readHeader();
141 StringBuilder sb = new StringBuilder();
142 sb.append("\nHeader length = 49");
143 sb.append("\nSubfield ID = RA");
144 sb.append("\nSubfield length = 20");
145 sb.append("\nSubfield version = 1");
146 sb.append("\nChunk length = 58315");
147 sb.append("\nNumber of chunks = 7");
148 String expResult = sb.toString();
149 assertEquals(expResult, header.toString());