Add more CTS tests for RelativeLayout RTL support
Change-Id: Ib4aca327422f8034985072626c8926b5a89eab9d
diff --git a/tests/res/layout/relative_layout.xml b/tests/res/layout/relative_layout.xml
index 669e86e..db4b2e8 100644
--- a/tests/res/layout/relative_layout.xml
+++ b/tests/res/layout/relative_layout.xml
@@ -162,4 +162,97 @@
android:layout_height="match_parent"
android:prompt="@string/text_view_hello"/>
+ <RelativeLayout
+ android:id="@+id/relative_sublayout_attrs_2"
+ android:background="@drawable/blue"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <!-- view21, centered within its parent. -->
+ <TextView
+ android:id="@+id/relative_view21"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:text="@string/relative_view1"/>
+
+ <!-- view22, below view1 and has same start position with view21. -->
+ <TextView
+ android:id="@+id/relative_view22"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/relative_view21"
+ android:layout_alignStart="@id/relative_view21"
+ android:text="@string/relative_view2"/>
+
+ <!-- view23, has same top position with view21 and same bottom position with view22,
+ and on the end of view1. -->
+ <TextView
+ android:id="@+id/relative_view23"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignTop="@id/relative_view21"
+ android:layout_alignBottom="@id/relative_view22"
+ android:layout_toEndOf="@id/relative_view21"
+ android:text="@string/relative_view3"/>
+
+ <!-- view24, has same end position with view23 and above view23. -->
+ <TextView
+ android:id="@+id/relative_view24"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignEnd="@id/relative_view23"
+ android:layout_above="@id/relative_view23"
+ android:text="@string/relative_view4"/>
+
+ <!-- view25 goes on the start-bottom -->
+ <TextView
+ android:id="@+id/relative_view25"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentStart="true"
+ android:text="@string/relative_view5"/>
+
+ <!-- view26 goes on the top-end -->
+ <TextView
+ android:id="@+id/relative_view26"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentEnd="true"
+ android:text="@string/relative_view6"/>
+
+ <!-- view27, has same baseline with view26 and centered horizontally within its parent. -->
+ <TextView
+ android:id="@+id/relative_view27"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignBaseline="@id/relative_view26"
+ android:layout_centerHorizontal="true"
+ android:text="@string/relative_view7"/>
+
+ <!-- view28, centered vertically within its parent and on the start of view21. -->
+ <TextView
+ android:id="@+id/relative_view28"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toStartOf="@id/relative_view21"
+ android:layout_centerVertical="true"
+ android:text="@string/relative_view8"/>
+
+ <!-- view29, has same top and bottom position with view23 and same start position
+ with its parent. -->
+ <TextView
+ android:id="@+id/relative_view29"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignStart="@id/gravity_bottom"
+ android:layout_alignTop="@id/relative_view23"
+ android:layout_alignBottom="@id/relative_view23"
+ android:layout_alignWithParentIfMissing="true"
+ android:text="@string/relative_view9"/>
+
+ </RelativeLayout>
+
</RelativeLayout>
diff --git a/tests/tests/widget/src/android/widget/cts/RelativeLayout_LayoutParamsTest.java b/tests/tests/widget/src/android/widget/cts/RelativeLayout_LayoutParamsTest.java
index 4c9d2ab..e034562 100644
--- a/tests/tests/widget/src/android/widget/cts/RelativeLayout_LayoutParamsTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RelativeLayout_LayoutParamsTest.java
@@ -160,6 +160,167 @@
assertEquals(R.id.relative_view3, rules[RelativeLayout.ALIGN_BOTTOM]);
}
+ public void testStartEnd() {
+ RelativeLayout.LayoutParams layoutParams;
+
+ // Test RelativeLayout.Params which generated from the xml file.
+ int rules[];
+ RelativeLayoutStubActivity activity = getActivity();
+
+ // test attributes used in RelativeLayout.
+ RelativeLayout relativeLayout = (RelativeLayout) activity.findViewById(
+ R.id.relative_sublayout_attrs_2);
+
+ // view1, centered within its parent.
+ // TEST: android:layout_centerInParent
+ View view1 = activity.findViewById(R.id.relative_view21);
+ ViewAsserts.assertHorizontalCenterAligned(relativeLayout, view1);
+ ViewAsserts.assertVerticalCenterAligned(relativeLayout, view1);
+ layoutParams = (RelativeLayout.LayoutParams) (view1.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.CENTER_IN_PARENT]);
+
+ // view2, below view1 and has same left position with view1.
+ // TEST: android:layout_below; android:layout_alignStart
+ View view2 = activity.findViewById(R.id.relative_view22);
+ ViewAsserts.assertLeftAligned(view1, view2);
+ assertEquals(view1.getBottom(), view2.getTop());
+ layoutParams = (RelativeLayout.LayoutParams) (view2.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.BELOW]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.ALIGN_START]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.ALIGN_LEFT]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_RIGHT]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.BELOW]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.ALIGN_START]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_LEFT]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.ALIGN_RIGHT]);
+
+ // view3, has same top position with view1 and same bottom position with view2,
+ // and on the right of view1.1.
+ // TEST: android:layout_alignTop; android:layout_alignBottom; android:layout_toEndOf
+ View view3 = activity.findViewById(R.id.relative_view23);
+ ViewAsserts.assertTopAligned(view1, view3);
+ ViewAsserts.assertBottomAligned(view2, view3);
+ assertEquals(view1.getRight(), view3.getLeft());
+ layoutParams = (RelativeLayout.LayoutParams) (view3.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.ALIGN_TOP]);
+ assertEquals(R.id.relative_view22, rules[RelativeLayout.ALIGN_BOTTOM]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.END_OF]);
+ assertEquals(0, rules[RelativeLayout.LEFT_OF]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.RIGHT_OF]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.ALIGN_TOP]);
+ assertEquals(R.id.relative_view22, rules[RelativeLayout.ALIGN_BOTTOM]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.END_OF]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.LEFT_OF]);
+ assertEquals(0, rules[RelativeLayout.RIGHT_OF]);
+
+ // view4, has same right position with view3 and above view3.
+ // TEST: android:layout_alignEnd; android:layout_above
+ View view4 = activity.findViewById(R.id.relative_view24);
+ ViewAsserts.assertRightAligned(view3, view4);
+ assertEquals(view3.getTop(), view4.getBottom());
+ layoutParams = (RelativeLayout.LayoutParams) (view4.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_END]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_LEFT]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_RIGHT]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ABOVE]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_END]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_LEFT]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_RIGHT]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ABOVE]);
+
+ // view5 goes on the left-bottom.
+ // TEST: android:layout_alignParentBottom; android:layout_alignParentStart
+ View view5 = activity.findViewById(R.id.relative_view25);
+ ViewAsserts.assertLeftAligned(relativeLayout, view5);
+ ViewAsserts.assertBottomAligned(relativeLayout, view5);
+ layoutParams = (RelativeLayout.LayoutParams) (view5.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_START]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_LEFT]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_RIGHT]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_START]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_LEFT]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_RIGHT]);
+
+ // view6 goes on the top-right.
+ // TEST: android:layout_alignParentTop; android:layout_alignParentEnd
+ View view6 = activity.findViewById(R.id.relative_view26);
+ ViewAsserts.assertTopAligned(relativeLayout, view6);
+ ViewAsserts.assertRightAligned(relativeLayout, view6);
+ layoutParams = (RelativeLayout.LayoutParams) (view6.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_TOP]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_END]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_LEFT]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_RIGHT]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_TOP]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_END]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_LEFT]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_RIGHT]);
+
+ // view7, has same baseline with view6 and centered horizontally within its parent.
+ // TEST: android:layout_alignBaseline; android:layout_centerHorizontal
+ View view7 = activity.findViewById(R.id.relative_view27);
+ ViewAsserts.assertBaselineAligned(view6, view7);
+ ViewAsserts.assertHorizontalCenterAligned(relativeLayout, view7);
+ layoutParams = (RelativeLayout.LayoutParams) (view7.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(R.id.relative_view26, rules[RelativeLayout.ALIGN_BASELINE]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.CENTER_HORIZONTAL]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(R.id.relative_view26, rules[RelativeLayout.ALIGN_BASELINE]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.CENTER_HORIZONTAL]);
+
+ // view8, centered vertically within its parent and on the left of view1.
+ // TEST: android:layout_toStartOf; android:layout_centerVertical
+ View view8 = activity.findViewById(R.id.relative_view28);
+ ViewAsserts.assertVerticalCenterAligned(relativeLayout, view8);
+ assertEquals(view1.getLeft(), view8.getRight());
+ layoutParams = (RelativeLayout.LayoutParams) (view8.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.START_OF]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.LEFT_OF]);
+ assertEquals(0, rules[RelativeLayout.RIGHT_OF]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.CENTER_VERTICAL]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.START_OF]);
+ assertEquals(0, rules[RelativeLayout.LEFT_OF]);
+ assertEquals(R.id.relative_view21, rules[RelativeLayout.RIGHT_OF]);
+ assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.CENTER_VERTICAL]);
+
+ // view9, has same top and bottom position with view3 and same left position with its parent
+ // TEST: android:layout_alignStart; android:layout_alignTop; android:layout_alignBottom;
+ // android:layout_alignWithParentIfMissing
+ View view9 = activity.findViewById(R.id.relative_view29);
+ ViewAsserts.assertTopAligned(view3, view9);
+ ViewAsserts.assertBottomAligned(view3, view9);
+ ViewAsserts.assertLeftAligned(relativeLayout, view9);
+ layoutParams = (RelativeLayout.LayoutParams) (view9.getLayoutParams());
+ rules = layoutParams.getRules();
+ assertEquals(R.id.gravity_bottom, rules[RelativeLayout.ALIGN_START]);
+ assertEquals(R.id.gravity_bottom, rules[RelativeLayout.ALIGN_LEFT]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_RIGHT]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_TOP]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_BOTTOM]);
+ rules = layoutParams.getRules(View.LAYOUT_DIRECTION_RTL);
+ assertEquals(R.id.gravity_bottom, rules[RelativeLayout.ALIGN_START]);
+ assertEquals(0, rules[RelativeLayout.ALIGN_LEFT]);
+ assertEquals(R.id.gravity_bottom, rules[RelativeLayout.ALIGN_RIGHT]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_TOP]);
+ assertEquals(R.id.relative_view23, rules[RelativeLayout.ALIGN_BOTTOM]);
+ }
+
public void testAccessRule1() {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(200, 300);
int rules[]= layoutParams.getRules();