コード例 #1
0
  public void testAccessors() throws IOException {
    LocalSocket socket = new LocalSocket();
    LocalSocketAddress addr = new LocalSocketAddress("secondary");

    assertFalse(socket.isBound());
    socket.bind(addr);
    assertTrue(socket.isBound());
    assertEquals(addr, socket.getLocalSocketAddress());

    String str = socket.toString();
    assertTrue(str.contains("impl:android.net.LocalSocketImpl"));

    socket.setReceiveBufferSize(1999);
    assertEquals(1999 << 1, socket.getReceiveBufferSize());

    socket.setSendBufferSize(3998);
    assertEquals(3998 << 1, socket.getSendBufferSize());

    // Timeout is not support at present, so set is ignored
    socket.setSoTimeout(1996);
    assertEquals(0, socket.getSoTimeout());

    try {
      socket.getRemoteSocketAddress();
      fail("testLocalSocketSecondary shouldn't come to here");
    } catch (UnsupportedOperationException e) {
      // expected
    }

    try {
      socket.isClosed();
      fail("testLocalSocketSecondary shouldn't come to here");
    } catch (UnsupportedOperationException e) {
      // expected
    }

    try {
      socket.isInputShutdown();
      fail("testLocalSocketSecondary shouldn't come to here");
    } catch (UnsupportedOperationException e) {
      // expected
    }

    try {
      socket.isOutputShutdown();
      fail("testLocalSocketSecondary shouldn't come to here");
    } catch (UnsupportedOperationException e) {
      // expected
    }

    try {
      socket.connect(addr, 2005);
      fail("testLocalSocketSecondary shouldn't come to here");
    } catch (UnsupportedOperationException e) {
      // expected
    }
  }