1 16 17 18 package org.apache.commons.io.input; 19 20 21 import java.io.ByteArrayInputStream ; 22 import java.io.IOException ; 23 24 import junit.framework.TestCase; 25 26 27 34 35 public class SwappedDataInputStreamTest extends TestCase { 36 37 private SwappedDataInputStream sdis; 38 private byte[] bytes; 39 40 public SwappedDataInputStreamTest(String name) { 41 super(name); 42 } 43 44 public void setUp() { 45 bytes = new byte[] { 46 0x01, 47 0x02, 48 0x03, 49 0x04, 50 0x05, 51 0x06, 52 0x07, 53 0x08 54 }; 55 ByteArrayInputStream bais = new ByteArrayInputStream ( bytes ); 56 this.sdis = new SwappedDataInputStream( bais ); 57 } 58 59 public void tearDown() { 60 this.sdis = null; 61 } 62 63 public void testReadBoolean() throws IOException { 64 assertEquals( false, this.sdis.readBoolean() ); 65 } 66 67 public void testReadByte() throws IOException { 68 assertEquals( 0x01, this.sdis.readByte() ); 69 } 70 71 public void testReadChar() throws IOException { 72 assertEquals( (char) 0x0201, this.sdis.readChar() ); 73 } 74 75 public void testReadDouble() throws IOException { 76 assertEquals( Double.longBitsToDouble(0x0807060504030201L), this.sdis.readDouble(), 0 ); 77 } 78 79 public void testReadFloat() throws IOException { 80 assertEquals( Float.intBitsToFloat(0x04030201), this.sdis.readFloat(), 0 ); 81 } 82 83 public void testReadFully() throws IOException { 84 byte[] bytesIn = new byte[8]; 85 this.sdis.readFully(bytesIn); 86 for( int i=0; i<8; i++) { 87 assertEquals( bytes[i], bytesIn[i] ); 88 } 89 } 90 91 public void testReadInt() throws IOException { 92 assertEquals( (int) 0x04030201, this.sdis.readInt() ); 93 } 94 95 public void testReadLine() throws IOException { 96 try { 97 String unexpected = this.sdis.readLine(); 98 fail("readLine should be unsupported. "); 99 } catch(UnsupportedOperationException uoe) { 100 } 101 } 102 103 public void testReadLong() throws IOException { 104 assertEquals( 0x0807060504030201L, this.sdis.readLong() ); 105 } 106 107 public void testReadShort() throws IOException { 108 assertEquals( (short) 0x0201, this.sdis.readShort() ); 109 } 110 111 public void testReadUnsignedByte() throws IOException { 112 assertEquals( 0x01, this.sdis.readUnsignedByte() ); 113 } 114 115 public void testReadUnsignedShort() throws IOException { 116 assertEquals( (short) 0x0201, this.sdis.readUnsignedShort() ); 117 } 118 119 public void testReadUTF() throws IOException { 120 try { 121 String unexpected = this.sdis.readUTF(); 122 fail("readUTF should be unsupported. "); 123 } catch(UnsupportedOperationException uoe) { 124 } 125 } 126 127 public void testSkipBytes() throws IOException { 128 this.sdis.skipBytes(4); 129 assertEquals( (int)0x08070605, this.sdis.readInt() ); 130 } 131 132 } 133 | Popular Tags |