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

Comparing jsr166/src/test/tck/AtomicLongTest.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 AtomicLongTest extends TestCase {
12 > public class AtomicLongTest extends JSR166TestCase {
13      public static void main (String[] args) {
14          junit.textui.TestRunner.run (suite());
15      }
# Line 16 | Line 17 | public class AtomicLongTest extends Test
17          return new TestSuite(AtomicLongTest.class);
18      }
19  
20 +    /**
21 +     *
22 +     */
23      public void testConstructor(){
24          AtomicLong ai = new AtomicLong(1);
25          assertEquals(1,ai.get());
26      }
27  
28 +    /**
29 +     *
30 +     */
31      public void testConstructor2(){
32          AtomicLong ai = new AtomicLong();
33          assertEquals(0,ai.get());
34      }
35  
36 +    /**
37 +     *
38 +     */
39      public void testGetSet(){
40          AtomicLong ai = new AtomicLong(1);
41          assertEquals(1,ai.get());
# Line 35 | Line 45 | public class AtomicLongTest extends Test
45          assertEquals(-3,ai.get());
46          
47      }
48 +    /**
49 +     *
50 +     */
51      public void testCompareAndSet(){
52          AtomicLong ai = new AtomicLong(1);
53          assertTrue(ai.compareAndSet(1,2));
# Line 46 | Line 59 | public class AtomicLongTest extends Test
59          assertEquals(7,ai.get());
60      }
61  
62 +    /**
63 +     *
64 +     */
65      public void testWeakCompareAndSet(){
66          AtomicLong ai = new AtomicLong(1);
67          while(!ai.weakCompareAndSet(1,2));
# Line 55 | Line 71 | public class AtomicLongTest extends Test
71          assertEquals(7,ai.get());
72      }
73  
74 +    /**
75 +     *
76 +     */
77      public void testGetAndSet(){
78          AtomicLong ai = new AtomicLong(1);
79          assertEquals(1,ai.getAndSet(0));
# Line 62 | Line 81 | public class AtomicLongTest extends Test
81          assertEquals(-10,ai.getAndSet(1));
82      }
83  
84 +    /**
85 +     *
86 +     */
87      public void testGetAndAdd(){
88          AtomicLong ai = new AtomicLong(1);
89          assertEquals(1,ai.getAndAdd(2));
# Line 70 | Line 92 | public class AtomicLongTest extends Test
92          assertEquals(-1,ai.get());
93      }
94  
95 +    /**
96 +     *
97 +     */
98      public void testGetAndDecrement(){
99          AtomicLong ai = new AtomicLong(1);
100          assertEquals(1,ai.getAndDecrement());
# Line 77 | Line 102 | public class AtomicLongTest extends Test
102          assertEquals(-1,ai.getAndDecrement());
103      }
104  
105 +    /**
106 +     *
107 +     */
108      public void testGetAndIncrement(){
109          AtomicLong ai = new AtomicLong(1);
110          assertEquals(1,ai.getAndIncrement());
# Line 88 | Line 116 | public class AtomicLongTest extends Test
116          assertEquals(1,ai.get());
117      }
118  
119 +    /**
120 +     *
121 +     */
122      public void testAddAndGet(){
123          AtomicLong ai = new AtomicLong(1);
124          assertEquals(3,ai.addAndGet(2));
# Line 96 | Line 127 | public class AtomicLongTest extends Test
127          assertEquals(-1,ai.get());
128      }
129  
130 +    /**
131 +     *
132 +     */
133      public void testDecrementAndGet(){
134          AtomicLong ai = new AtomicLong(1);
135          assertEquals(0,ai.decrementAndGet());
# Line 104 | Line 138 | public class AtomicLongTest extends Test
138          assertEquals(-2,ai.get());
139      }
140  
141 +    /**
142 +     *
143 +     */
144      public void testIncrementAndGet(){
145          AtomicLong ai = new AtomicLong(1);
146          assertEquals(2,ai.incrementAndGet());
# Line 115 | Line 152 | public class AtomicLongTest extends Test
152          assertEquals(1,ai.get());
153      }
154  
155 +    /**
156 +     *
157 +     */
158 +    public void testSerialization() {
159 +        AtomicLong l = new AtomicLong();
160 +
161 +        try {
162 +            l.set(-22);
163 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
164 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
165 +            out.writeObject(l);
166 +            out.close();
167 +
168 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
169 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
170 +            AtomicLong r = (AtomicLong) in.readObject();
171 +            assertEquals(l.get(), r.get());
172 +        } catch(Exception e){
173 +            unexpectedException();
174 +        }
175 +    }
176  
177   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines