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

Comparing jsr166/src/test/tck/AtomicReferenceTest.java (file contents):
Revision 1.1 by dl, Sun Aug 31 19:24:53 2003 UTC vs.
Revision 1.4 by dl, Sat Sep 20 18:20:07 2003 UTC

# Line 7 | Line 7
7  
8   import junit.framework.*;
9   import java.util.concurrent.atomic.*;
10 + import java.io.*;
11  
12 < public class AtomicReferenceTest extends TestCase {
12 > public class AtomicReferenceTest extends JSR166TestCase {
13      public static void main (String[] args) {
14          junit.textui.TestRunner.run (suite());
15      }
# Line 16 | Line 17 | public class AtomicReferenceTest extends
17          return new TestSuite(AtomicReferenceTest.class);
18      }
19  
20 <    static final Integer zero = new Integer(0);
21 <    static final Integer one = new Integer(1);
22 <    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 <
20 >    /**
21 >     *
22 >     */
23      public void testConstructor(){
24          AtomicReference ai = new AtomicReference(one);
25          assertEquals(one,ai.get());
26      }
27  
28 +    /**
29 +     *
30 +     */
31      public void testConstructor2(){
32          AtomicReference ai = new AtomicReference();
33          assertNull(ai.get());
34      }
35  
36 +    /**
37 +     *
38 +     */
39      public void testGetSet(){
40          AtomicReference ai = new AtomicReference(one);
41          assertEquals(one,ai.get());
# Line 44 | Line 45 | public class AtomicReferenceTest extends
45          assertEquals(m3,ai.get());
46          
47      }
48 +    /**
49 +     *
50 +     */
51      public void testCompareAndSet(){
52          AtomicReference ai = new AtomicReference(one);
53          assertTrue(ai.compareAndSet(one,two));
# Line 55 | Line 59 | public class AtomicReferenceTest extends
59          assertEquals(seven,ai.get());
60      }
61  
62 +    /**
63 +     *
64 +     */
65      public void testWeakCompareAndSet(){
66          AtomicReference ai = new AtomicReference(one);
67          while(!ai.weakCompareAndSet(one,two));
# Line 64 | Line 71 | public class AtomicReferenceTest extends
71          assertEquals(seven,ai.get());
72      }
73  
74 +    /**
75 +     *
76 +     */
77      public void testGetAndSet(){
78          AtomicReference ai = new AtomicReference(one);
79          assertEquals(one,ai.getAndSet(zero));
# Line 71 | Line 81 | public class AtomicReferenceTest extends
81          assertEquals(m10,ai.getAndSet(one));
82      }
83  
84 +    /**
85 +     *
86 +     */
87 +    public void testSerialization() {
88 +        AtomicReference l = new AtomicReference();
89 +
90 +        try {
91 +            l.set(one);
92 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
93 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
94 +            out.writeObject(l);
95 +            out.close();
96 +
97 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
98 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
99 +            AtomicReference r = (AtomicReference) in.readObject();
100 +            assertEquals(l.get(), r.get());
101 +        } catch(Exception e){
102 +            unexpectedException();
103 +        }
104 +    }
105 +
106   }
107  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines