author | igerasim |
Tue, 27 Mar 2018 13:22:40 -0700 | |
changeset 49431 | 5812849b5027 |
parent 47216 | 71c04702a3d5 |
child 54681 | edd709e64ea1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49431
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6505016 |
|
49431
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
27 |
* @summary Socket spec should clarify what getInetAddress/getPort/etc return |
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
28 |
* after the Socket is closed |
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
29 |
* @run main TestAfterClose |
5812849b5027
8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents:
47216
diff
changeset
|
30 |
* @run main/othervm -Djava.net.preferIPv4Stack=true TestAfterClose |
2 | 31 |
*/ |
32 |
||
33 |
import java.net.*; |
|
34 |
import java.io.*; |
|
35 |
||
36 |
public class TestAfterClose |
|
37 |
{ |
|
38 |
static int failCount; |
|
39 |
||
40 |
public static void main(String[] args) { |
|
41 |
try { |
|
42 |
ServerSocket ss = new ServerSocket(0, 0, null); |
|
43 |
Socket socket = new Socket("localhost", ss.getLocalPort()); |
|
44 |
ss.accept(); |
|
45 |
ss.close(); |
|
46 |
test(socket); |
|
47 |
} catch (IOException ioe) { |
|
48 |
ioe.printStackTrace(); |
|
49 |
} |
|
50 |
||
51 |
if (failCount > 0) |
|
52 |
throw new RuntimeException("Failed: failcount = " + failCount); |
|
53 |
||
54 |
} |
|
55 |
||
56 |
static void test(Socket socket) throws IOException { |
|
57 |
//Before Close |
|
58 |
int socketPort = socket.getPort(); |
|
59 |
InetAddress socketInetAddress = socket.getInetAddress(); |
|
60 |
SocketAddress socketRemoteSocketAddress = socket.getRemoteSocketAddress(); |
|
61 |
int socketLocalPort = socket.getLocalPort(); |
|
62 |
||
63 |
//After Close |
|
64 |
socket.close(); |
|
65 |
||
66 |
if (socketPort != socket.getPort()) { |
|
67 |
System.out.println("Socket.getPort failed"); |
|
68 |
failCount++; |
|
69 |
} |
|
70 |
||
71 |
if (!socket.getInetAddress().equals(socketInetAddress)) { |
|
72 |
System.out.println("Socket.getInetAddress failed"); |
|
73 |
failCount++; |
|
74 |
} |
|
75 |
||
76 |
if (!socket.getRemoteSocketAddress().equals(socketRemoteSocketAddress)) { |
|
77 |
System.out.println("Socket.getRemoteSocketAddresss failed"); |
|
78 |
failCount++; |
|
79 |
} |
|
80 |
||
81 |
if (socketLocalPort != socket.getLocalPort()) { |
|
82 |
System.out.println("Socket.getLocalPort failed"); |
|
83 |
failCount++; |
|
84 |
} |
|
85 |
||
86 |
InetAddress anyAddr = null; |
|
87 |
try { |
|
88 |
anyAddr = InetAddress.getByAddress("",new byte[] {0,0,0,0}); |
|
89 |
} catch (UnknownHostException uhe) { |
|
90 |
} |
|
91 |
||
92 |
if (anyAddr != null && !socket.getLocalAddress().equals(anyAddr)) { |
|
93 |
System.out.println("Socket.getLocalAddress failed"); |
|
94 |
failCount++; |
|
95 |
} |
|
96 |
||
97 |
InetSocketAddress addr = new InetSocketAddress(socket.getLocalPort()); |
|
98 |
if (!socket.getLocalSocketAddress().equals(addr)) { |
|
99 |
System.out.println("Socket.getLocalSocketAddress failed"); |
|
100 |
failCount++; |
|
101 |
} |
|
102 |
||
103 |
if (!socket.isConnected()) { |
|
104 |
System.out.println("Socket.isConnected failed"); |
|
105 |
failCount++; |
|
106 |
} |
|
107 |
||
108 |
if (!socket.isBound()) { |
|
109 |
System.out.println("Socket.isBound failed"); |
|
110 |
failCount++; |
|
111 |
} |
|
112 |
} |
|
113 |
} |