Methods Summary |
---|
public void | ensureExceptionThrownIfOptionIsUnsupportedOnOS(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 boolean | getOptionIsSupported(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.String | getSocketOptionString(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 void | handleException(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());
}
|