|
1 | 1 | /* |
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 $ |
5 | 5 | * |
6 | 6 | * ==================================================================== |
7 | 7 | * |
|
70 | 70 |
|
71 | 71 | /** |
72 | 72 | * @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 $ |
74 | 74 | */ |
75 | 75 |
|
76 | 76 | public class EndianUtilsTest extends TestCase { |
@@ -131,6 +131,52 @@ public void testSymmetry() { |
131 | 131 | assertEquals( d1, EndianUtils.swapDouble( EndianUtils.swapDouble( d1 ) ), 0.0 ); |
132 | 132 | } |
133 | 133 |
|
| 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 | + |
134 | 180 | /* |
135 | 181 | // TODO: |
136 | 182 |
|
|
0 commit comments