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

Comparing jsr166/src/test/tck/AtomicReferenceArrayTest.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 AtomicReferenceArrayTest extends TestCase
12 > public class AtomicReferenceArrayTest extends JSR166TestCase
13   {
13    static final int N = 10;
14
15    static final Integer zero = new Integer(0);
16    static final Integer one = new Integer(1);
17    static final Integer two = new Integer(2);
18    static final Integer m3  = new Integer(-3);
19    static final Integer m4 = new Integer(-4);
20    static final Integer m5 = new Integer(-5);
21    static final Integer seven = new Integer(7);
22    static final Integer m10 = new Integer(-10);
23
14      public static void main (String[] args) {
15          junit.textui.TestRunner.run (suite());
16      }
# Line 28 | Line 18 | public class AtomicReferenceArrayTest ex
18          return new TestSuite(AtomicReferenceArrayTest.class);
19      }
20  
21 +    /**
22 +     *
23 +     */
24      public void testConstructor(){
25 <        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(N);
26 <        for (int i = 0; i < N; ++i) {
25 >        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(SIZE);
26 >        for (int i = 0; i < SIZE; ++i) {
27              assertNull(ai.get(i));
28          }
29      }
30  
31 +    /**
32 +     *
33 +     */
34      public void testGetSet(){
35 <        AtomicReferenceArray ai = new AtomicReferenceArray(N);
36 <        for (int i = 0; i < N; ++i) {
35 >        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
36 >        for (int i = 0; i < SIZE; ++i) {
37              ai.set(i, one);
38              assertEquals(one,ai.get(i));
39              ai.set(i, two);
# Line 47 | Line 43 | public class AtomicReferenceArrayTest ex
43          }
44      }
45  
46 +    /**
47 +     *
48 +     */
49      public void testCompareAndSet(){
50 <        AtomicReferenceArray ai = new AtomicReferenceArray(N);
51 <        for (int i = 0; i < N; ++i) {
50 >        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
51 >        for (int i = 0; i < SIZE; ++i) {
52              ai.set(i, one);
53              assertTrue(ai.compareAndSet(i, one,two));
54              assertTrue(ai.compareAndSet(i, two,m4));
# Line 61 | Line 60 | public class AtomicReferenceArrayTest ex
60          }
61      }
62  
63 +    /**
64 +     *
65 +     */
66      public void testWeakCompareAndSet(){
67 <        AtomicReferenceArray ai = new AtomicReferenceArray(N);
68 <        for (int i = 0; i < N; ++i) {
67 >        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
68 >        for (int i = 0; i < SIZE; ++i) {
69              ai.set(i, one);
70              while(!ai.weakCompareAndSet(i, one,two));
71              while(!ai.weakCompareAndSet(i, two,m4));
# Line 73 | Line 75 | public class AtomicReferenceArrayTest ex
75          }
76      }
77  
78 +    /**
79 +     *
80 +     */
81      public void testGetAndSet(){
82 <        AtomicReferenceArray ai = new AtomicReferenceArray(N);
83 <        for (int i = 0; i < N; ++i) {
82 >        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
83 >        for (int i = 0; i < SIZE; ++i) {
84              ai.set(i, one);
85              assertEquals(one,ai.getAndSet(i,zero));
86              assertEquals(0,ai.getAndSet(i,m10));
# Line 83 | Line 88 | public class AtomicReferenceArrayTest ex
88          }
89      }
90  
91 +    /**
92 +     *
93 +     */
94 +    public void testSerialization() {
95 +        AtomicReferenceArray l = new AtomicReferenceArray(SIZE);
96 +        for (int i = 0; i < SIZE; ++i) {
97 +            l.set(i, new Integer(-i));
98 +        }
99 +
100 +        try {
101 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
102 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
103 +            out.writeObject(l);
104 +            out.close();
105 +
106 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
107 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
108 +            AtomicReferenceArray r = (AtomicReferenceArray) in.readObject();
109 +            assertEquals(l.length(), r.length());
110 +            for (int i = 0; i < SIZE; ++i) {
111 +                assertEquals(r.get(i), l.get(i));
112 +            }
113 +        } catch(Exception e){
114 +            unexpectedException();
115 +        }
116 +    }
117  
118   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines