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

Comparing jsr166/src/test/tck/AtomicIntegerArrayTest.java (file contents):
Revision 1.19 by jsr166, Sat Oct 9 19:30:34 2010 UTC vs.
Revision 1.23 by jsr166, Fri Jun 10 19:45:01 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
10 < import java.util.concurrent.atomic.*;
11 < import java.io.*;
12 < import java.util.*;
10 > import java.util.Arrays;
11 > import java.util.concurrent.atomic.AtomicIntegerArray;
12  
13   public class AtomicIntegerArrayTest extends JSR166TestCase {
14  
# Line 20 | Line 19 | public class AtomicIntegerArrayTest exte
19          return new TestSuite(AtomicIntegerArrayTest.class);
20      }
21  
23
22      /**
23       * constructor creates array of given size with all elements zero
24       */
# Line 45 | Line 43 | public class AtomicIntegerArrayTest exte
43       * constructor with array is of same size and has all elements
44       */
45      public void testConstructor2() {
46 <        int[] a = { 17, 3, -42, 99, -7};
46 >        int[] a = { 17, 3, -42, 99, -7 };
47          AtomicIntegerArray ai = new AtomicIntegerArray(a);
48          assertEquals(a.length, ai.length());
49          for (int i = 0; i < a.length; ++i)
# Line 307 | Line 305 | public class AtomicIntegerArrayTest exte
305          assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN);
306      }
307  
310
308      /**
309       * a deserialized serialized array holds same values
310       */
311      public void testSerialization() throws Exception {
312 <        AtomicIntegerArray l = new AtomicIntegerArray(SIZE);
313 <        for (int i = 0; i < SIZE; ++i)
314 <            l.set(i, -i);
315 <
316 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
317 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
318 <        out.writeObject(l);
319 <        out.close();
323 <
324 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
325 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
326 <        AtomicIntegerArray r = (AtomicIntegerArray) in.readObject();
327 <        for (int i = 0; i < SIZE; ++i) {
328 <            assertEquals(l.get(i), r.get(i));
312 >        AtomicIntegerArray x = new AtomicIntegerArray(SIZE);
313 >        for (int i = 0; i < SIZE; i++)
314 >            x.set(i, -i);
315 >        AtomicIntegerArray y = serialClone(x);
316 >        assertTrue(x != y);
317 >        assertEquals(x.length(), y.length());
318 >        for (int i = 0; i < SIZE; i++) {
319 >            assertEquals(x.get(i), y.get(i));
320          }
321      }
322  
332
323      /**
324       * toString returns current value.
325       */
326      public void testToString() {
327 <        int[] a = { 17, 3, -42, 99, -7};
327 >        int[] a = { 17, 3, -42, 99, -7 };
328          AtomicIntegerArray ai = new AtomicIntegerArray(a);
329          assertEquals(Arrays.toString(a), ai.toString());
330      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines