ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicReferenceTest.java
Revision: 1.1
Committed: Sun Aug 31 19:24:53 2003 UTC (20 years, 8 months ago) by dl
Branch: MAIN
Log Message:
First check-in of tests to be in tck

File Contents

# Content
1 /*
2 * Written by members of JCP JSR-166 Expert Group and released to the
3 * public domain. Use, modify, and redistribute this code in any way
4 * without acknowledgement. Other contributors include Andrew Wright,
5 * Jeffrey Hayes, Pat Fischer, Mike Judd.
6 */
7
8 import junit.framework.*;
9 import java.util.concurrent.atomic.*;
10
11 public class AtomicReferenceTest extends TestCase {
12 public static void main (String[] args) {
13 junit.textui.TestRunner.run (suite());
14 }
15 public static Test suite() {
16 return new TestSuite(AtomicReferenceTest.class);
17 }
18
19 static final Integer zero = new Integer(0);
20 static final Integer one = new Integer(1);
21 static final Integer two = new Integer(2);
22 static final Integer m3 = new Integer(-3);
23 static final Integer m4 = new Integer(-4);
24 static final Integer m5 = new Integer(-5);
25 static final Integer seven = new Integer(7);
26 static final Integer m10 = new Integer(-10);
27
28 public void testConstructor(){
29 AtomicReference ai = new AtomicReference(one);
30 assertEquals(one,ai.get());
31 }
32
33 public void testConstructor2(){
34 AtomicReference ai = new AtomicReference();
35 assertNull(ai.get());
36 }
37
38 public void testGetSet(){
39 AtomicReference ai = new AtomicReference(one);
40 assertEquals(one,ai.get());
41 ai.set(two);
42 assertEquals(two,ai.get());
43 ai.set(m3);
44 assertEquals(m3,ai.get());
45
46 }
47 public void testCompareAndSet(){
48 AtomicReference ai = new AtomicReference(one);
49 assertTrue(ai.compareAndSet(one,two));
50 assertTrue(ai.compareAndSet(two,m4));
51 assertEquals(m4,ai.get());
52 assertFalse(ai.compareAndSet(m5,seven));
53 assertFalse((seven.equals(ai.get())));
54 assertTrue(ai.compareAndSet(m4,seven));
55 assertEquals(seven,ai.get());
56 }
57
58 public void testWeakCompareAndSet(){
59 AtomicReference ai = new AtomicReference(one);
60 while(!ai.weakCompareAndSet(one,two));
61 while(!ai.weakCompareAndSet(two,m4));
62 assertEquals(m4,ai.get());
63 while(!ai.weakCompareAndSet(m4,seven));
64 assertEquals(seven,ai.get());
65 }
66
67 public void testGetAndSet(){
68 AtomicReference ai = new AtomicReference(one);
69 assertEquals(one,ai.getAndSet(zero));
70 assertEquals(zero,ai.getAndSet(m10));
71 assertEquals(m10,ai.getAndSet(one));
72 }
73
74 }
75