Add CTS unit tests for View textAlignment
Change-Id: I4f0344b4e3e1722d91287f10774ad0e25b583f7b
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index f6bb07b..7b321d7 100755
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -3150,6 +3150,128 @@
assertEquals(View.TEXT_DIRECTION_FIRST_STRONG, tv.getResolvedTextDirection());
}
+ @UiThreadTest
+ public void testTextAlignmentDefault() {
+ TextView tv = new TextView(getActivity());
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getTextAlignment());
+ // resolved default text alignment is GRAVITY
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getResolvedTextAlignment());
+ }
+
+ @UiThreadTest
+ public void testSetGetTextAlignment() {
+ TextView tv = new TextView(getActivity());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
+ assertEquals(View.TEXT_ALIGNMENT_TEXT_START, tv.getTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
+ assertEquals(View.TEXT_ALIGNMENT_TEXT_END, tv.getTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
+ assertEquals(View.TEXT_ALIGNMENT_VIEW_START, tv.getTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
+ assertEquals(View.TEXT_ALIGNMENT_VIEW_END, tv.getTextAlignment());
+ }
+
+ @UiThreadTest
+ public void testGetResolvedTextAlignment() {
+ TextView tv = new TextView(getActivity());
+
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getResolvedTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getResolvedTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
+ assertEquals(View.TEXT_ALIGNMENT_TEXT_START, tv.getResolvedTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
+ assertEquals(View.TEXT_ALIGNMENT_TEXT_END, tv.getResolvedTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
+ assertEquals(View.TEXT_ALIGNMENT_VIEW_START, tv.getResolvedTextAlignment());
+
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
+ assertEquals(View.TEXT_ALIGNMENT_VIEW_END, tv.getResolvedTextAlignment());
+ }
+
+ @UiThreadTest
+ public void testGetResolvedTextAlignmentWithInheritance() {
+ LinearLayout ll = new LinearLayout(getActivity());
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
+
+ TextView tv = new TextView(getActivity());
+ ll.addView(tv);
+
+ // check defaults
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getTextAlignment());
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getResolvedTextAlignment());
+
+ // set inherit and check that child is following parent
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_INHERIT);
+ assertEquals(View.TEXT_ALIGNMENT_INHERIT, tv.getTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
+ assertEquals(View.TEXT_ALIGNMENT_TEXT_START, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
+ assertEquals(View.TEXT_ALIGNMENT_TEXT_END, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
+ assertEquals(View.TEXT_ALIGNMENT_VIEW_START, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
+ assertEquals(View.TEXT_ALIGNMENT_VIEW_END, tv.getResolvedTextAlignment());
+
+ // now get rid of the inheritance but still change the parent
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+ }
+
+ @UiThreadTest
+ public void testResetTextAlignment() {
+ TextViewStubActivity activity = getActivity();
+
+ LinearLayout ll = (LinearLayout) activity.findViewById(R.id.layout_textviewtest);
+ TextView tv = (TextView) activity.findViewById(R.id.textview_rtl);
+
+ ll.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
+ tv.setTextAlignment(View.TEXT_ALIGNMENT_INHERIT);
+ assertEquals(View.TEXT_ALIGNMENT_CENTER, tv.getResolvedTextAlignment());
+
+ ll.removeView(tv);
+ // default text alignment is GRAVITY
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getResolvedTextAlignment());
+ }
+
private static class MockOnEditorActionListener implements OnEditorActionListener {
private boolean isOnEditorActionCalled;