bayard      2004/02/29 13:46:17

  Modified:    io/src/test/org/apache/commons/io EndianUtilsTest.java
  Log:
  added all writeSwapped(OutputStream) methods
  
  Revision  Changes    Path
  1.12      +52 -11    
jakarta-commons/io/src/test/org/apache/commons/io/EndianUtilsTest.java
  
  Index: EndianUtilsTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/io/src/test/org/apache/commons/io/EndianUtilsTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EndianUtilsTest.java      29 Feb 2004 21:34:14 -0000      1.11
  +++ EndianUtilsTest.java      29 Feb 2004 21:46:17 -0000      1.12
  @@ -90,11 +90,17 @@
           assertEquals( 0x0102, EndianUtils.readSwappedShort( input ) );
       }
   
  -    public void testWriteSwappedShort() {
  +    public void testWriteSwappedShort() throws IOException {
           byte[] bytes = new byte[2];
           EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 );
           assertEquals( 0x02, bytes[0] );
           assertEquals( 0x01, bytes[1] );
  +
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream(2);
  +        EndianUtils.writeSwappedShort( baos, (short) 0x0102 );
  +        bytes = baos.toByteArray();
  +        assertEquals( 0x02, bytes[0] );
  +        assertEquals( 0x01, bytes[1] );
       }
   
       public void testReadSwappedUnsignedShort() throws IOException {
  @@ -111,13 +117,21 @@
           assertEquals( 0x01020304, EndianUtils.readSwappedInteger( input ) );
       }
   
  -    public void testWriteSwappedInteger() {
  +    public void testWriteSwappedInteger() throws IOException {
           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] );
  +
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream(4);
  +        EndianUtils.writeSwappedInteger( baos, 0x01020304 );
  +        bytes = baos.toByteArray();
  +        assertEquals( 0x04, bytes[0] );
  +        assertEquals( 0x03, bytes[1] );
  +        assertEquals( 0x02, bytes[2] );
  +        assertEquals( 0x01, bytes[3] );
       }
   
       public void testReadSwappedUnsignedInteger() throws IOException {
  @@ -134,7 +148,7 @@
           assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( input ) );
       }
   
  -    public void testWriteSwappedLong() {
  +    public void testWriteSwappedLong() throws IOException {
           byte[] bytes = new byte[8];
           EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L );
           assertEquals( 0x08, bytes[0] );
  @@ -145,6 +159,18 @@
           assertEquals( 0x03, bytes[5] );
           assertEquals( 0x02, bytes[6] );
           assertEquals( 0x01, bytes[7] );
  +
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
  +        EndianUtils.writeSwappedLong( baos, 0x0102030405060708L );
  +        bytes = baos.toByteArray();
  +        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] );
       }
   
       public void testReadSwappedFloat() throws IOException {
  @@ -156,7 +182,7 @@
           assertEquals( f1, EndianUtils.readSwappedFloat( input ), 0.0 );
       }
   
  -    public void testWriteSwappedFloat() {
  +    public void testWriteSwappedFloat() throws IOException {
           byte[] bytes = new byte[4];
           float f1 = Float.intBitsToFloat( 0x01020304 );
           EndianUtils.writeSwappedFloat( bytes, 0, f1 );
  @@ -164,6 +190,14 @@
           assertEquals( 0x03, bytes[1] );
           assertEquals( 0x02, bytes[2] );
           assertEquals( 0x01, bytes[3] );
  +
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream(4);
  +        EndianUtils.writeSwappedFloat( baos, f1 );
  +        bytes = baos.toByteArray();
  +        assertEquals( 0x04, bytes[0] );
  +        assertEquals( 0x03, bytes[1] );
  +        assertEquals( 0x02, bytes[2] );
  +        assertEquals( 0x01, bytes[3] );
       }
   
       public void testReadSwappedDouble() throws IOException {
  @@ -175,7 +209,7 @@
           assertEquals( d1, EndianUtils.readSwappedDouble( input ), 0.0 );
       }
   
  -    public void testWriteSwappedDouble() {
  +    public void testWriteSwappedDouble() throws IOException {
           byte[] bytes = new byte[8];
           double d1 = Double.longBitsToDouble( 0x0102030405060708L );
           EndianUtils.writeSwappedDouble( bytes, 0, d1 );
  @@ -187,11 +221,18 @@
           assertEquals( 0x03, bytes[5] );
           assertEquals( 0x02, bytes[6] );
           assertEquals( 0x01, bytes[7] );
  -    }
   
  -    /*
  -    // TODO:
  -    // All writeSwappedXxxx(OutputStream, xxxx)
  -    */
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
  +        EndianUtils.writeSwappedDouble( baos, d1 );
  +        bytes = baos.toByteArray();
  +        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] );
  +    }
   
   }
  
  
  

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

Reply via email to