4 package jp.sourceforge.mikutoga.parser;
6 import java.io.ByteArrayInputStream;
7 import org.junit.After;
8 import org.junit.AfterClass;
9 import org.junit.Before;
10 import org.junit.BeforeClass;
11 import org.junit.Test;
12 import static org.junit.Assert.*;
17 public class MmdInputStreamTest {
19 public MmdInputStreamTest() {
23 public static void setUpClass() {
27 public static void tearDownClass() {
35 public void tearDown() {
39 * Test of parseByte method, of class MmdInputStream.
42 public void testParseByte() throws Exception {
43 System.out.println("parseByte");
46 ByteArrayInputStream bis;
48 bis = new ByteArrayInputStream(new byte[]{0x01, 0x02});
49 mis = new MmdInputStream(bis);
53 result = mis.parseByte();
54 assertEquals(result, (byte)0x01);
56 result = mis.parseByte();
57 assertEquals(result, (byte)0x02);
62 }catch(MmdEofException e){
66 assertEquals(-1, mis.read());
72 * Test of parseBoolean method, of class MmdInputStream.
75 public void testParseBoolean() throws Exception {
76 System.out.println("parseBoolean");
79 ByteArrayInputStream bis;
81 bis = new ByteArrayInputStream(new byte[]{0x00, 0x01, 0x02});
82 mis = new MmdInputStream(bis);
86 result = mis.parseBoolean();
89 result = mis.parseBoolean();
92 result = mis.parseBoolean();
98 }catch(MmdEofException e){
102 assertEquals(-1, mis.read());
108 * Test of parseBeShort method, of class MmdInputStream.
111 public void testParseBeShort() throws Exception {
112 System.out.println("parseBeShort");
115 ByteArrayInputStream bis;
117 bis = new ByteArrayInputStream(new byte[]{0x01, 0x02, 0x03});
118 mis = new MmdInputStream(bis);
122 result = mis.parseBeShort();
123 assertEquals((short)0x0102, result);
128 }catch(MmdEofException e){
132 assertEquals(-1, mis.read());
138 * Test of parseLeShort method, of class MmdInputStream.
141 public void testParseLeShort() throws Exception {
142 System.out.println("parseLeShort");
145 ByteArrayInputStream bis;
147 bis = new ByteArrayInputStream(new byte[]{0x01, 0x02, 0x03});
148 mis = new MmdInputStream(bis);
152 result = mis.parseLeShort();
153 assertEquals((short)0x0201, result);
158 }catch(MmdEofException e){
162 assertEquals(-1, mis.read());
168 * Test of parseBeInt method, of class MmdInputStream.
171 public void testParseBeInt() throws Exception {
172 System.out.println("parseBeInt");
175 ByteArrayInputStream bis;
177 bis = new ByteArrayInputStream(
178 new byte[]{0x01, 0x02, 0x03, 0x04, 0x05});
179 mis = new MmdInputStream(bis);
183 result = mis.parseBeInt();
184 assertEquals(0x01020304, result);
189 }catch(MmdEofException e){
193 assertEquals(-1, mis.read());
199 * Test of parseLeInt method, of class MmdInputStream.
202 public void testParseLeInt() throws Exception {
203 System.out.println("parseLeInt");
206 ByteArrayInputStream bis;
208 bis = new ByteArrayInputStream(
209 new byte[]{0x01, 0x02, 0x03, 0x04, 0x05});
210 mis = new MmdInputStream(bis);
214 result = mis.parseLeInt();
215 assertEquals(0x04030201, result);
220 }catch(MmdEofException e){
224 assertEquals(-1, mis.read());
230 * Test of parseBeFloat method, of class MmdInputStream.
233 public void testParseBeFloat() throws Exception {
234 System.out.println("parseBeFloat");
237 ByteArrayInputStream bis;
239 bis = new ByteArrayInputStream(
240 new byte[]{0x01, 0x02, 0x03, 0x04, 0x05});
241 mis = new MmdInputStream(bis);
245 result = mis.parseBeFloat();
246 assertEquals(Float.intBitsToFloat(0x01020304), result, 0.0f);
251 }catch(MmdEofException e){
255 assertEquals(-1, mis.read());
261 * Test of parseLeFloat method, of class MmdInputStream.
264 public void testParseLeFloat() throws Exception {
265 System.out.println("parseLeFloat");
268 ByteArrayInputStream bis;
270 bis = new ByteArrayInputStream(
271 new byte[]{0x01, 0x02, 0x03, 0x04, 0x05});
272 mis = new MmdInputStream(bis);
276 result = mis.parseLeFloat();
277 assertEquals(Float.intBitsToFloat(0x04030201), result, 0.0f);
282 }catch(MmdEofException e){
286 assertEquals(-1, mis.read());
292 * Test of skipRepeat method, of class MmdInputStream.
295 public void testSkipRepeat() throws Exception {
296 System.out.println("skipRepeat");
299 ByteArrayInputStream bis;
301 bis = new ByteArrayInputStream(new byte[]{0x11, 0x12, 0x13});
302 mis = new MmdInputStream(bis);
308 assertEquals(0x11, result);
310 skipped = mis.skip(1L);
311 assertEquals(1L, skipped);
314 assertEquals(0x13, result);
316 skipped = mis.skip(1L);
317 assertEquals(0L, skipped);
319 // TODO: BufferedInputStreamと組み合わせた時の不思議なskip動作