summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2011-05-26 16:21:17 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-05-26 16:21:17 -0700
commitbc359ee522a2defe6cfd9ac78ec9e1730cee19e9 (patch)
tree574f6597c2e007917111cff577a0abbeafbd4aad
parent4966cf7b87f3d7ea2e143dfa04643e3139056f31 (diff)
parent4a89a7c6712e1ee088dc45c23b8a2b8dcb44fcdc (diff)
downloadapache-harmony-bc359ee522a2defe6cfd9ac78ec9e1730cee19e9.tar.gz
Merge "Fix a DatagramChannel test (and improve another)." into dalvik-dev
-rw-r--r--nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
index 172d803..cff718e 100644
--- a/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
+++ b/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
@@ -1483,17 +1483,27 @@ public class DatagramChannelTest extends TestCase {
this.channel1.connect(localAddr2);
this.channel2.send(ByteBuffer.wrap(strHello.getBytes()), localAddr1);
assertEquals(strHello.length(), this.channel1.read(buf));
+ assertAscii(buf, strHello);
}
public void testReceive_Peek_NoSecurity_Nonblocking() throws Exception {
- ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
String strHello = "hello";
localAddr1 = new InetSocketAddress("127.0.0.1", testPort);
this.channel1.socket().bind(localAddr1);
sendByChannel(strHello, localAddr1);
this.channel1.configureBlocking(false);
// for accepted addr, no problem.
- assertNull(this.channel1.receive(buf));
+ ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
+ InetSocketAddress source = (InetSocketAddress) this.channel1.receive(buf);
+ assertEquals(localAddr1.getAddress(), source.getAddress());
+ assertAscii(buf, strHello);
+ }
+
+ private static void assertAscii(ByteBuffer b, String s) {
+ assertEquals(s.length(), b.position());
+ for (int i = 0; i < s.length(); ++i) {
+ assertEquals(s.charAt(i), b.get(i));
+ }
}
// -------------------------------------------------------------------