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

Comparing jsr166/src/test/tck/AtomicBooleanTest.java (file contents):
Revision 1.1 by dl, Sun Aug 31 19:24:52 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 AtomicBooleanTest extends TestCase {
12 > public class AtomicBooleanTest extends JSR166TestCase {
13      public static void main (String[] args) {
14          junit.textui.TestRunner.run (suite());
15      }
# Line 16 | Line 17 | public class AtomicBooleanTest extends T
17          return new TestSuite(AtomicBooleanTest.class);
18      }
19  
20 <    public void testConstructor(){
20 >    /**
21 >     *
22 >     */
23 >    public void testConstructor() {
24          AtomicBoolean ai = new AtomicBoolean(true);
25          assertEquals(true,ai.get());
26      }
27  
28 <    public void testConstructor2(){
28 >    /**
29 >     *
30 >     */
31 >    public void testConstructor2() {
32          AtomicBoolean ai = new AtomicBoolean();
33          assertEquals(false,ai.get());
34      }
35  
36 <    public void testGetSet(){
36 >    /**
37 >     *
38 >     */
39 >    public void testGetSet() {
40          AtomicBoolean ai = new AtomicBoolean(true);
41          assertEquals(true,ai.get());
42          ai.set(false);
# Line 35 | Line 45 | public class AtomicBooleanTest extends T
45          assertEquals(true,ai.get());
46          
47      }
48 <    public void testCompareAndSet(){
48 >    /**
49 >     *
50 >     */
51 >    public void testCompareAndSet() {
52          AtomicBoolean ai = new AtomicBoolean(true);
53          assertTrue(ai.compareAndSet(true,false));
54          assertEquals(false,ai.get());
# Line 47 | Line 60 | public class AtomicBooleanTest extends T
60          assertEquals(true,ai.get());
61      }
62  
63 <    public void testWeakCompareAndSet(){
63 >    /**
64 >     *
65 >     */
66 >    public void testWeakCompareAndSet() {
67          AtomicBoolean ai = new AtomicBoolean(true);
68          while(!ai.weakCompareAndSet(true,false));
69          assertEquals(false,ai.get());
# Line 57 | Line 73 | public class AtomicBooleanTest extends T
73          assertEquals(true,ai.get());
74      }
75  
76 <    public void testGetAndSet(){
76 >    /**
77 >     *
78 >     */
79 >    public void testGetAndSet() {
80          AtomicBoolean ai = new AtomicBoolean(true);
81          assertEquals(true,ai.getAndSet(false));
82          assertEquals(false,ai.getAndSet(false));
# Line 65 | Line 84 | public class AtomicBooleanTest extends T
84          assertEquals(true,ai.get());
85      }
86  
87 +    /**
88 +     *
89 +     */
90 +    public void testSerialization() {
91 +        AtomicBoolean l = new AtomicBoolean();
92 +
93 +        try {
94 +            l.set(true);
95 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
96 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
97 +            out.writeObject(l);
98 +            out.close();
99 +
100 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
101 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
102 +            AtomicBoolean r = (AtomicBoolean) in.readObject();
103 +            assertEquals(l.get(), r.get());
104 +        } catch(Exception e){
105 +            e.printStackTrace();
106 +            unexpectedException();
107 +        }
108 +    }
109 +
110  
111   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines