summaryrefslogtreecommitdiffstats
path: root/tests/CoreTests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-10-08 12:59:43 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-10-08 12:59:43 -0700
commit6190ba5a94ce80ee9bec890d4803e8136c60b921 (patch)
treed74de1bf859d35e6458577fb2112470ca9dfd523 /tests/CoreTests
parente6089612ec1e39e1d03be97f2f9371516da3df19 (diff)
parentddd49c28b0280ee8468e94a8a2c4420c89e504e7 (diff)
downloadframeworks_base-6190ba5a94ce80ee9bec890d4803e8136c60b921.zip
frameworks_base-6190ba5a94ce80ee9bec890d4803e8136c60b921.tar.gz
frameworks_base-6190ba5a94ce80ee9bec890d4803e8136c60b921.tar.bz2
Merge "NIOTest fixes."
Diffstat (limited to 'tests/CoreTests')
-rw-r--r--tests/CoreTests/android/core/NIOTest.java51
1 files changed, 32 insertions, 19 deletions
diff --git a/tests/CoreTests/android/core/NIOTest.java b/tests/CoreTests/android/core/NIOTest.java
index fd279ca..9476d07 100644
--- a/tests/CoreTests/android/core/NIOTest.java
+++ b/tests/CoreTests/android/core/NIOTest.java
@@ -40,27 +40,31 @@ public class NIOTest extends TestCase {
}
@SmallTest
- public void testNIO() throws Exception {
- ByteBuffer b;
-
+ public void testNIO_byte_array() throws Exception {
// Test byte array-based buffer
- b = ByteBuffer.allocate(12);
- byteBufferTest(b);
+ byteBufferTest(ByteBuffer.allocate(12));
+ }
+ public void testNIO_direct() throws Exception {
// Test native heap-allocated buffer
- b = ByteBuffer.allocateDirect(12);
- byteBufferTest(b);
+ byteBufferTest(ByteBuffer.allocateDirect(12));
+ }
+ public void testNIO_short_array() throws Exception {
// Test short array-based buffer
short[] shortArray = new short[8];
ShortBuffer sb = ShortBuffer.wrap(shortArray);
shortBufferTest(sb);
+ }
+ public void testNIO_int_array() throws Exception {
// Test int array-based buffer
int[] intArray = new int[8];
IntBuffer ib = IntBuffer.wrap(intArray);
intBufferTest(ib);
+ }
+ public void testNIO_float_array() throws Exception {
// Test float array-based buffer
float[] floatArray = new float[8];
FloatBuffer fb = FloatBuffer.wrap(floatArray);
@@ -70,6 +74,12 @@ public class NIOTest extends TestCase {
private void byteBufferTest(ByteBuffer b) {
checkBuffer(b);
+ // Duplicate buffers revert to big-endian.
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ ByteBuffer dupe = b.duplicate();
+ assertEquals(ByteOrder.BIG_ENDIAN, dupe.order());
+ b.order(ByteOrder.BIG_ENDIAN);
+
// Bounds checks
try {
b.put(-1, (byte) 0);
@@ -272,9 +282,9 @@ public class NIOTest extends TestCase {
// Check 'getFloat'
b.order(ByteOrder.LITTLE_ENDIAN);
b.position(0);
- assertEquals(0xA3A2A1A0, Float.floatToIntBits(b.getFloat()));
- assertEquals(0xA7A6A5A4, Float.floatToIntBits(b.getFloat()));
- assertEquals(0xABAAA9A8, Float.floatToIntBits(b.getFloat()));
+ assertEquals(0xA3A2A1A0, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xA7A6A5A4, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xABAAA9A8, Float.floatToRawIntBits(b.getFloat()));
try {
b.getFloat();
fail("expected exception not thrown");
@@ -284,9 +294,9 @@ public class NIOTest extends TestCase {
b.order(ByteOrder.BIG_ENDIAN);
b.position(0);
- assertEquals(0xA0A1A2A3, Float.floatToIntBits(b.getFloat()));
- assertEquals(0xA4A5A6A7, Float.floatToIntBits(b.getFloat()));
- assertEquals(0xA8A9AAAB, Float.floatToIntBits(b.getFloat()));
+ assertEquals(0xA0A1A2A3, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xA4A5A6A7, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xA8A9AAAB, Float.floatToRawIntBits(b.getFloat()));
try {
b.getFloat();
fail("expected exception not thrown");
@@ -296,8 +306,8 @@ public class NIOTest extends TestCase {
// Check 'getDouble(int position)'
b.order(ByteOrder.LITTLE_ENDIAN);
- assertEquals(0xA7A6A5A4A3A2A1A0L, Double.doubleToLongBits(b.getDouble(0)));
- assertEquals(0xA8A7A6A5A4A3A2A1L, Double.doubleToLongBits(b.getDouble(1)));
+ assertEquals(0xA7A6A5A4A3A2A1A0L, Double.doubleToRawLongBits(b.getDouble(0)));
+ assertEquals(0xA8A7A6A5A4A3A2A1L, Double.doubleToRawLongBits(b.getDouble(1)));
try {
b.getDouble(-1);
fail("expected exception not thrown");
@@ -312,8 +322,8 @@ public class NIOTest extends TestCase {
}
b.order(ByteOrder.BIG_ENDIAN);
- assertEquals(0xA0A1A2A3A4A5A6A7L, Double.doubleToLongBits(b.getDouble(0)));
- assertEquals(0xA1A2A3A4A5A6A7A8L, Double.doubleToLongBits(b.getDouble(1)));
+ assertEquals(0xA0A1A2A3A4A5A6A7L, Double.doubleToRawLongBits(b.getDouble(0)));
+ assertEquals(0xA1A2A3A4A5A6A7A8L, Double.doubleToRawLongBits(b.getDouble(1)));
try {
b.getDouble(-1);
fail("expected exception not thrown");
@@ -333,6 +343,9 @@ public class NIOTest extends TestCase {
b.order(ByteOrder.LITTLE_ENDIAN);
bb = b.slice();
assertEquals(4, bb.capacity());
+ assertEquals(ByteOrder.BIG_ENDIAN, bb.order());
+ assertEquals(0xA1A2A3A4, bb.getInt(0));
+ bb.order(ByteOrder.LITTLE_ENDIAN);
assertEquals(0xA4A3A2A1, bb.getInt(0));
bb.order(ByteOrder.LITTLE_ENDIAN);
@@ -370,14 +383,14 @@ public class NIOTest extends TestCase {
checkBuffer(fb);
assertEquals(1, fb.capacity());
- assertEquals(0xA4A3A2A1, Float.floatToIntBits(fb.get()));
+ assertEquals(0xA4A3A2A1, Float.floatToRawIntBits(fb.get()));
bb.order(ByteOrder.BIG_ENDIAN);
fb = bb.asFloatBuffer();
checkBuffer(fb);
assertEquals(1, fb.capacity());
- assertEquals(0xA1A2A3A4, Float.floatToIntBits(fb.get()));
+ assertEquals(0xA1A2A3A4, Float.floatToRawIntBits(fb.get()));
}
private void shortBufferTest(ShortBuffer sb) {