--- jsr166/src/test/tck/AtomicLongTest.java 2003/08/31 19:24:53 1.1 +++ jsr166/src/test/tck/AtomicLongTest.java 2003/09/20 18:20:07 1.4 @@ -7,8 +7,9 @@ import junit.framework.*; import java.util.concurrent.atomic.*; +import java.io.*; -public class AtomicLongTest extends TestCase { +public class AtomicLongTest extends JSR166TestCase { public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } @@ -16,16 +17,25 @@ public class AtomicLongTest extends Test return new TestSuite(AtomicLongTest.class); } + /** + * + */ public void testConstructor(){ AtomicLong ai = new AtomicLong(1); assertEquals(1,ai.get()); } + /** + * + */ public void testConstructor2(){ AtomicLong ai = new AtomicLong(); assertEquals(0,ai.get()); } + /** + * + */ public void testGetSet(){ AtomicLong ai = new AtomicLong(1); assertEquals(1,ai.get()); @@ -35,6 +45,9 @@ public class AtomicLongTest extends Test assertEquals(-3,ai.get()); } + /** + * + */ public void testCompareAndSet(){ AtomicLong ai = new AtomicLong(1); assertTrue(ai.compareAndSet(1,2)); @@ -46,6 +59,9 @@ public class AtomicLongTest extends Test assertEquals(7,ai.get()); } + /** + * + */ public void testWeakCompareAndSet(){ AtomicLong ai = new AtomicLong(1); while(!ai.weakCompareAndSet(1,2)); @@ -55,6 +71,9 @@ public class AtomicLongTest extends Test assertEquals(7,ai.get()); } + /** + * + */ public void testGetAndSet(){ AtomicLong ai = new AtomicLong(1); assertEquals(1,ai.getAndSet(0)); @@ -62,6 +81,9 @@ public class AtomicLongTest extends Test assertEquals(-10,ai.getAndSet(1)); } + /** + * + */ public void testGetAndAdd(){ AtomicLong ai = new AtomicLong(1); assertEquals(1,ai.getAndAdd(2)); @@ -70,6 +92,9 @@ public class AtomicLongTest extends Test assertEquals(-1,ai.get()); } + /** + * + */ public void testGetAndDecrement(){ AtomicLong ai = new AtomicLong(1); assertEquals(1,ai.getAndDecrement()); @@ -77,6 +102,9 @@ public class AtomicLongTest extends Test assertEquals(-1,ai.getAndDecrement()); } + /** + * + */ public void testGetAndIncrement(){ AtomicLong ai = new AtomicLong(1); assertEquals(1,ai.getAndIncrement()); @@ -88,6 +116,9 @@ public class AtomicLongTest extends Test assertEquals(1,ai.get()); } + /** + * + */ public void testAddAndGet(){ AtomicLong ai = new AtomicLong(1); assertEquals(3,ai.addAndGet(2)); @@ -96,6 +127,9 @@ public class AtomicLongTest extends Test assertEquals(-1,ai.get()); } + /** + * + */ public void testDecrementAndGet(){ AtomicLong ai = new AtomicLong(1); assertEquals(0,ai.decrementAndGet()); @@ -104,6 +138,9 @@ public class AtomicLongTest extends Test assertEquals(-2,ai.get()); } + /** + * + */ public void testIncrementAndGet(){ AtomicLong ai = new AtomicLong(1); assertEquals(2,ai.incrementAndGet()); @@ -115,5 +152,26 @@ public class AtomicLongTest extends Test assertEquals(1,ai.get()); } + /** + * + */ + public void testSerialization() { + AtomicLong l = new AtomicLong(); + + try { + l.set(-22); + ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); + ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); + out.writeObject(l); + out.close(); + + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); + AtomicLong r = (AtomicLong) in.readObject(); + assertEquals(l.get(), r.get()); + } catch(Exception e){ + unexpectedException(); + } + } }