diff options
author | Jesse Wilson <jessewilson@google.com> | 2009-09-25 16:04:59 -0700 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2009-09-26 09:28:17 -0700 |
commit | e78fcbac04f3b0a8e6a287db321abfc25b6131de (patch) | |
tree | 082d823e6230b6b4ccc449bd973a43eb66446e81 /tests/CoreTests | |
parent | 057018399c7ce6d3893ee5fc622f1592f51773b9 (diff) | |
download | frameworks_base-e78fcbac04f3b0a8e6a287db321abfc25b6131de.zip frameworks_base-e78fcbac04f3b0a8e6a287db321abfc25b6131de.tar.gz frameworks_base-e78fcbac04f3b0a8e6a287db321abfc25b6131de.tar.bz2 |
DO NOT MERGE: Cleaning up the PipedStreamTest
Diffstat (limited to 'tests/CoreTests')
-rw-r--r-- | tests/CoreTests/android/core/PipedStreamTest.java | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/tests/CoreTests/android/core/PipedStreamTest.java b/tests/CoreTests/android/core/PipedStreamTest.java index 564b337..d98bc10 100644 --- a/tests/CoreTests/android/core/PipedStreamTest.java +++ b/tests/CoreTests/android/core/PipedStreamTest.java @@ -117,7 +117,7 @@ public class PipedStreamTest extends TestCase { for (; ;) { try { reader.join(60 * 1000); - writer.join(1 * 1000); + writer.join(1000); break; } catch (InterruptedException ex) { } @@ -166,11 +166,11 @@ public class PipedStreamTest extends TestCase { int readInt = (((int) readBytes[0] & 0xff) << 24) | (((int) readBytes[1] & 0xff) << 16) | (((int) readBytes[2] & 0xff) << 8) - | (((int) readBytes[3] & 0xff) << 0); + | (((int) readBytes[3] & 0xff)); - assertEquals(readInt, fib.next()); - assertEquals(0, readBytes[4]); + assertEquals("Error at " + countRead, fib.next(), readInt); + assertEquals("Error at " + countRead, 0, readBytes[4]); countRead++; } } @@ -189,7 +189,7 @@ public class PipedStreamTest extends TestCase { writeBytes[0] = (byte) (toWrite >> 24); writeBytes[1] = (byte) (toWrite >> 16); writeBytes[2] = (byte) (toWrite >> 8); - writeBytes[3] = (byte) (toWrite >> 0); + writeBytes[3] = (byte) (toWrite); writeBytes[4] = 0; out.write(writeBytes, 0, writeBytes.length); } @@ -203,37 +203,35 @@ public class PipedStreamTest extends TestCase { for (; ;) { try { reader.join(60 * 1000); - writer.join(1 * 1000); + writer.join(1000); break; } catch (InterruptedException ex) { } } - assertEquals(2000, reader.countRead); - - if (writer.exception != null) { - throw new Exception(writer.exception); - } if (reader.exception != null) { throw new Exception(reader.exception); } + if (writer.exception != null) { + throw new Exception(writer.exception); + } + + assertEquals(2000, reader.countRead); } @SmallTest public void testC() throws Exception { final PipedInputStream in = new PipedInputStream(); final PipedOutputStream out = new PipedOutputStream(in); + final byte readBytes[] = new byte[1024 * 2]; assertEquals(0, in.available()); TestThread reader, writer; reader = new TestThread() { - Fibonacci fib = new Fibonacci(); - @Override public void runTest() throws Exception { - byte readBytes[] = new byte[1024 * 2]; int ret; for (; ;) { @@ -246,17 +244,6 @@ public class PipedStreamTest extends TestCase { } nread += ret; } - - assertEquals(nread, readBytes.length); - - for (int i = 0; i < (readBytes.length - 4); i += 4) { - int readInt = (((int) readBytes[i + 0] & 0xff) << 24) - | (((int) readBytes[i + 1] & 0xff) << 16) - | (((int) readBytes[i + 2] & 0xff) << 8) - | (((int) readBytes[i + 3] & 0xff) << 0); - - assertEquals(readInt, fib.next()); - } } } }; @@ -271,10 +258,10 @@ public class PipedStreamTest extends TestCase { byte writeBytes[] = new byte[1024 * 2]; for (int i = 0; i < (writeBytes.length - 4); i += 4) { int toWrite = fib.next(); - writeBytes[i + 0] = (byte) (toWrite >> 24); + writeBytes[i ] = (byte) (toWrite >> 24); writeBytes[i + 1] = (byte) (toWrite >> 16); writeBytes[i + 2] = (byte) (toWrite >> 8); - writeBytes[i + 3] = (byte) (toWrite >> 0); + writeBytes[i + 3] = (byte) (toWrite); } out.write(writeBytes, 0, writeBytes.length); out.close(); @@ -287,17 +274,27 @@ public class PipedStreamTest extends TestCase { for (; ;) { try { reader.join(60 * 1000); - writer.join(1 * 100); + writer.join(1000); break; } catch (InterruptedException ex) { } } + if (reader.exception != null) { + throw new Exception(reader.exception); + } if (writer.exception != null) { throw new Exception(writer.exception); } - if (reader.exception != null) { - throw new Exception(reader.exception); + + Fibonacci fib = new Fibonacci(); + for (int i = 0; i < (readBytes.length - 4); i += 4) { + int readInt = (((int) readBytes[i] & 0xff) << 24) + | (((int) readBytes[i + 1] & 0xff) << 16) + | (((int) readBytes[i + 2] & 0xff) << 8) + | (((int) readBytes[i + 3] & 0xff)); + + assertEquals("Error at " + i, readInt, fib.next()); } } } |