3 package jp.sourceforge.mikutoga.parser;
5 import java.io.ByteArrayInputStream;
6 import java.io.FilterInputStream;
7 import java.io.IOException;
8 import org.junit.After;
9 import org.junit.AfterClass;
10 import org.junit.Before;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13 import static org.junit.Assert.*;
18 public class SpottedInputStreamTest {
20 public SpottedInputStreamTest() {
24 public static void setUpClass() {
28 public static void tearDownClass() {
36 public void tearDown() {
40 * Test of read method, of class SpottedInputStream.
43 public void testRead_0args() throws Exception {
44 System.out.println("read");
46 SpottedInputStream sis;
47 ByteArrayInputStream bis;
49 bis = new ByteArrayInputStream(new byte[]{0x01, 0x02});
50 sis = new SpottedInputStream(bis);
55 assertEquals(0x01, result);
58 assertEquals(0x02, result);
61 assertEquals(-1, result);
67 * Test of read method, of class SpottedInputStream.
70 public void testRead_byteArr() throws Exception {
71 System.out.println("read");
73 SpottedInputStream sis;
74 ByteArrayInputStream bis;
76 bis = new ByteArrayInputStream(new byte[]{0x01, 0x02, 0x03});
77 sis = new SpottedInputStream(bis);
79 byte[] buf = new byte[2];
82 result = sis.read(buf);
83 assertEquals(2, result);
84 assertEquals((byte)0x01, buf[0]);
85 assertEquals((byte)0x02, buf[1]);
87 result = sis.read(buf);
88 assertEquals(1, result);
89 assertEquals((byte)0x03, buf[0]);
91 result = sis.read(buf);
92 assertEquals(-1, result);
98 * Test of read method, of class SpottedInputStream.
101 public void testRead_3args() throws Exception {
102 System.out.println("read");
105 SpottedInputStream sis;
106 ByteArrayInputStream bis;
108 bis = new ByteArrayInputStream(new byte[]{0x01, 0x02, 0x03});
109 sis = new SpottedInputStream(bis);
111 byte[] buf = new byte[3];
117 result = sis.read(buf, 1, 2);
118 assertEquals(2, result);
119 assertEquals((byte)0xf1, buf[0]);
120 assertEquals((byte)0x01, buf[1]);
121 assertEquals((byte)0x02, buf[2]);
123 result = sis.read(buf, 0, 1);
124 assertEquals(1, result);
125 assertEquals((byte)0x03, buf[0]);
126 assertEquals((byte)0x01, buf[1]);
127 assertEquals((byte)0x02, buf[2]);
129 result = sis.read(buf, 0, 1);
130 assertEquals(-1, result);
136 * Test of skip method, of class SpottedInputStream.
139 public void testSkip() throws Exception {
140 System.out.println("skip");
142 SpottedInputStream sis;
143 ByteArrayInputStream bis;
145 bis = new ByteArrayInputStream(new byte[]{0x11, 0x12, 0x13});
146 sis = new SpottedInputStream(bis);
152 assertEquals(0x11, result);
154 skipped = sis.skip(1L);
155 assertEquals(1L, skipped);
158 assertEquals(0x13, result);
160 skipped = sis.skip(1L);
161 assertEquals(0L, skipped);
167 * Test of close method, of class SpottedInputStream.
170 public void testClose() throws Exception {
171 System.out.println("close");
173 SpottedInputStream sis;
176 tis = new TestInputStream();
177 sis = new SpottedInputStream(tis);
179 assertFalse(tis.closed);
181 assertTrue(tis.closed);
187 * Test of getPosition method, of class SpottedInputStream.
190 public void testGetPosition() throws Exception{
191 System.out.println("getPosition");
193 SpottedInputStream sis;
194 ByteArrayInputStream bis;
196 bis = new ByteArrayInputStream(new byte[]{0x01,0x02});
197 sis = new SpottedInputStream(bis);
199 assertEquals(0L, sis.getPosition());
202 assertEquals(1L, sis.getPosition());
205 assertEquals(2L, sis.getPosition());
208 assertEquals(2L, sis.getPosition());
214 * Test of hasMore method, of class SpottedInputStream.
217 public void testHasMore() throws Exception {
218 System.out.println("hasMore");
220 SpottedInputStream sis;
221 ByteArrayInputStream bis;
223 bis = new ByteArrayInputStream(new byte[]{0x01,0x02});
224 sis = new SpottedInputStream(bis);
226 assertTrue(sis.hasMore());
228 assertTrue(sis.hasMore());
230 assertFalse(sis.hasMore());
235 private static class TestInputStream extends FilterInputStream{
236 public boolean closed = false;
237 public boolean flushed = false;
240 super(new ByteArrayInputStream(new byte[]{}));
245 public void close() throws IOException {