1 // Tags: JDK1.0 |
|
2 |
|
3 // Copyright (C) 2002 Free Software Foundation, Inc. |
|
4 // Written by Mark Wielaard (mark@klomp.org) |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. */ |
|
22 |
|
23 package gnu.testlet.java.lang.Thread; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 |
|
28 public class interrupt implements Testlet |
|
29 { |
|
30 |
|
31 public void test (TestHarness harness) |
|
32 { |
|
33 Thread current = Thread.currentThread(); |
|
34 |
|
35 // Make sure interrupt flag is cleared |
|
36 Thread.interrupted(); |
|
37 |
|
38 harness.check(!current.isInterrupted(), |
|
39 "Thread.interrupted() makes isInterrupted() false"); |
|
40 harness.check(!Thread.interrupted(), |
|
41 "Thread.interrupted() makes interrupted() false"); |
|
42 |
|
43 // Make sure interrupt flag is set |
|
44 current.interrupt(); |
|
45 |
|
46 harness.check(current.isInterrupted(), |
|
47 "interrupt() makes isInterrupted() true"); |
|
48 harness.check(current.isInterrupted(), |
|
49 "isInterrupt() doesn't clear interrupt flag"); |
|
50 harness.check(Thread.interrupted(), |
|
51 "interrupt() makes interrupted() true"); |
|
52 |
|
53 // Set interrupt flag again for wait test |
|
54 current.interrupt(); |
|
55 boolean interrupted_exception = false; |
|
56 try |
|
57 { |
|
58 Object o = new Object(); |
|
59 synchronized(o) {o.wait(50);} |
|
60 } |
|
61 catch(InterruptedException ie) |
|
62 { |
|
63 interrupted_exception = true; |
|
64 } |
|
65 harness.check(interrupted_exception, |
|
66 "wait with interrupt flag throws InterruptedException"); |
|
67 |
|
68 harness.check(interrupted_exception && !Thread.interrupted(), |
|
69 "InterruptedException in wait() clears interrupt flag"); |
|
70 |
|
71 // Set interrupt flag again for sleep test |
|
72 current.interrupt(); |
|
73 interrupted_exception = false; |
|
74 try |
|
75 { |
|
76 Thread.sleep(50); |
|
77 } |
|
78 catch(InterruptedException ie) |
|
79 { |
|
80 interrupted_exception = true; |
|
81 } |
|
82 harness.check(interrupted_exception, |
|
83 "sleep with interrupt flag throws InterruptedException"); |
|
84 |
|
85 harness.check(interrupted_exception && !Thread.interrupted(), |
|
86 "InterruptedException in sleep() clears interrupt flag"); |
|
87 |
|
88 // Set interrupt flag again for join test |
|
89 current.interrupt(); |
|
90 interrupted_exception = false; |
|
91 try |
|
92 { |
|
93 current.join(50, 50); |
|
94 } |
|
95 catch(InterruptedException ie) |
|
96 { |
|
97 interrupted_exception = true; |
|
98 } |
|
99 harness.check(interrupted_exception, |
|
100 "join with interrupt flag throws InterruptedException"); |
|
101 |
|
102 harness.check(interrupted_exception && !Thread.interrupted(), |
|
103 "InterruptedException in join() clears interrupt flag"); |
|
104 } |
|
105 } |
|
106 |
|