44 this.testValue = testValue; 45 } 46 static Test create (SocketOption<?> option, Object testValue) { 47 return new Test(option, testValue); 48 } 49 Object option; 50 Object testValue; 51 } 52 53 // The tests set the option using the new API, read back the set value 54 // which could be diferent, and then use the legacy get API to check 55 // these values are the same 56 57 static Test[] socketTests = new Test[] { 58 Test.create(StandardSocketOptions.SO_KEEPALIVE, Boolean.TRUE), 59 Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)), 60 Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), 61 Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), 62 Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), 63 Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(80)), 64 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)) 65 }; 66 67 static Test[] serverSocketTests = new Test[] { 68 Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), 69 Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), 70 Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), 71 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)) 72 }; 73 74 static Test[] dgSocketTests = new Test[] { 75 Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)), 76 Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), 77 Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), 78 Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), 79 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)) 80 }; 81 82 static Test[] mcSocketTests = new Test[] { 83 Test.create(StandardSocketOptions.IP_MULTICAST_IF, getNetworkInterface()), 84 Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(10)), 85 Test.create(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.TRUE) 86 }; 87 88 static NetworkInterface getNetworkInterface() { 89 try { 90 Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); 91 while (nifs.hasMoreElements()) { 92 NetworkInterface ni = (NetworkInterface)nifs.nextElement(); 93 if (ni.supportsMulticast()) { 94 return ni; 95 } 96 } 97 } catch (Exception e) { 98 } 99 return null; 100 } 101 102 static void doSocketTests() throws Exception { 103 try ( 104 ServerSocket srv = new ServerSocket(0, 50, InetAddress.getLoopbackAddress()); | 44 this.testValue = testValue; 45 } 46 static Test create (SocketOption<?> option, Object testValue) { 47 return new Test(option, testValue); 48 } 49 Object option; 50 Object testValue; 51 } 52 53 // The tests set the option using the new API, read back the set value 54 // which could be diferent, and then use the legacy get API to check 55 // these values are the same 56 57 static Test[] socketTests = new Test[] { 58 Test.create(StandardSocketOptions.SO_KEEPALIVE, Boolean.TRUE), 59 Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)), 60 Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), 61 Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), 62 Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), 63 Test.create(StandardSocketOptions.SO_LINGER, Integer.valueOf(80)), 64 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(0)), // lower-bound 65 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)), 66 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(255)) //upper-bound 67 }; 68 69 static Test[] serverSocketTests = new Test[] { 70 Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), 71 Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), 72 Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), 73 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(0)), // lower-bound 74 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)), 75 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(255)) //upper-bound 76 }; 77 78 static Test[] dgSocketTests = new Test[] { 79 Test.create(StandardSocketOptions.SO_SNDBUF, Integer.valueOf(10 * 100)), 80 Test.create(StandardSocketOptions.SO_RCVBUF, Integer.valueOf(8 * 100)), 81 Test.create(StandardSocketOptions.SO_REUSEADDR, Boolean.FALSE), 82 Test.create(StandardSocketOptions.SO_REUSEPORT, Boolean.FALSE), 83 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(0)), // lower-bound 84 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(100)), 85 Test.create(StandardSocketOptions.IP_TOS, Integer.valueOf(255)) //upper-bound 86 }; 87 88 static Test[] mcSocketTests = new Test[] { 89 Test.create(StandardSocketOptions.IP_MULTICAST_IF, getNetworkInterface()), 90 Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(0)), // lower-bound 91 Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(10)), 92 Test.create(StandardSocketOptions.IP_MULTICAST_TTL, Integer.valueOf(255)), //upper-bound 93 Test.create(StandardSocketOptions.IP_MULTICAST_LOOP, Boolean.TRUE) 94 }; 95 96 static NetworkInterface getNetworkInterface() { 97 try { 98 Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); 99 while (nifs.hasMoreElements()) { 100 NetworkInterface ni = (NetworkInterface)nifs.nextElement(); 101 if (ni.supportsMulticast()) { 102 return ni; 103 } 104 } 105 } catch (Exception e) { 106 } 107 return null; 108 } 109 110 static void doSocketTests() throws Exception { 111 try ( 112 ServerSocket srv = new ServerSocket(0, 50, InetAddress.getLoopbackAddress()); |