diff options
Diffstat (limited to 'core/tests/coretests/src/android/widget/TextViewTest.java')
-rw-r--r-- | core/tests/coretests/src/android/widget/TextViewTest.java | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/core/tests/coretests/src/android/widget/TextViewTest.java b/core/tests/coretests/src/android/widget/TextViewTest.java index 6db67c0..c54e4a1 100644 --- a/core/tests/coretests/src/android/widget/TextViewTest.java +++ b/core/tests/coretests/src/android/widget/TextViewTest.java @@ -16,23 +16,25 @@ package android.widget; -import com.google.android.collect.Lists; -import com.google.android.collect.Maps; +import com.android.frameworks.coretests.R; -import android.test.AndroidTestCase; +import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.SmallTest; import android.text.GetChars; import android.view.View; -import android.widget.TextView; /** * TextViewTest tests {@link TextView}. */ -public class TextViewTest extends AndroidTestCase { +public class TextViewTest extends ActivityInstrumentationTestCase2<TextViewTestActivity> { + + public TextViewTest() { + super(TextViewTestActivity.class); + } @SmallTest public void testArray() throws Exception { - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); char[] c = new char[] { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!' }; @@ -62,13 +64,13 @@ public class TextViewTest extends AndroidTestCase { @SmallTest public void testTextDirectionDefault() { - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); assertEquals(View.TEXT_DIRECTION_INHERIT, tv.getTextDirection()); } @SmallTest public void testSetGetTextDirection() { - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getTextDirection()); @@ -88,7 +90,7 @@ public class TextViewTest extends AndroidTestCase { @SmallTest public void testGetResolvedTextDirectionLtr() { - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); tv.setText("this is a test"); tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); @@ -109,10 +111,10 @@ public class TextViewTest extends AndroidTestCase { @SmallTest public void testGetResolvedTextDirectionLtrWithInheritance() { - LinearLayout ll = new LinearLayout(mContext); + LinearLayout ll = new LinearLayout(getActivity()); ll.setTextDirection(View.TEXT_DIRECTION_RTL); - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); tv.setText("this is a test"); ll.addView(tv); @@ -134,7 +136,7 @@ public class TextViewTest extends AndroidTestCase { @SmallTest public void testGetResolvedTextDirectionRtl() { - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); tv.setText("\u05DD\u05DE"); // hebrew tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); @@ -155,10 +157,9 @@ public class TextViewTest extends AndroidTestCase { @SmallTest public void testGetResolvedTextDirectionRtlWithInheritance() { - LinearLayout ll = new LinearLayout(mContext); - ll.setTextDirection(View.TEXT_DIRECTION_RTL); + LinearLayout ll = new LinearLayout(getActivity()); - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); tv.setText("\u05DD\u05DE"); // hebrew ll.addView(tv); @@ -169,6 +170,24 @@ public class TextViewTest extends AndroidTestCase { assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); + assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_LTR); + assertEquals(View.TEXT_DIRECTION_LTR, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_RTL); + assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + // Force to RTL text direction on the layout + ll.setTextDirection(View.TEXT_DIRECTION_RTL); + + tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); + assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_ANY_RTL); + assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + + tv.setTextDirection(View.TEXT_DIRECTION_INHERIT); assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); tv.setTextDirection(View.TEXT_DIRECTION_LTR); @@ -180,10 +199,10 @@ public class TextViewTest extends AndroidTestCase { @SmallTest public void testCharCountHeuristic() { - LinearLayout ll = new LinearLayout(mContext); + LinearLayout ll = new LinearLayout(getActivity()); ll.setLayoutDirection(View.LAYOUT_DIRECTION_RTL); - TextView tv = new TextView(mContext); + TextView tv = new TextView(getActivity()); ll.addView(tv); tv.setTextDirection(View.TEXT_DIRECTION_CHAR_COUNT); @@ -211,4 +230,23 @@ public class TextViewTest extends AndroidTestCase { tv.setText("ab \u05DD\u05DE"); // latin + hebrew at 50% each assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); } + + @SmallTest + public void testResetTextDirection() { + final TextViewTestActivity activity = getActivity(); + + final LinearLayout ll = (LinearLayout) activity.findViewById(R.id.textviewtest_layout); + final TextView tv = (TextView) activity.findViewById(R.id.textviewtest_textview); + + getActivity().runOnUiThread(new Runnable() { + public void run() { + tv.setTextDirection(View.TEXT_DIRECTION_FIRST_STRONG); + assertEquals(View.TEXT_DIRECTION_RTL, tv.getResolvedTextDirection()); + assertEquals(true, tv.isResolvedTextDirection()); + + ll.removeView(tv); + assertEquals(false, tv.isResolvedTextDirection()); + } + }); + } } |