summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2011-04-29 10:00:20 -0700
committerAndroid Code Review <code-review@android.com>2011-04-29 10:00:20 -0700
commit425db473a05e4204301bf46d4ab6f51b12d9c447 (patch)
tree1b22b697ed69b94982c26ceeddba78a861c0adb1
parent58e4a5e2094c5003225fc715ee1a53b2461e71b1 (diff)
parentcee2051adac53a85653ba8ead3a671c0978af43b (diff)
downloadframeworks_base-425db473a05e4204301bf46d4ab6f51b12d9c447.zip
frameworks_base-425db473a05e4204301bf46d4ab6f51b12d9c447.tar.gz
frameworks_base-425db473a05e4204301bf46d4ab6f51b12d9c447.tar.bz2
Merge "CHAR_SEQUENCE_CREATOR cannot handle null string"
-rw-r--r--core/java/android/text/TextUtils.java12
-rw-r--r--core/tests/coretests/src/android/text/TextUtilsTest.java46
2 files changed, 55 insertions, 3 deletions
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java
index 8675d05..0d7aa02 100644
--- a/core/java/android/text/TextUtils.java
+++ b/core/java/android/text/TextUtils.java
@@ -627,10 +627,16 @@ public class TextUtils {
public CharSequence createFromParcel(Parcel p) {
int kind = p.readInt();
- if (kind == 1)
- return p.readString();
+ String string = p.readString();
+ if (string == null) {
+ return null;
+ }
+
+ if (kind == 1) {
+ return string;
+ }
- SpannableString sp = new SpannableString(p.readString());
+ SpannableString sp = new SpannableString(string);
while (true) {
kind = p.readInt();
diff --git a/core/tests/coretests/src/android/text/TextUtilsTest.java b/core/tests/coretests/src/android/text/TextUtilsTest.java
index 79d57f1..63dd0cc 100644
--- a/core/tests/coretests/src/android/text/TextUtilsTest.java
+++ b/core/tests/coretests/src/android/text/TextUtilsTest.java
@@ -17,6 +17,7 @@
package android.text;
import android.graphics.Paint;
+import android.os.Parcel;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.Spannable;
@@ -352,6 +353,51 @@ public class TextUtilsTest extends TestCase {
assertFalse(TextUtils.delimitedStringContains("network,mock,gpsx", ',', "gps"));
}
+ @SmallTest
+ 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);
+ p = Parcel.obtain();
+ TextUtils.writeToParcel("test", p, 0);
+ text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
+ assertEquals("conversion to/from parcel failed", "test", text);
+ }
+
+ @SmallTest
+ public void testCharSequenceCreatorNull() {
+ 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);
+ }
+
+ @SmallTest
+ public void testCharSequenceCreatorSpannable() {
+ 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());
+ }
+
+ @SmallTest
+ public void testCharSequenceCreatorString() {
+ 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());
+ }
+
/**
* CharSequence wrapper for testing the cases where text is copied into
* a char array instead of working from a String or a Spanned.