bayard      2003/11/26 20:08:14

  Modified:    io/src/test/org/apache/commons/io EndianUtilsTest.java
  Log:
  Added unit tests for the read/write methods for short/int/long with byte[].
  
  Revision  Changes    Path
  1.4       +50 -4     
jakarta-commons-sandbox/io/src/test/org/apache/commons/io/EndianUtilsTest.java
  
  Index: EndianUtilsTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/io/src/test/org/apache/commons/io/EndianUtilsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EndianUtilsTest.java      26 Nov 2003 08:15:32 -0000      1.3
  +++ EndianUtilsTest.java      27 Nov 2003 04:08:14 -0000      1.4
  @@ -131,6 +131,52 @@
           assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 
0.0 );
       }
   
  +    public void testReadSwappedShort() {
  +        byte[] bytes = new byte[] { 0x02, 0x01 };
  +        assertEquals( 0x0102, EndianUtils.readSwappedShort( bytes, 0 ) );
  +    }
  +
  +    public void testWriteSwappedShort() {
  +        byte[] bytes = new byte[2];
  +        EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 );
  +        assertEquals( 0x02, bytes[0] );
  +        assertEquals( 0x01, bytes[1] );
  +    }
  +
  +    public void testReadSwappedInteger() {
  +        byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
  +        int ln = EndianUtils.readSwappedInteger( bytes, 0 );
  +        assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) );
  +    }
  +
  +    public void testWriteSwappedInteger() {
  +        byte[] bytes = new byte[4];
  +        EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 );
  +        assertEquals( 0x04, bytes[0] );
  +        assertEquals( 0x03, bytes[1] );
  +        assertEquals( 0x02, bytes[2] );
  +        assertEquals( 0x01, bytes[3] );
  +    }
  +
  +    public void testReadSwappedLong() {
  +        byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 
};
  +        long ln = EndianUtils.readSwappedLong( bytes, 0 );
  +        assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( bytes, 0 ) 
);
  +    }
  +
  +    public void testWriteSwappedLong() {
  +        byte[] bytes = new byte[8];
  +        EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L );
  +        assertEquals( 0x08, bytes[0] );
  +        assertEquals( 0x07, bytes[1] );
  +        assertEquals( 0x06, bytes[2] );
  +        assertEquals( 0x05, bytes[3] );
  +        assertEquals( 0x04, bytes[4] );
  +        assertEquals( 0x03, bytes[5] );
  +        assertEquals( 0x02, bytes[6] );
  +        assertEquals( 0x01, bytes[7] );
  +    }
  +
       /*
       // TODO:
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to