ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.4 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.5 by dl, Fri Sep 26 15:33:13 2003 UTC

# Line 12 | Line 12 | import java.io.*;
12  
13  
14   /**
15 < * Base class for JSR166 Junit TCK tests.  Defines some constants and
16 < * utility methods, as well as a simple framework for helping to make
17 < * sure that assertions failing in generated threads cause the
18 < * associated test that generated them to itself fail (which JUnit doe
19 < * not otherwise arrange).  The rules for creating such tests are:
15 > * Base class for JSR166 Junit TCK tests.  Defines some constants,
16 > * utility methods and classes, as well as a simple framework for
17 > * helping to make sure that assertions failing in generated threads
18 > * cause the associated test that generated them to itself fail (which
19 > * JUnit doe not otherwise arrange).  The rules for creating such
20 > * tests are:
21   *
22   * <ol>
23   *
# Line 36 | Line 37 | import java.io.*;
37   * <li>All delays and timeouts must use one of the constants {@link
38   * SHORT_DELAY_MS}, {@link SMALL_DELAY_MS}, {@link MEDIUM_DELAY_MS},
39   * {@link LONG_DELAY_MS}. The idea here is that a SHORT is always
40 < * discriminatable from zero time, and always allows enough time for
41 < * the small amounts of computation (creating a thread, calling a few
40 > * discriminable from zero time, and always allows enough time for the
41 > * small amounts of computation (creating a thread, calling a few
42   * methods, etc) needed to reach a timeout point. Similarly, a SMALL
43   * is always discriminable as larger than SHORT and smaller than
44   * MEDIUM.  And so on. These constants are set to conservative values,
# Line 69 | Line 70 | public class JSR166TestCase extends Test
70  
71  
72      /**
73 <     * Set delays as multiples fo SHORT_DELAY.
73 >     * Set delays as multiples of SHORT_DELAY.
74       */
75      protected  void setDelays() {
76          SHORT_DELAY_MS = getShortDelay();
# Line 81 | Line 82 | public class JSR166TestCase extends Test
82      /**
83       * Flag set true if any threadAssert methods fail
84       */
85 <    protected volatile boolean threadFailed;
85 >    volatile boolean threadFailed;
86  
87      /**
88       * Initialize test to indicate that no thread assertions have failed
# Line 98 | Line 99 | public class JSR166TestCase extends Test
99          assertFalse(threadFailed);  
100      }
101  
102 +    /**
103 +     * Fail, also setting status to indicate current testcase should fail
104 +     */
105      public void threadFail(String reason) {
106          threadFailed = true;
107          fail(reason);
108      }
109  
110 +    /**
111 +     * If expression not true, set status to indicate current testcase
112 +     * should fail
113 +     */
114      public void threadAssertTrue(boolean b) {
115          if (!b) {
116              threadFailed = true;
117              assertTrue(b);
118          }
119      }
120 +
121 +    /**
122 +     * If expression not false, set status to indicate current testcase
123 +     * should fail
124 +     */
125      public void threadAssertFalse(boolean b) {
126          if (b) {
127              threadFailed = true;
128              assertFalse(b);
129          }
130      }
131 +
132 +    /**
133 +     * If argument not null, set status to indicate current testcase
134 +     * should fail
135 +     */
136      public void threadAssertNull(Object x) {
137          if (x != null) {
138              threadFailed = true;
139              assertNull(x);
140          }
141      }
142 +
143 +    /**
144 +     * If arguments not equal, set status to indicate current testcase
145 +     * should fail
146 +     */
147      public void threadAssertEquals(long x, long y) {
148          if (x != y) {
149              threadFailed = true;
150              assertEquals(x, y);
151          }
152      }
153 +
154 +    /**
155 +     * If arguments not equal, set status to indicate current testcase
156 +     * should fail
157 +     */
158      public void threadAssertEquals(Object x, Object y) {
159          if (x != y && (x == null || !x.equals(y))) {
160              threadFailed = true;
# Line 134 | Line 162 | public class JSR166TestCase extends Test
162          }
163      }
164  
165 +    /**
166 +     * threadFail with message "should throw exception"
167 +     */
168      public void threadShouldThrow() {
169          threadFailed = true;
170          fail("should throw exception");
171      }
172  
173 +    /**
174 +     * threadFail with message "Unexpected exception"
175 +     */
176      public void threadUnexpectedException() {
177          threadFailed = true;
178          fail("Unexpected exception");
# Line 157 | Line 191 | public class JSR166TestCase extends Test
191          }
192      }
193  
194 <    
194 >
195 >    /**
196 >     * fail with message "should throw exception"
197 >     */
198      public void shouldThrow() {
199          fail("Should throw exception");
200      }
201  
202 +    /**
203 +     * fail with message "Unexpected exception"
204 +     */
205      public void unexpectedException() {
206          fail("Unexpected exception");
207      }
# Line 170 | Line 210 | public class JSR166TestCase extends Test
210      /**
211       * The number of elements to place in collections, arrays, etc.
212       */
213 <    public static final int SIZE = 20;
213 >    static final int SIZE = 20;
214  
215      // Some convenient Integer constants
216  
217 <    public static final Integer zero = new Integer(0);
218 <    public static final Integer one = new Integer(1);
219 <    public static final Integer two = new Integer(2);
220 <    public static final Integer three  = new Integer(3);
221 <    public static final Integer four  = new Integer(4);
222 <    public static final Integer five  = new Integer(5);
223 <    public static final Integer six = new Integer(6);
224 <    public static final Integer seven = new Integer(7);
225 <    public static final Integer eight = new Integer(8);
226 <    public static final Integer nine = new Integer(9);
227 <    public static final Integer m1  = new Integer(-1);
228 <    public static final Integer m2  = new Integer(-2);
229 <    public static final Integer m3  = new Integer(-3);
230 <    public static final Integer m4 = new Integer(-4);
231 <    public static final Integer m5 = new Integer(-5);
232 <    public static final Integer m10 = new Integer(-10);
217 >    static final Integer zero = new Integer(0);
218 >    static final Integer one = new Integer(1);
219 >    static final Integer two = new Integer(2);
220 >    static final Integer three  = new Integer(3);
221 >    static final Integer four  = new Integer(4);
222 >    static final Integer five  = new Integer(5);
223 >    static final Integer six = new Integer(6);
224 >    static final Integer seven = new Integer(7);
225 >    static final Integer eight = new Integer(8);
226 >    static final Integer nine = new Integer(9);
227 >    static final Integer m1  = new Integer(-1);
228 >    static final Integer m2  = new Integer(-2);
229 >    static final Integer m3  = new Integer(-3);
230 >    static final Integer m4 = new Integer(-4);
231 >    static final Integer m5 = new Integer(-5);
232 >    static final Integer m10 = new Integer(-10);
233  
234  
235      // Some convenient Runnable classes
236  
237 <    public static class NoOpRunnable implements Runnable {
237 >    static class NoOpRunnable implements Runnable {
238          public void run() {}
239      }
240  
241 <    public static class NoOpCallable implements Callable {
241 >    static class NoOpCallable implements Callable {
242          public Object call() { return Boolean.TRUE; }
243      }
244  
245 <    public class ShortRunnable implements Runnable {
245 >    class ShortRunnable implements Runnable {
246          public void run() {
247              try {
248                  Thread.sleep(SHORT_DELAY_MS);
# Line 213 | Line 253 | public class JSR166TestCase extends Test
253          }
254      }
255  
256 <    public class ShortInterruptedRunnable implements Runnable {
256 >    class ShortInterruptedRunnable implements Runnable {
257          public void run() {
258              try {
259                  Thread.sleep(SHORT_DELAY_MS);
# Line 224 | Line 264 | public class JSR166TestCase extends Test
264          }
265      }
266  
267 <    public class SmallRunnable implements Runnable {
267 >    class SmallRunnable implements Runnable {
268          public void run() {
269              try {
270                  Thread.sleep(SMALL_DELAY_MS);
# Line 235 | Line 275 | public class JSR166TestCase extends Test
275          }
276      }
277  
278 <    public class SmallCallable implements Callable {
278 >    class SmallCallable implements Callable {
279          public Object call() {
280              try {
281                  Thread.sleep(SMALL_DELAY_MS);
# Line 247 | Line 287 | public class JSR166TestCase extends Test
287          }
288      }
289  
290 <    public class SmallInterruptedRunnable implements Runnable {
290 >    class SmallInterruptedRunnable implements Runnable {
291          public void run() {
292              try {
293                  Thread.sleep(SMALL_DELAY_MS);
# Line 259 | Line 299 | public class JSR166TestCase extends Test
299      }
300  
301  
302 <    public class MediumRunnable implements Runnable {
302 >    class MediumRunnable implements Runnable {
303          public void run() {
304              try {
305                  Thread.sleep(MEDIUM_DELAY_MS);
# Line 270 | Line 310 | public class JSR166TestCase extends Test
310          }
311      }
312  
313 <    public class MediumInterruptedRunnable implements Runnable {
313 >    class MediumInterruptedRunnable implements Runnable {
314          public void run() {
315              try {
316                  Thread.sleep(MEDIUM_DELAY_MS);
# Line 281 | Line 321 | public class JSR166TestCase extends Test
321          }
322      }
323  
324 <    public class MediumPossiblyInterruptedRunnable implements Runnable {
324 >    class MediumPossiblyInterruptedRunnable implements Runnable {
325          public void run() {
326              try {
327                  Thread.sleep(MEDIUM_DELAY_MS);
# Line 290 | Line 330 | public class JSR166TestCase extends Test
330              }
331          }
332      }
333 +
334 +    /**
335 +     * For use as ThreadFactory in constructors
336 +     */
337 +    static class SimpleThreadFactory implements ThreadFactory{
338 +        public Thread newThread(Runnable r){
339 +            return new Thread(r);
340 +        }  
341 +    }
342 +
343 +    static class TrackedRunnable implements Runnable {
344 +        volatile boolean done = false;
345 +        public void run() {
346 +            try {
347 +                Thread.sleep(SMALL_DELAY_MS);
348 +                done = true;
349 +            } catch(Exception e){
350 +            }
351 +        }
352 +    }
353 +
354 +    static class TrackedCallable implements Callable {
355 +        volatile boolean done = false;
356 +        public Object call() {
357 +            try {
358 +                Thread.sleep(SMALL_DELAY_MS);
359 +                done = true;
360 +            } catch(Exception e){
361 +            }
362 +            return Boolean.TRUE;
363 +        }
364 +    }
365 +
366 +    /**
367 +     * For use as RejectedExecutionHandler in constructors
368 +     */
369 +    static class NoOpREHandler implements RejectedExecutionHandler{
370 +        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){}
371 +    }
372 +
373      
374   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines