Add more CTS test for TextView and Drawables

- see bug #7419054 TextView Drawables resolution is broken in RTL mode

Change-Id: I05cceb1f59aa1a96e73ac378b6ae6b1decca0b8b
diff --git a/tests/res/drawable/icon_black.jpg b/tests/res/drawable/icon_black.jpg
new file mode 100644
index 0000000..4c9062a
--- /dev/null
+++ b/tests/res/drawable/icon_black.jpg
Binary files differ
diff --git a/tests/res/drawable/icon_blue.jpg b/tests/res/drawable/icon_blue.jpg
new file mode 100644
index 0000000..9e6c1c8
--- /dev/null
+++ b/tests/res/drawable/icon_blue.jpg
Binary files differ
diff --git a/tests/res/drawable/icon_green.jpg b/tests/res/drawable/icon_green.jpg
new file mode 100644
index 0000000..55a78f2
--- /dev/null
+++ b/tests/res/drawable/icon_green.jpg
Binary files differ
diff --git a/tests/res/drawable/icon_red.jpg b/tests/res/drawable/icon_red.jpg
new file mode 100644
index 0000000..6bc9e1f
--- /dev/null
+++ b/tests/res/drawable/icon_red.jpg
Binary files differ
diff --git a/tests/res/drawable/icon_yellow.jpg b/tests/res/drawable/icon_yellow.jpg
new file mode 100644
index 0000000..e748059
--- /dev/null
+++ b/tests/res/drawable/icon_yellow.jpg
Binary files differ
diff --git a/tests/res/layout/textview_layout.xml b/tests/res/layout/textview_layout.xml
index 512184f..5aea538 100644
--- a/tests/res/layout/textview_layout.xml
+++ b/tests/res/layout/textview_layout.xml
@@ -96,4 +96,120 @@
               android:layout_height="wrap_content"
               android:layout_width="wrap_content"/>
 
+    <TextView android:id="@+id/textview_drawable_1_1"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:drawableLeft="@drawable/icon_blue"
+              android:drawableRight="@drawable/icon_red"
+              android:drawableTop="@drawable/icon_green"
+              android:drawableBottom="@drawable/icon_yellow"
+            />
+
+    <TextView android:id="@+id/textview_drawable_1_2"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:drawableLeft="@drawable/icon_blue"
+              android:drawableRight="@drawable/icon_red"
+              android:drawableTop="@drawable/icon_green"
+              android:drawableBottom="@drawable/icon_yellow"
+              android:layoutDirection="rtl"
+            />
+
+    <TextView android:id="@+id/textview_drawable_2_1"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:drawableStart="@drawable/icon_blue"
+              android:drawableEnd="@drawable/icon_red"
+              android:drawableTop="@drawable/icon_green"
+              android:drawableBottom="@drawable/icon_yellow"
+            />
+
+    <TextView android:id="@+id/textview_drawable_2_2"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:drawableStart="@drawable/icon_blue"
+              android:drawableEnd="@drawable/icon_red"
+              android:drawableTop="@drawable/icon_green"
+              android:drawableBottom="@drawable/icon_yellow"
+              android:layoutDirection="rtl"
+            />
+
+    <TextView android:id="@+id/textview_drawable_3_1"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:drawableLeft="@drawable/icon_black"
+              android:drawableRight="@drawable/icon_black"
+              android:drawableStart="@drawable/icon_blue"
+              android:drawableEnd="@drawable/icon_red"
+              android:drawableTop="@drawable/icon_green"
+              android:drawableBottom="@drawable/icon_yellow"
+            />
+
+    <TextView android:id="@+id/textview_drawable_3_2"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:drawableLeft="@drawable/icon_black"
+              android:drawableRight="@drawable/icon_black"
+              android:drawableStart="@drawable/icon_blue"
+              android:drawableEnd="@drawable/icon_red"
+              android:drawableTop="@drawable/icon_green"
+              android:drawableBottom="@drawable/icon_yellow"
+              android:layoutDirection="rtl"
+            />
+
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="ltr">
+
+        <TextView android:id="@+id/textview_drawable_4_1"
+                  android:layout_height="wrap_content"
+                  android:layout_width="wrap_content"
+                  android:drawableStart="@drawable/icon_blue"
+                  android:drawableEnd="@drawable/icon_red"
+                  android:drawableTop="@drawable/icon_green"
+                  android:drawableBottom="@drawable/icon_yellow"
+                />
+
+        <TextView android:id="@+id/textview_drawable_5_1"
+                  android:layout_height="wrap_content"
+                  android:layout_width="wrap_content"
+                  android:drawableLeft="@drawable/icon_black"
+                  android:drawableRight="@drawable/icon_black"
+                  android:drawableStart="@drawable/icon_blue"
+                  android:drawableEnd="@drawable/icon_red"
+                  android:drawableTop="@drawable/icon_green"
+                  android:drawableBottom="@drawable/icon_yellow"
+                />
+
+    </LinearLayout>
+
+    <LinearLayout android:orientation="vertical"
+                  android:layout_width="match_parent"
+                  android:layout_height="match_parent"
+                  android:layoutDirection="rtl">
+
+        <TextView android:id="@+id/textview_drawable_4_2"
+                  android:layout_height="wrap_content"
+                  android:layout_width="wrap_content"
+                  android:drawableStart="@drawable/icon_blue"
+                  android:drawableEnd="@drawable/icon_red"
+                  android:drawableTop="@drawable/icon_green"
+                  android:drawableBottom="@drawable/icon_yellow"
+                />
+
+        <TextView android:id="@+id/textview_drawable_5_2"
+                  android:layout_height="wrap_content"
+                  android:layout_width="wrap_content"
+                  android:drawableLeft="@drawable/icon_black"
+                  android:drawableRight="@drawable/icon_black"
+                  android:drawableStart="@drawable/icon_blue"
+                  android:drawableEnd="@drawable/icon_red"
+                  android:drawableTop="@drawable/icon_green"
+                  android:drawableBottom="@drawable/icon_yellow"
+                />
+
+    </LinearLayout>
+
 </LinearLayout>
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index b4279f2..9080320 100755
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -3279,6 +3279,150 @@
         assertEquals(View.TEXT_ALIGNMENT_GRAVITY, tv.getTextAlignment());
     }
 
+    @UiThreadTest
+    public void testDrawableResolution() {
+        final int LEFT = 0;
+        final int TOP = 1;
+        final int RIGHT = 2;
+        final int BOTTOM = 3;
+
+        TextViewStubActivity activity = getActivity();
+
+        // Case 1.1: left / right drawable defined in default LTR mode
+        TextView tv = (TextView) activity.findViewById(R.id.textview_drawable_1_1);
+        Drawable[] drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 1.2: left / right drawable defined in default RTL mode
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_1_2);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 2.1: start / end drawable defined in LTR mode
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_2_1);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 2.2: start / end drawable defined in RTL mode
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_2_2);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 3.1: left / right / start / end drawable defined in LTR mode
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_3_1);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 3.2: left / right / start / end drawable defined in RTL mode
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_3_2);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 4.1: start / end drawable defined in LTR mode inside a layout
+        // that defines the layout direction
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_4_1);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 4.2: start / end drawable defined in RTL mode inside a layout
+        // that defines the layout direction
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_4_2);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 5.1: left / right / start / end drawable defined in LTR mode inside a layout
+        // that defines the layout direction
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_3_1);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+
+        // Case 5.2: left / right / start / end drawable defined in RTL mode inside a layout
+        // that defines the layout direction
+        tv = (TextView) activity.findViewById(R.id.textview_drawable_3_2);
+        drawables = tv.getCompoundDrawables();
+
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_red),
+                ((BitmapDrawable) drawables[LEFT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_blue),
+                ((BitmapDrawable) drawables[RIGHT]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_green),
+                ((BitmapDrawable) drawables[TOP]).getBitmap());
+        WidgetTestUtils.assertEquals(getBitmap(R.drawable.icon_yellow),
+                ((BitmapDrawable) drawables[BOTTOM]).getBitmap());
+    }
+
     private static class MockOnEditorActionListener implements OnEditorActionListener {
         private boolean isOnEditorActionCalled;