Skip to content

Commit 7df318b

Browse files
committed
Added unit tests for the read/write methods for short/int/long with byte[].
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140434 13f79535-47bb-0310-9956-ffa450edef68
1 parent d0efecf commit 7df318b

1 file changed

Lines changed: 50 additions & 4 deletions

File tree

src/test/org/apache/commons/io/EndianUtilsTest.java

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//io/src/test/org/apache/commons/io/EndianUtilsTest.java,v 1.3 2003/11/26 08:15:32 bayard Exp $
3-
* $Revision: 1.3 $
4-
* $Date: 2003/11/26 08:15:32 $
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//io/src/test/org/apache/commons/io/EndianUtilsTest.java,v 1.4 2003/11/27 04:08:14 bayard Exp $
3+
* $Revision: 1.4 $
4+
* $Date: 2003/11/27 04:08:14 $
55
*
66
* ====================================================================
77
*
@@ -70,7 +70,7 @@
7070

7171
/**
7272
* @author Henri Yandell (bayard at apache dot org)
73-
* @version $Revision: 1.3 $ $Date: 2003/11/26 08:15:32 $
73+
* @version $Revision: 1.4 $ $Date: 2003/11/27 04:08:14 $
7474
*/
7575

7676
public class EndianUtilsTest extends TestCase {
@@ -131,6 +131,52 @@ public void testSymmetry() {
131131
assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 0.0 );
132132
}
133133

134+
public void testReadSwappedShort() {
135+
byte[] bytes = new byte[] { 0x02, 0x01 };
136+
assertEquals( 0x0102, EndianUtils.readSwappedShort( bytes, 0 ) );
137+
}
138+
139+
public void testWriteSwappedShort() {
140+
byte[] bytes = new byte[2];
141+
EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 );
142+
assertEquals( 0x02, bytes[0] );
143+
assertEquals( 0x01, bytes[1] );
144+
}
145+
146+
public void testReadSwappedInteger() {
147+
byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 };
148+
int ln = EndianUtils.readSwappedInteger( bytes, 0 );
149+
assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) );
150+
}
151+
152+
public void testWriteSwappedInteger() {
153+
byte[] bytes = new byte[4];
154+
EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 );
155+
assertEquals( 0x04, bytes[0] );
156+
assertEquals( 0x03, bytes[1] );
157+
assertEquals( 0x02, bytes[2] );
158+
assertEquals( 0x01, bytes[3] );
159+
}
160+
161+
public void testReadSwappedLong() {
162+
byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
163+
long ln = EndianUtils.readSwappedLong( bytes, 0 );
164+
assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( bytes, 0 ) );
165+
}
166+
167+
public void testWriteSwappedLong() {
168+
byte[] bytes = new byte[8];
169+
EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L );
170+
assertEquals( 0x08, bytes[0] );
171+
assertEquals( 0x07, bytes[1] );
172+
assertEquals( 0x06, bytes[2] );
173+
assertEquals( 0x05, bytes[3] );
174+
assertEquals( 0x04, bytes[4] );
175+
assertEquals( 0x03, bytes[5] );
176+
assertEquals( 0x02, bytes[6] );
177+
assertEquals( 0x01, bytes[7] );
178+
}
179+
134180
/*
135181
// TODO:
136182

0 commit comments

Comments
 (0)