cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2004/01/01 22:44:26 Modified:io/src/test/org/apache/commons/io EndianUtilsTest.java Log: Implemented tests for the unsigned methods and removed the todo comments Revision ChangesPath 1.8 +13 -8 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- EndianUtilsTest.java 30 Dec 2003 15:26:59 - 1.7 +++ EndianUtilsTest.java 2 Jan 2004 06:44:26 - 1.8 @@ -136,6 +136,11 @@ assertEquals( 0x01, bytes[1] ); } +public void testReadSwappedUnsignedShort() { +byte[] bytes = new byte[] { 0x02, 0x01 }; +assertEquals( 0x0102, EndianUtils.readSwappedUnsignedShort( bytes, 0 ) ); +} + public void testReadSwappedInteger() { byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; int ln = EndianUtils.readSwappedInteger( bytes, 0 ); @@ -151,7 +156,10 @@ assertEquals( 0x01, bytes[3] ); } -// TODO: public void testWriteUnsignedInteger +public void testReadSwappedUnsignedInteger() { +byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; +assertEquals( 0x01020304L, EndianUtils.readSwappedUnsignedInteger( bytes, 0 ) ); +} public void testReadSwappedLong() { byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; @@ -211,9 +219,6 @@ /* // TODO: - -// All readSwappedXxxx(byte[], int) -// All writeSwappedXxxx(byte[], int, ) // All readSwappedXxxx(InputStream) // All writeSwappedXxxx(OutputStream, ) */ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2004/01/01 22:44:54 Modified:io/src/test/org/apache/commons/io EndianUtilsTest.java Log: removed unnecessary line Revision ChangesPath 1.9 +4 -5 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- EndianUtilsTest.java 2 Jan 2004 06:44:26 - 1.8 +++ EndianUtilsTest.java 2 Jan 2004 06:44:54 - 1.9 @@ -143,7 +143,6 @@ public void testReadSwappedInteger() { byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; -int ln = EndianUtils.readSwappedInteger( bytes, 0 ); assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) ); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2003/11/25 23:50:05 Added: io/src/test/org/apache/commons/io EndianUtilsTest.java Log: the beginnings of a unit test for this class Revision ChangesPath 1.1 jakarta-commons-sandbox/io/src/test/org/apache/commons/io/EndianUtilsTest.java Index: EndianUtilsTest.java === /* * $Header: /home/cvs/jakarta-commons-sandbox/io/src/test/org/apache/commons/io/EndianUtilsTest.java,v 1.1 2003/11/26 07:50:05 bayard Exp $ * $Revision: 1.1 $ * $Date: 2003/11/26 07:50:05 $ * * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Commons, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package org.apache.commons.io; import java.io.IOException; import junit.framework.TestCase; /** * @author Henri Yandell (bayard at apache dot org) * @version $Revision: 1.1 $ $Date: 2003/11/26 07:50:05 $ */ public class EndianUtilsTest extends TestCase { public EndianUtilsTest(String name) { super(name); } public void testSwapShort() { // need to study to make up these assertEquals( 1, EndianUtils.swapShort( (short) 256 ) ); } public void testSwapInteger() { assertEquals( 0, EndianUtils.swapInteger( 0 ) ); assertEquals( 0x04030201, EndianUtils.swapInteger( 0x01020304 ) ); assertEquals( 0x0100, EndianUtils.swapInteger( 0x0001 ) ); assertEquals( 0x0001, EndianUtils.swapInteger( 0x0100 ) ); assertEquals( 0x, EndianUtils.swapInteger( 0x ) ); assertEquals( 0xabcdef10, EndianUtils.swapInteger( 0x10efcdab ) ); assertEquals( 0xab, EndianUtils.swapInteger( 0xab00 ) ); } public void testSwapLong() { assertEquals( 0, EndianUtils.swapLong( 0 ) ); assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) ); } // TODO: /* public void testSwapFloat() { } public void testSwapDouble() { } // All readSwappedXxxx(byte[], int) // All writeSwappedXxxx(byte[], int, ) // All readSwappedXxxx(InputStream) // All writeSwappedXxxx(OutputStream, ) */ }
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2003/11/25 23:56:38 Modified:io/src/test/org/apache/commons/io EndianUtilsTest.java Log: Filled things in a bit more test wise. Revision ChangesPath 1.2 +21 -6 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- EndianUtilsTest.java 26 Nov 2003 07:50:05 - 1.1 +++ EndianUtilsTest.java 26 Nov 2003 07:56:38 - 1.2 @@ -80,8 +80,10 @@ } public void testSwapShort() { -// need to study to make up these -assertEquals( 1, EndianUtils.swapShort( (short) 256 ) ); +assertEquals( (short) 0, EndianUtils.swapShort( (short) 0 ) ); +assertEquals( (short) 0x0201, EndianUtils.swapShort( (short) 0x0102 ) ); +assertEquals( (short) 0x, EndianUtils.swapShort( (short) 0x ) ); +assertEquals( (short) 0x0102, EndianUtils.swapShort( (short) 0x0201 ) ); } public void testSwapInteger() { @@ -99,13 +101,26 @@ assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) ); } -// TODO: /* public void testSwapFloat() { } public void testSwapDouble() { } +*/ + +/** + * Tests all swapXxxx methods for symmetry when going from one endian + * to another and back again. + */ +public void testSymmetry() { +assertEquals( (short) 0x0102, EndianUtils.swapShort( EndianUtils.swapShort( (short) 0x0102 ) ) ); +assertEquals( 0x01020304, EndianUtils.swapInteger( EndianUtils.swapInteger( 0x01020304 ) ) ); +assertEquals( 0x0102030405060708L, EndianUtils.swapLong( EndianUtils.swapLong( 0x0102030405060708L ) ) ); +} + +/* +// TODO: // All readSwappedXxxx(byte[], int) // All writeSwappedXxxx(byte[], int, ) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2003/11/26 00:15:32 Modified:io/src/test/org/apache/commons/io EndianUtilsTest.java Log: Can't say I understand Float.intBitsToFloat and the Double.longBitsToDouble, but seems to pass the test well enough. I just have this feeling it should be complaining about lost bits. Revision ChangesPath 1.3 +18 -6 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- EndianUtilsTest.java 26 Nov 2003 07:56:38 - 1.2 +++ EndianUtilsTest.java 26 Nov 2003 08:15:32 - 1.3 @@ -99,15 +99,23 @@ public void testSwapLong() { assertEquals( 0, EndianUtils.swapLong( 0 ) ); assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) ); +assertEquals( 0xL, EndianUtils.swapLong( 0xL ) ); +assertEquals( 0xab, EndianUtils.swapLong( 0xab00L ) ); } -/* public void testSwapFloat() { +assertEquals( 0.0f, EndianUtils.swapFloat( 0.0f ), 0.0 ); +float f1 = Float.intBitsToFloat( 0x01020304 ); +float f2 = Float.intBitsToFloat( 0x04030201 ); +assertEquals( f2, EndianUtils.swapFloat( f1 ), 0.0 ); } public void testSwapDouble() { +assertEquals( 0.0, EndianUtils.swapDouble( 0.0 ), 0.0 ); +double d1 = Double.longBitsToDouble( 0x0102030405060708L ); +double d2 = Double.longBitsToDouble( 0x0807060504030201L ); +assertEquals( d2, EndianUtils.swapDouble( d1 ), 0.0 ); } -*/ /** * Tests all swapXxxx methods for symmetry when going from one endian @@ -117,6 +125,10 @@ assertEquals( (short) 0x0102, EndianUtils.swapShort( EndianUtils.swapShort( (short) 0x0102 ) ) ); assertEquals( 0x01020304, EndianUtils.swapInteger( EndianUtils.swapInteger( 0x01020304 ) ) ); assertEquals( 0x0102030405060708L, EndianUtils.swapLong( EndianUtils.swapLong( 0x0102030405060708L ) ) ); +float f1 = Float.intBitsToFloat( 0x01020304 ); +assertEquals( f1, EndianUtils.swapFloat( EndianUtils.swapFloat( f1 ) ), 0.0 ); +double d1 = Double.longBitsToDouble( 0x0102030405060708L ); +assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 0.0 ); } /* - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
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 ChangesPath 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 - 1.3 +++ EndianUtilsTest.java 27 Nov 2003 04:08:14 - 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]
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2003/11/26 22:27:52 Modified:io/src/test/org/apache/commons/io EndianUtilsTest.java Log: removed unused line and added the read/write float byte methods Revision ChangesPath 1.5 +23 -5 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- EndianUtilsTest.java 27 Nov 2003 04:08:14 - 1.4 +++ EndianUtilsTest.java 27 Nov 2003 06:27:52 - 1.5 @@ -158,9 +158,10 @@ assertEquals( 0x01, bytes[3] ); } +// TODO: public void testWriteUnsignedInteger + 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 ) ); } @@ -175,6 +176,23 @@ assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); +} + +public void testReadSwappedFloat() { +byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; +float f1 = Float.intBitsToFloat( 0x01020304 ); +float f2 = EndianUtils.readSwappedFloat( bytes, 0 ); +assertEquals( f1, f2, 0.0 ); +} + +public void testWriteSwappedFloat() { +byte[] bytes = new byte[4]; +float f1 = Float.intBitsToFloat( 0x01020304 ); +EndianUtils.writeSwappedFloat( bytes, 0, f1 ); +assertEquals( 0x04, bytes[0] ); +assertEquals( 0x03, bytes[1] ); +assertEquals( 0x02, bytes[2] ); +assertEquals( 0x01, bytes[3] ); } /* - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons-sandbox/io/src/test/org/apache/commons/io EndianUtilsTest.java
bayard 2003/11/26 22:30:26 Modified:io/src/test/org/apache/commons/io EndianUtilsTest.java Log: added read/write double byte methods Revision ChangesPath 1.6 +25 -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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- EndianUtilsTest.java 27 Nov 2003 06:27:52 - 1.5 +++ EndianUtilsTest.java 27 Nov 2003 06:30:26 - 1.6 @@ -195,6 +195,27 @@ assertEquals( 0x01, bytes[3] ); } +public void testReadSwappedDouble() { +byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; +double d1 = Double.longBitsToDouble( 0x0102030405060708L ); +double d2 = EndianUtils.readSwappedDouble( bytes, 0 ); +assertEquals( d1, d2, 0.0 ); +} + +public void testWriteSwappedDouble() { +byte[] bytes = new byte[8]; +double d1 = Double.longBitsToDouble( 0x0102030405060708L ); +EndianUtils.writeSwappedDouble( bytes, 0, d1 ); +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]