Merge "Move cts tests using reflection" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fd533c751b
@@ -26,11 +26,29 @@ import android.support.test.runner.AndroidJUnit4;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccessibilityEvent is public, so CTS covers it pretty well. Verifying hidden methods here.
|
* AccessibilityEvent is public, so CTS covers it pretty well. Verifying hidden methods here.
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class AccessibilityEventTest {
|
public class AccessibilityEventTest {
|
||||||
|
// The number of fields tested in the corresponding CTS AccessibilityEventTest:
|
||||||
|
// See the CTS tests for AccessibilityRecord:
|
||||||
|
// fullyPopulateAccessibilityEvent, assertEqualsAccessiblityEvent,
|
||||||
|
// and assertAccessibilityEventCleared
|
||||||
|
|
||||||
|
/** The number of properties of the {@link AccessibilityEvent} class. */
|
||||||
|
private static final int A11Y_EVENT_NON_STATIC_FIELD_COUNT = 32;
|
||||||
|
|
||||||
|
// The number of fields tested in the corresponding CTS AccessibilityRecordTest:
|
||||||
|
// assertAccessibilityRecordCleared, fullyPopulateAccessibilityRecord,
|
||||||
|
// and assertEqualAccessibilityRecord
|
||||||
|
|
||||||
|
/** The number of properties of the {@link AccessibilityRecord} class. */
|
||||||
|
private static final int A11Y_RECORD_NON_STATIC_FIELD_COUNT = 24;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testImportantForAccessibiity_getSetWorkAcrossParceling() {
|
public void testImportantForAccessibiity_getSetWorkAcrossParceling() {
|
||||||
AccessibilityEvent event = AccessibilityEvent.obtain();
|
AccessibilityEvent event = AccessibilityEvent.obtain();
|
||||||
@@ -59,10 +77,42 @@ public class AccessibilityEventTest {
|
|||||||
assertEquals(windowChanges, copyEventViaParcel(event).getWindowChanges());
|
assertEquals(windowChanges, copyEventViaParcel(event).getWindowChanges());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dontForgetToUpdateA11yRecordCtsParcelingTestWhenYouAddNewFields() {
|
||||||
|
AccessibilityEventTest.assertNoNewNonStaticFieldsAdded(
|
||||||
|
AccessibilityRecord.class, A11Y_RECORD_NON_STATIC_FIELD_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dontForgetToUpdateA11yEventCtsParcelingTestWhenYouAddNewFields() {
|
||||||
|
AccessibilityEventTest.assertNoNewNonStaticFieldsAdded(
|
||||||
|
AccessibilityEvent.class, A11Y_EVENT_NON_STATIC_FIELD_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
private AccessibilityEvent copyEventViaParcel(AccessibilityEvent event) {
|
private AccessibilityEvent copyEventViaParcel(AccessibilityEvent event) {
|
||||||
Parcel parcel = Parcel.obtain();
|
Parcel parcel = Parcel.obtain();
|
||||||
event.writeToParcel(parcel, 0);
|
event.writeToParcel(parcel, 0);
|
||||||
parcel.setDataPosition(0);
|
parcel.setDataPosition(0);
|
||||||
return AccessibilityEvent.CREATOR.createFromParcel(parcel);
|
return AccessibilityEvent.CREATOR.createFromParcel(parcel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that no new fields have been added, so we are testing marshaling
|
||||||
|
* of all such.
|
||||||
|
*/
|
||||||
|
static void assertNoNewNonStaticFieldsAdded(Class<?> clazz, int expectedCount) {
|
||||||
|
int nonStaticFieldCount = 0;
|
||||||
|
|
||||||
|
while (clazz != Object.class) {
|
||||||
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
|
if ((field.getModifiers() & Modifier.STATIC) == 0) {
|
||||||
|
nonStaticFieldCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = "New fields have been added, so add code to test marshaling them.";
|
||||||
|
assertEquals(message, expectedCount, nonStaticFieldCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,16 @@ import java.util.ArrayList;
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class AccessibilityNodeInfoTest {
|
public class AccessibilityNodeInfoTest {
|
||||||
|
// The number of fields tested in the corresponding CTS AccessibilityNodeInfoTest:
|
||||||
|
// See fullyPopulateAccessibilityNodeInfo, assertEqualsAccessibilityNodeInfo,
|
||||||
|
// and assertAccessibilityNodeInfoCleared in that class.
|
||||||
|
private static final int NUM_MARSHALLED_PROPERTIES = 35;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of properties that are purposely not marshalled
|
||||||
|
* mOriginalText - Used when resolving clickable spans; intentionally not parceled
|
||||||
|
*/
|
||||||
|
private static final int NUM_NONMARSHALLED_PROPERTIES = 1;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStandardActions_serializationFlagIsValid() {
|
public void testStandardActions_serializationFlagIsValid() {
|
||||||
@@ -114,4 +124,10 @@ public class AccessibilityNodeInfoTest {
|
|||||||
assertThat(unparceledNode.getActionList(), emptyCollectionOf(AccessibilityAction.class));
|
assertThat(unparceledNode.getActionList(), emptyCollectionOf(AccessibilityAction.class));
|
||||||
assertThat(unparceledNode.getText(), equalTo(text));
|
assertThat(unparceledNode.getText(), equalTo(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dontForgetToUpdateCtsParcelingTestWhenYouAddNewFields() {
|
||||||
|
AccessibilityEventTest.assertNoNewNonStaticFieldsAdded(AccessibilityNodeInfo.class,
|
||||||
|
NUM_MARSHALLED_PROPERTIES + NUM_NONMARSHALLED_PROPERTIES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user