FileDocCategorySizeDatePackage
SocketTestCase.javaAPI DocAndroid 1.5 API5668Wed May 06 22:41:04 BST 2009tests.api.java.net

SocketTestCase

public abstract class SocketTestCase extends TestCase

Fields Summary
public static final int
SO_MULTICAST
public static final int
SO_MULTICAST_INTERFACE
public static final int
SO_LINGER
public static final int
SO_RCVBUF
public static final int
SO_TIMEOUT
public static final int
SO_SNDBUF
public static final int
TCP_NODELAY
public static final int
SO_KEEPALIVE
public static final int
SO_REUSEADDR
public static final int
SO_OOBINLINE
public static final int
IP_TOS
public static final int
SO_BROADCAST
public static final int
SO_USELOOPBACK
public static final String
LINUX
private static final String
osDoesNotSupportOperationString
private static final String
osDoesNotSupportOptionString
private static final String
osDoesNotSupportOptionArgumentString
Constructors Summary
public SocketTestCase()


      
    
public SocketTestCase(String name)

        super(name);
    
Methods Summary
public voidensureExceptionThrownIfOptionIsUnsupportedOnOS(int option)
This method should be called at the end of a socket option test's code but before the exception catch statements. It throws a failure if the option given is not supported on the current platform but the VM failed to throw an exception. So, on platforms which do not support the option, the execution should never get to this method.

        if (!getOptionIsSupported(option)) {
            String platform = System.getProperty("os.name");
            String version = System.getProperty("os.version");
            fail("Failed to throw exception for unsupported socket option: "
                    + getSocketOptionString(option));
        }
    
public booleangetOptionIsSupported(int option)
Answer whether the OS supports the given socket option.

        switch (option) {
        case SO_RCVBUF:
        case SO_SNDBUF:
            return true;
        case SO_MULTICAST:
        case SO_MULTICAST_INTERFACE:
        case SO_LINGER:
            return true;
        case TCP_NODELAY:
        case SO_TIMEOUT:
            return true;
        case SO_KEEPALIVE:
        case SO_REUSEADDR:
            return true;
        case SO_OOBINLINE:
            return true;
        case IP_TOS:
            return true;
        case SO_BROADCAST:
            return true;
        case SO_USELOOPBACK:
            return true;
        }
        return false;
    
private java.lang.StringgetSocketOptionString(int option)
Answer a string for the socket option given.

        switch (option) {
        case SO_MULTICAST:
            return "Multicast";
        case SO_LINGER:
            return "Linger";
        case SO_RCVBUF:
            return "Receive buffer size";
        case SO_TIMEOUT:
            return "Socket timeout";
        case SO_SNDBUF:
            return "Send buffer size";
        case TCP_NODELAY:
            return "TCP no delay";
        case SO_KEEPALIVE:
            return "Keepalive";
        case SO_REUSEADDR:
            return "Reuse address";
        case SO_OOBINLINE:
            return "out of band data inline";
        case IP_TOS:
            return "Traffic class";
        case SO_BROADCAST:
            return "broadcast";
        case SO_USELOOPBACK:
            return "loopback";
        }
        return "Unknown socket option";
    
public voidhandleException(java.lang.Exception e, int option)
If the exception is "socket does not support the operation" exception and it is expected on the current platform, do nothing. Otherwise, fail the test.

        if (!getOptionIsSupported(option)) {
            String message = e.getMessage();
            if (message != null
                    && (message.equals(osDoesNotSupportOperationString)
                            || message.equals(osDoesNotSupportOptionString) || message
                            .equals(osDoesNotSupportOptionArgumentString))) {
                /*
                 * This exception is the correct behavior for platforms which do
                 * not support the option
                 */
            } else {
                fail("Threw \""
                        + e
                        + "\" instead of correct exception for unsupported socket option: "
                        + getSocketOptionString(option));
            }
        } else {
            fail("Exception during test : " + e.getMessage());
        }