summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Roozbeh Pournader <roozbeh@google.com> 2017-07-06 17:07:39 -0700
committer Roozbeh Pournader <roozbeh@google.com> 2017-07-06 17:16:33 -0700
commitc38d390c5cd35bbcea29d49120ea15eb7f9bfed1 (patch)
treec9e0b53f7ee383d11c4bb54fac2487ccebd6a556
parent0b513504e085cd270fb70ea29523d2ed6bbf15c3 (diff)
Trying to fix flaky tests related to testCharSequence*
We now recycle the Parcels after use. Hoping this fixes/reduces flakiness. Bug: 62715590 Test: adb shell am instrument -w -e package android.text com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner Change-Id: Ifbce8d8a7d823d36aa7bfbeae49059ae15abd334
-rw-r--r--core/tests/coretests/src/android/text/TextUtilsTest.java59
1 files changed, 40 insertions, 19 deletions
diff --git a/core/tests/coretests/src/android/text/TextUtilsTest.java b/core/tests/coretests/src/android/text/TextUtilsTest.java
index 4cc648def549..472b3e2cd20d 100644
--- a/core/tests/coretests/src/android/text/TextUtilsTest.java
+++ b/core/tests/coretests/src/android/text/TextUtilsTest.java
@@ -363,14 +363,23 @@ public class TextUtilsTest {
@Test
public void testCharSequenceCreator() {
Parcel p = Parcel.obtain();
- TextUtils.writeToParcel(null, p, 0);
- CharSequence text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
- assertNull("null CharSequence should generate null from parcel", text);
+ CharSequence text;
+ try {
+ TextUtils.writeToParcel(null, p, 0);
+ text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+ assertNull("null CharSequence should generate null from parcel", text);
+ } finally {
+ p.recycle();
+ }
p = Parcel.obtain();
- TextUtils.writeToParcel("test", p, 0);
- p.setDataPosition(0);
- text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
- assertEquals("conversion to/from parcel failed", "test", text);
+ try {
+ TextUtils.writeToParcel("test", p, 0);
+ p.setDataPosition(0);
+ text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+ assertEquals("conversion to/from parcel failed", "test", text);
+ } finally {
+ p.recycle();
+ }
}
@Test
@@ -378,10 +387,14 @@ public class TextUtilsTest {
Parcel p;
CharSequence text;
p = Parcel.obtain();
- TextUtils.writeToParcel(null, p, 0);
- p.setDataPosition(0);
- text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
- assertNull("null CharSequence should generate null from parcel", text);
+ try {
+ TextUtils.writeToParcel(null, p, 0);
+ p.setDataPosition(0);
+ text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+ assertNull("null CharSequence should generate null from parcel", text);
+ } finally {
+ p.recycle();
+ }
}
@Test
@@ -389,10 +402,14 @@ public class TextUtilsTest {
Parcel p;
CharSequence text;
p = Parcel.obtain();
- TextUtils.writeToParcel(new SpannableString("test"), p, 0);
- p.setDataPosition(0);
- text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
- assertEquals("conversion to/from parcel failed", "test", text.toString());
+ try {
+ TextUtils.writeToParcel(new SpannableString("test"), p, 0);
+ p.setDataPosition(0);
+ text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+ assertEquals("conversion to/from parcel failed", "test", text.toString());
+ } finally {
+ p.recycle();
+ }
}
@Test
@@ -400,10 +417,14 @@ public class TextUtilsTest {
Parcel p;
CharSequence text;
p = Parcel.obtain();
- TextUtils.writeToParcel("test", p, 0);
- p.setDataPosition(0);
- text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
- assertEquals("conversion to/from parcel failed", "test", text.toString());
+ try {
+ TextUtils.writeToParcel("test", p, 0);
+ p.setDataPosition(0);
+ text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+ assertEquals("conversion to/from parcel failed", "test", text.toString());
+ } finally {
+ p.recycle();
+ }
}
/**