JavaNetSocketTestpublic class JavaNetSocketTest extends TestCase
Fields Summary |
---|
SecurityManager | old |
Methods Summary |
---|
protected void | setUp()
old = System.getSecurityManager();
super.setUp();
| protected void | tearDown()
System.setSecurityManager(old);
super.tearDown();
| public void | test_ctor()
class TestSecurityManager extends SecurityManager {
boolean called = false;
String host = null;
int port = -1;
void reset(){
called = false;
host = null;
port = -1;
}
@Override
public void checkConnect(String host, int port) {
this.called = true;
this.port = port;
this.host = host;
}
@Override
public void checkPermission(Permission permission) {
}
}
String host = "www.google.ch";
int port = 80;
String hostAddress = InetAddress.getByName(host).getHostAddress();
TestSecurityManager s = new TestSecurityManager();
System.setSecurityManager(s);
s.reset();
new Socket(host, port);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
s.reset();
new Socket(host, port, true);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
s.reset();
new Socket(host, port, InetAddress.getByAddress(new byte[] {0,0,0,0}), 0);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
s.reset();
new Socket(InetAddress.getByName(host), port);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
s.reset();
new Socket(InetAddress.getByName(host), port, true);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
s.reset();
new Socket(InetAddress.getByName(host), port, InetAddress.getByAddress(new byte[] {0,0,0,0}), 0);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
| public void | test_ctor2()
class TestSecurityManager extends SecurityManager {
boolean called = false;
String host = null;
int port = -1;
void reset(){
called = false;
host = null;
port = -1;
}
@Override
public void checkConnect(String host, int port) {
this.called = true;
this.port = port;
this.host = host;
}
@Override
public void checkPermission(Permission permission) {
}
}
String host = "www.google.ch";
int port = 80;
String hostAddress = InetAddress.getByName(host).getHostAddress();
TestSecurityManager s = new TestSecurityManager();
System.setSecurityManager(s);
s.reset();
new Socket(InetAddress.getByName(host), port, InetAddress.getLocalHost(), 0);
assertTrue("java.net.ServerSocket ctor must call checkConnect on security permissions", s.called);
assertEquals("Argument of checkConnect is not correct", hostAddress, s.host);
assertEquals("Argument of checkConnect is not correct", port, s.port);
|
|