1 /* AcceptGetLocalPort.java - Test for getLocalPort on accepted Socket. |
|
2 Copyright (C) 2005, Mark J. Wielaard <mark@klomp.org> |
|
3 |
|
4 This file is part of Mauve. |
|
5 |
|
6 Mauve is free software; you can redistribute it and/or modify |
|
7 it under the terms of the GNU General Public License as published by |
|
8 the Free Software Foundation; either version 2, or (at your option) |
|
9 any later version. |
|
10 |
|
11 Mauve is distributed in the hope that it will be useful, but |
|
12 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 General Public License for more details. |
|
15 |
|
16 You should have received a copy of the GNU General Public License |
|
17 along with Mauve; see the file COPYING. If not, write to the |
|
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 02110-1301 USA. */ |
|
20 |
|
21 // Tags: JDK1.0 |
|
22 |
|
23 package gnu.testlet.java.net.ServerSocket; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 |
|
28 import java.net.*; |
|
29 import java.io.*; |
|
30 |
|
31 public class AcceptGetLocalPort implements Testlet, Runnable |
|
32 { |
|
33 private static int port = 5678; |
|
34 |
|
35 public void test (TestHarness harness) |
|
36 { |
|
37 new Thread(this).start(); |
|
38 try |
|
39 { |
|
40 ServerSocket ss = new ServerSocket(port); |
|
41 harness.check(ss.getLocalPort(), port); |
|
42 Socket s = ss.accept(); |
|
43 harness.check(s.getLocalPort(), port); |
|
44 s.close(); |
|
45 ss.close(); |
|
46 } |
|
47 catch (IOException ioe) |
|
48 { |
|
49 harness.debug(ioe); |
|
50 harness.check(false, ioe.toString()); |
|
51 } |
|
52 } |
|
53 |
|
54 public void run() |
|
55 { |
|
56 int i = 0; |
|
57 while (i < 10) |
|
58 { |
|
59 try |
|
60 { |
|
61 Socket s = new Socket("localhost", port); |
|
62 break; |
|
63 } |
|
64 catch (IOException ioe) |
|
65 { |
|
66 // ignore |
|
67 } |
|
68 try |
|
69 { |
|
70 Thread.sleep(1000); |
|
71 } |
|
72 catch (InterruptedException ie) |
|
73 { |
|
74 // ignore |
|
75 } |
|
76 } |
|
77 } |
|
78 } |
|