2 * DictZip library test.
4 * Copyright (C) 2016,2019,2022 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.
20 * Linking this library statically or dynamically with other modules is
21 * making a combined work based on this library. Thus, the terms and
22 * conditions of the GNU General Public License cover the whole
25 * As a special exception, the copyright holders of this library give you
26 * permission to link this library with independent modules to produce an
27 * executable, regardless of the license terms of these independent
28 * modules, and to copy and distribute the resulting executable under
29 * terms of your choice, provided that you also meet, for each linked
30 * independent module, the terms and conditions of the license of that
31 * module. An independent module is a module which is not derived from
32 * or based on this library. If you modify this library, you may extend
33 * this exception to your version of the library, but you are not
34 * obligated to do so. If you do not wish to do so, delete this
35 * exception statement from your version.
41 import org.junit.jupiter.api.Assertions;
42 import org.junit.jupiter.api.Test;
44 import static org.junit.jupiter.api.Assertions.assertEquals;
45 import static org.junit.jupiter.api.Assertions.assertTrue;
50 * @author Hiroshi Miura
52 public class RandomAccessInputStreamTest {
54 private final String dataFile = this.getClass().getResource("/test.dict.dz").getFile();
57 * Test of available method, of class RandomAccessInputStream.
58 * @throws Exception when i/o error.
61 public void testAvailable() throws Exception {
62 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
63 int expResult = 136856;
64 int result = instance.available();
65 assertEquals(result, expResult);
69 * Test of close method, of class RandomAccessInputStream.
70 * @throws Exception when error.
73 public void testClose() throws Exception {
74 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
79 * Test of getLength method, of class RandomAccessInputStream.
80 * @throws Exception when error.
83 public void testGetLength() throws Exception {
84 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
85 long expResult = 136856L;
86 long result = instance.length();
87 assertEquals(result, expResult);
91 * Test of getPos method, of class RandomAccessInputStream.
92 * @throws Exception when error.
95 public void testGetPos() throws Exception {
96 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
98 long result = instance.position();
99 assertEquals(result, expResult);
103 * Test of mark method, of class RandomAccessInputStream.
106 public void testMark() {
109 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
110 instance.mark(markpos);
111 } catch (Exception ex) {
112 Assertions.fail("get exception.");
117 * Test of markSupported method, of class RandomAccessInputStream.
120 public void testMarkSupported() {
122 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
123 boolean result = instance.markSupported();
125 } catch (Exception ex) {
126 Assertions.fail("get exception.");
131 * Test of read method, of class RandomAccessInputStream.
132 * @throws Exception when error.
135 public void testRead0args() throws Exception {
137 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
139 int result = instance.read();
140 assertEquals(result, expResult);
141 } catch (Exception ex) {
142 Assertions.fail("get exception.");
147 * Test of read method, of class RandomAccessInputStream.
148 * @throws Exception when error.
151 public void testRead3args() throws Exception {
152 byte[] b = new byte[512];
155 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
157 int result = instance.read(b, off, len);
158 assertEquals(result, expResult);
162 * Test of readFully method, of class RandomAccessInputStream.
163 * @throws Exception when error.
166 public void testReadFully() throws Exception {
167 byte[] b = new byte[512];
168 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
169 instance.readFully(b);
173 * Test of reset method, of class RandomAccessInputStream.
174 * @throws Exception when error.
177 public void testReset() throws Exception {
178 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
183 * Test of seek method, of class RandomAccessInputStream.
184 * @throws Exception when error.
187 public void testSeek() throws Exception {
189 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
194 * Test of skip method, of class RandomAccessInputStream.
195 * @throws Exception when error.
198 public void testSkip() throws Exception {
200 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
201 long expResult = 100L;
202 long result = instance.skip(n);
203 assertEquals(result, expResult);
207 public void testLastByte() throws Exception {
208 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
209 instance.seek(136854);
210 int c = instance.read();
216 long pos = instance.position();
217 assertEquals(136856, pos);
221 public void testLastBytes() throws Exception {
222 RandomAccessInputStream instance = new RandomAccessInputStream(dataFile, "r");
223 instance.seek(136848);
224 byte[] buf = new byte[9];
225 int len = instance.read(buf, 0, buf.length);
226 assertEquals(8, len);
227 assertEquals(5, buf[len - 2]);
228 assertEquals(0, buf[len - 1]);
229 long pos = instance.position();
230 assertEquals(136856, pos);