use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_socket_IllegalBlockingModeException.
/**
* @tests DatagramChannel#socket()
*/
public void test_socket_IllegalBlockingModeException() throws Exception {
// regression test for Harmony-1036
DatagramChannel channel = DatagramChannel.open();
channel.configureBlocking(false);
DatagramSocket socket = channel.socket();
try {
socket.send(null);
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
try {
socket.receive(null);
fail("should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
channel.close();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_getLocalSocketAddress_afterClose.
public void test_getLocalSocketAddress_afterClose() throws IOException {
DatagramChannel dc = DatagramChannel.open();
assertNull(dc.socket().getLocalSocketAddress());
InetSocketAddress bindAddr = new InetSocketAddress("localhost", 0);
dc.socket().bind(bindAddr);
assertNotNull(dc.socket().getLocalSocketAddress());
dc.close();
assertFalse(dc.isOpen());
dc.socket().getLocalSocketAddress();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method testReadWrite_NonBlock_WriterNotBound.
public void testReadWrite_NonBlock_WriterNotBound() throws Exception {
byte[] sourceArray = new byte[CAPACITY_NORMAL];
byte[] targetArray = new byte[CAPACITY_NORMAL];
for (int i = 0; i < sourceArray.length; i++) {
sourceArray[i] = (byte) i;
}
DatagramChannel dc = DatagramChannel.open();
// The writer isn't bound, but is connected.
dc.connect(channel1Address);
dc.configureBlocking(false);
channel2.configureBlocking(false);
// write
ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
assertEquals(CAPACITY_NORMAL, dc.write(sourceBuf));
// Connect channel2 after data has been written.
channel2.connect(dc.socket().getLocalSocketAddress());
// read
ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
assertEquals(0, this.channel2.read(targetBuf));
dc.close();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_send_LBuffer_LSocketAddress_PositionNotZero.
public void test_send_LBuffer_LSocketAddress_PositionNotZero() throws Exception {
// regression test for Harmony-701
int CAPACITY_NORMAL = 256;
int position = 16;
DatagramChannel dc = DatagramChannel.open();
byte[] sourceArray = new byte[CAPACITY_NORMAL];
// send ByteBuffer whose position is not zero
ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
sourceBuf.position(position);
int ret = dc.send(sourceBuf, datagramSocket1Address);
// assert send (256 - 16) bytes
assertEquals(CAPACITY_NORMAL - position, ret);
// assert the position of ByteBuffer has been set
assertEquals(CAPACITY_NORMAL, sourceBuf.position());
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelMulticastTest method test_joinAnySource_nonMulticastGroupAddress_IPv6.
public void test_joinAnySource_nonMulticastGroupAddress_IPv6() throws Exception {
if (!supportsMulticast) {
return;
}
DatagramChannel dc = createReceiverChannel();
try {
dc.join(UNICAST_IPv6_1, ipv6NetworkInterface);
fail();
} catch (IllegalArgumentException expected) {
}
dc.close();
}
Aggregations