use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method testSocket_BasicStatusBeforeConnect.
// -------------------------------------------------------------------
// Test for socket()
// -------------------------------------------------------------------
/**
* Test method for 'DatagramChannelImpl.socket()'
*/
public void testSocket_BasicStatusBeforeConnect() throws Exception {
final DatagramChannel dc = DatagramChannel.open();
// not connected
assertFalse(dc.isConnected());
DatagramSocket s1 = dc.socket();
assertFalse(s1.isBound());
assertFalse(s1.isClosed());
assertFalse(s1.isConnected());
assertFalse(s1.getBroadcast());
assertFalse(s1.getReuseAddress());
assertNull(s1.getInetAddress());
assertTrue(s1.getLocalAddress().isAnyLocalAddress());
assertEquals(s1.getLocalPort(), 0);
assertNull(s1.getLocalSocketAddress());
assertEquals(s1.getPort(), -1);
assertTrue(s1.getReceiveBufferSize() >= 8192);
assertNull(s1.getRemoteSocketAddress());
assertFalse(s1.getReuseAddress());
assertTrue(s1.getSendBufferSize() >= 8192);
assertEquals(s1.getSoTimeout(), 0);
assertEquals(s1.getTrafficClass(), 0);
DatagramSocket s2 = dc.socket();
// same
assertSame(s1, s2);
dc.close();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method testSocket_Block_BasicStatusAfterConnect.
/**
* Test method for 'DatagramChannelImpl.socket()'
*/
public void testSocket_Block_BasicStatusAfterConnect() throws IOException {
final DatagramChannel dc = DatagramChannel.open();
dc.connect(datagramSocket1Address);
DatagramSocket s1 = dc.socket();
assertSocketAfterConnect(s1);
DatagramSocket s2 = dc.socket();
// same
assertSame(s1, s2);
dc.close();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_read_LByteBuffer_closed_nullBuf.
/**
* @tests DatagramChannel#read(ByteBuffer)
*/
public void test_read_LByteBuffer_closed_nullBuf() throws Exception {
// regression test for Harmony-754
ByteBuffer c = null;
DatagramChannel channel = DatagramChannel.open();
channel.close();
try {
channel.read(c);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_bind_null.
public void test_bind_null() throws Exception {
DatagramChannel dc = DatagramChannel.open();
try {
assertNull(dc.socket().getLocalSocketAddress());
dc.socket().bind(null);
InetSocketAddress localAddress = (InetSocketAddress) dc.socket().getLocalSocketAddress();
assertTrue(localAddress.getAddress().isAnyLocalAddress());
assertTrue(localAddress.getPort() > 0);
} finally {
dc.close();
}
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method testReceive_UnboundBufNotEmpty.
public void testReceive_UnboundBufNotEmpty() throws Exception {
DatagramChannel dc = DatagramChannel.open();
assertFalse(dc.isConnected());
assertFalse(dc.socket().isBound());
ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
// buf is not empty
dst.put((byte) 88);
assertEquals(dst.position() + CAPACITY_NORMAL - 1, dst.limit());
assertNull(dc.receive(dst));
dc.close();
}
Aggregations