summaryrefslogtreecommitdiff
path: root/jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java
diff options
context:
space:
mode:
authorPrzemyslaw Szczepaniak <pszczepaniak@google.com>2016-03-11 15:59:10 +0000
committerPrzemyslaw Szczepaniak <pszczepaniak@google.com>2016-03-15 11:14:14 +0000
commite8b323c7cb7d55be9a4df579231e44f04f53d766 (patch)
treec40a0cadb5caa371c28b117b017daddef4b72c28 /jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java
parent0eedcb21289c1916e876810982c2c8d473edf24f (diff)
JSR-166 update without java 1.9 method/classes
Second attempt, in frist one I've submitted some code from openJdk 1.9 that shouldn't be here, orignial change can be found at 5328e07d282bef36ac8b757bbee16a761415b2c4 Adapted from sources taken from CVS using: cvs -d ':pserver:anonymous@gee.cs.oswego.edu/home/jsr166/jsr166' checkout -D "03/03/2016 10:00:00 GMT" jsr166 This time with hidden/removed "@since 9" methods and classes Bug: 27426599 Change-Id: Ibd8d26e13cba091bfd983c73d005e4f8d8f5946d (cherry picked from commit b8b75116273ecfdb8ffdd1869b1c0dd04570a95e)
Diffstat (limited to 'jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java')
-rw-r--r--jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java107
1 files changed, 104 insertions, 3 deletions
diff --git a/jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java b/jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java
index 204f814fab..d46280b889 100644
--- a/jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java
+++ b/jsr166-tests/src/test/java/jsr166/AtomicLongFieldUpdaterTest.java
@@ -15,9 +15,10 @@ import junit.framework.TestSuite;
public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
volatile long x = 0;
- int z;
+ protected volatile long protectedField;
+ private volatile long privateField;
long w;
-
+ float z;
// android-note: Removed because the CTS runner does a bad job of
// retrying tests that have suite() declarations.
//
@@ -25,7 +26,59 @@ public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
// main(suite(), args);
// }
// public static Test suite() {
- // return new TestSuite(...);
+ // return new TestSuite(AtomicLongFieldUpdaterTest.class);
+ // }
+
+ // for testing subclass access
+ // android-note: Removed because android doesn't restrict reflection access
+ // static class AtomicLongFieldUpdaterTestSubclass extends AtomicLongFieldUpdaterTest {
+ // public void checkPrivateAccess() {
+ // try {
+ // AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
+ // AtomicLongFieldUpdater.newUpdater
+ // (AtomicLongFieldUpdaterTest.class, "privateField");
+ // shouldThrow();
+ // } catch (RuntimeException success) {
+ // assertNotNull(success.getCause());
+ // }
+ // }
+
+ // public void checkCompareAndSetProtectedSub() {
+ // AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
+ // AtomicLongFieldUpdater.newUpdater
+ // (AtomicLongFieldUpdaterTest.class, "protectedField");
+ // this.protectedField = 1;
+ // assertTrue(a.compareAndSet(this, 1, 2));
+ // assertTrue(a.compareAndSet(this, 2, -4));
+ // assertEquals(-4, a.get(this));
+ // assertFalse(a.compareAndSet(this, -5, 7));
+ // assertEquals(-4, a.get(this));
+ // assertTrue(a.compareAndSet(this, -4, 7));
+ // assertEquals(7, a.get(this));
+ // }
+ // }
+
+ // static class UnrelatedClass {
+ // public void checkPackageAccess(AtomicLongFieldUpdaterTest obj) {
+ // obj.x = 72L;
+ // AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
+ // AtomicLongFieldUpdater.newUpdater
+ // (AtomicLongFieldUpdaterTest.class, "x");
+ // assertEquals(72L, a.get(obj));
+ // assertTrue(a.compareAndSet(obj, 72L, 73L));
+ // assertEquals(73L, a.get(obj));
+ // }
+
+ // public void checkPrivateAccess(AtomicLongFieldUpdaterTest obj) {
+ // try {
+ // AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a =
+ // AtomicLongFieldUpdater.newUpdater
+ // (AtomicLongFieldUpdaterTest.class, "privateField");
+ // throw new AssertionError("should throw");
+ // } catch (RuntimeException success) {
+ // assertNotNull(success.getCause());
+ // }
+ // }
// }
AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> updaterFor(String fieldName) {
@@ -66,6 +119,26 @@ public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
}
/**
+ * construction using private field from subclass throws RuntimeException
+ */
+ // android-note: Removed because android doesn't restrict reflection access
+ // public void testPrivateFieldInSubclass() {
+ // AtomicLongFieldUpdaterTestSubclass s =
+ // new AtomicLongFieldUpdaterTestSubclass();
+ // s.checkPrivateAccess();
+ // }
+
+ /**
+ * construction from unrelated class; package access is allowed,
+ * private access is not
+ */
+ // android-note: Removed because android doesn't restrict reflection access
+ // public void testUnrelatedClassAccess() {
+ // new UnrelatedClass().checkPackageAccess(this);
+ // new UnrelatedClass().checkPrivateAccess(this);
+ // }
+
+ /**
* get returns the last value set or assigned
*/
public void testGetSet() {
@@ -110,6 +183,34 @@ public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
}
/**
+ * compareAndSet succeeds in changing protected field value if
+ * equal to expected else fails
+ */
+ public void testCompareAndSetProtected() {
+ AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
+ a = updaterFor("protectedField");
+ protectedField = 1;
+ assertTrue(a.compareAndSet(this, 1, 2));
+ assertTrue(a.compareAndSet(this, 2, -4));
+ assertEquals(-4, a.get(this));
+ assertFalse(a.compareAndSet(this, -5, 7));
+ assertEquals(-4, a.get(this));
+ assertTrue(a.compareAndSet(this, -4, 7));
+ assertEquals(7, a.get(this));
+ }
+
+ /**
+ * compareAndSet succeeds in changing protected field value if
+ * equal to expected else fails
+ */
+ // android-note: Removed because android doesn't restrict reflection access
+ // public void testCompareAndSetProtectedInSubclass() {
+ // AtomicLongFieldUpdaterTestSubclass s =
+ // new AtomicLongFieldUpdaterTestSubclass();
+ // s.checkCompareAndSetProtectedSub();
+ // }
+
+ /**
* compareAndSet in one thread enables another waiting for value
* to succeed
*/