Add tests for new Drawable APIs

Adds tests for Drawable, but also for subclasses that override new method implementations.

Issue #21664685 [CTS] Add tests for newly public methods on Drawable

Change-Id: I1050879c3e25ce991993966bc7f0eb09a15452a5
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
index c895d0d..87ba01e 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
@@ -135,6 +135,22 @@
         assertTrue(bitmapDrawable.getPaint().isFilterBitmap());
     }
 
+    public void testIsFilterBitmap() {
+        InputStream source = mContext.getResources().openRawResource(R.raw.testimage);
+        BitmapDrawable bitmapDrawable = new BitmapDrawable(source);
+
+        assertTrue(bitmapDrawable.isFilterBitmap());
+
+        bitmapDrawable.setFilterBitmap(false);
+        assertFalse(bitmapDrawable.isFilterBitmap());
+        assertEquals(bitmapDrawable.isFilterBitmap(), bitmapDrawable.getPaint().isFilterBitmap());
+
+
+        bitmapDrawable.setFilterBitmap(true);
+        assertTrue(bitmapDrawable.isFilterBitmap());
+        assertEquals(bitmapDrawable.isFilterBitmap(), bitmapDrawable.getPaint().isFilterBitmap());
+    }
+
     public void testSetDither() {
         InputStream source = mContext.getResources().openRawResource(R.raw.testimage);
         BitmapDrawable bitmapDrawable = new BitmapDrawable(source);
@@ -149,6 +165,21 @@
 
     }
 
+    public void testGetDither() {
+        InputStream source = mContext.getResources().openRawResource(R.raw.testimage);
+        BitmapDrawable bitmapDrawable = new BitmapDrawable(source);
+
+        assertTrue(bitmapDrawable.getPaint().isDither());
+
+        bitmapDrawable.setDither(false);
+        assertFalse(bitmapDrawable.getDither());
+        assertEquals(bitmapDrawable.getDither(), bitmapDrawable.getPaint().isDither());
+
+        bitmapDrawable.setDither(true);
+        assertTrue(bitmapDrawable.getDither());
+        assertEquals(bitmapDrawable.getDither(), bitmapDrawable.getPaint().isDither());
+    }
+
     public void testAccessTileMode() {
         InputStream source = mContext.getResources().openRawResource(R.raw.testimage);
         BitmapDrawable bitmapDrawable = new BitmapDrawable(source);
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableContainerTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableContainerTest.java
index 036c756..bd19b00 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableContainerTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableContainerTest.java
@@ -16,6 +16,7 @@
 
 package android.graphics.drawable.cts;
 
+import android.graphics.drawable.GradientDrawable;
 import junit.framework.TestCase;
 
 import java.util.Arrays;
@@ -185,6 +186,63 @@
         assertTrue(dr.hasSetDitherCalled());
     }
 
+    public void testGetDither() {
+        assertConstantStateNotSet();
+        assertNull(mDrawableContainer.getCurrent());
+
+        mDrawableContainer.setConstantState(mDrawableContainerState);
+
+        MockDrawable dr = new MockDrawable();
+        addAndSelectDrawable(dr);
+
+
+        mDrawableContainer.setDither(true);
+        assertTrue(mDrawableContainer.getDither());
+
+        mDrawableContainer.setDither(false);
+        assertFalse(mDrawableContainer.getDither());
+
+        dr.reset();
+    }
+
+    public void testSetHotspotBounds() {
+        Rect bounds = new Rect(10, 15, 100, 150);
+        assertConstantStateNotSet();
+        assertNull(mDrawableContainer.getCurrent());
+
+        mDrawableContainer.setConstantState(mDrawableContainerState);
+
+        MockDrawable dr = new MockDrawable();
+        addAndSelectDrawable(dr);
+
+        dr.reset();
+        mDrawableContainer.setHotspotBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
+        Rect outRect = new Rect();
+        mDrawableContainer.getHotspotBounds(outRect);
+        assertEquals(bounds, outRect);
+
+        dr.reset();
+    }
+
+    public void testGetHotspotBounds() {
+        Rect bounds = new Rect(10, 15, 100, 150);
+        assertConstantStateNotSet();
+        assertNull(mDrawableContainer.getCurrent());
+
+        mDrawableContainer.setConstantState(mDrawableContainerState);
+
+        MockDrawable dr = new MockDrawable();
+        addAndSelectDrawable(dr);
+
+        dr.reset();
+        mDrawableContainer.setHotspotBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
+        Rect outRect = new Rect();
+        mDrawableContainer.getHotspotBounds(outRect);
+        assertEquals(bounds, outRect);
+
+        dr.reset();
+    }
+
     public void testSetColorFilter() {
         assertConstantStateNotSet();
         assertNull(mDrawableContainer.getCurrent());
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
index a48372e..56ccc7c 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/DrawableTest.java
@@ -16,6 +16,8 @@
 
 package android.graphics.drawable.cts;
 
+import android.graphics.drawable.BitmapDrawable;
+import android.view.View;
 import com.android.cts.graphics.R;
 
 import org.xmlpull.v1.XmlPullParser;
@@ -545,6 +547,54 @@
         mockDrawable.setDither(false);
     }
 
+    public void testGetDither() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        // getDither simply returns false for Drawable superclass
+        assertFalse((mockDrawable.getDither()));
+    }
+
+    public void testSetHotspotBounds() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        // setHotspotBounds is a non-operation function.
+        mockDrawable.setHotspotBounds(10, 15, 100, 150);
+    }
+
+    public void testGetHotspotBounds() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        // getHotspotBounds doesn't do anything interesting in the Drawable superclass
+        mockDrawable.getHotspotBounds(new Rect());
+    }
+
+    public void testSetLayoutDirection() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        mockDrawable.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
+        assertEquals(View.LAYOUT_DIRECTION_LTR, mockDrawable.getLayoutDirection());
+
+        mockDrawable.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
+        assertEquals(View.LAYOUT_DIRECTION_RTL, mockDrawable.getLayoutDirection());
+    }
+
+    public void testGetLayoutDirection() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        mockDrawable.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
+        assertEquals(View.LAYOUT_DIRECTION_LTR, mockDrawable.getLayoutDirection());
+
+        mockDrawable.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
+        assertEquals(View.LAYOUT_DIRECTION_RTL, mockDrawable.getLayoutDirection());
+    }
+
+    public void testOnLayoutDirectionChanged() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        // onLayoutDirectionChanged is a non-operation function.
+        mockDrawable.onLayoutDirectionChanged(View.LAYOUT_DIRECTION_LTR);
+    }
+
     public void testSetFilterBitmap() {
         MockDrawable mockDrawable = new MockDrawable();
 
@@ -552,6 +602,13 @@
         mockDrawable.setFilterBitmap(false);
     }
 
+    public void testIsFilterBitmap() {
+        MockDrawable mockDrawable = new MockDrawable();
+
+        // setFilterBitmap is a non-operation function.
+        mockDrawable.isFilterBitmap();
+    }
+
     public void testUnscheduleSelf() {
         MockDrawable mockDrawable = new MockDrawable();
         MockCallback mockCallback = new MockCallback();
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java
index eeda22c..78980a5 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/GradientDrawableTest.java
@@ -189,6 +189,16 @@
         gradientDrawable.setDither(false);
     }
 
+    public void testGetDither() {
+        GradientDrawable gradientDrawable = new GradientDrawable();
+
+        gradientDrawable.setDither(true);
+        assertTrue(gradientDrawable.getDither());
+
+        gradientDrawable.setDither(false);
+        assertFalse(gradientDrawable.getDither());
+    }
+
     public void testSetColorFilter() {
         GradientDrawable gradientDrawable = new GradientDrawable();
         ColorFilter cf = new ColorFilter();
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java
index e930671..452f0d0 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/LayerDrawableTest.java
@@ -501,6 +501,45 @@
         assertTrue(mockDrawable2.hasCalledSetDither());
     }
 
+    public void testGetDither() {
+        MockDrawable mockDrawable1 = new MockDrawable();
+        MockDrawable mockDrawable2 = new MockDrawable();
+        Drawable[] array = new Drawable[] { mockDrawable1, mockDrawable2 };
+        LayerDrawable layerDrawable = new LayerDrawable(array);
+
+        layerDrawable.setDither(true);
+        assertTrue(layerDrawable.getDither());
+
+        layerDrawable.setDither(false);
+        assertFalse(layerDrawable.getDither());
+    }
+
+    public void testSetHotspotBounds() {
+        Rect bounds = new Rect(10, 15, 100, 150);
+        MockDrawable mockDrawable1 = new MockDrawable();
+        MockDrawable mockDrawable2 = new MockDrawable();
+        Drawable[] array = new Drawable[] { mockDrawable1, mockDrawable2 };
+        LayerDrawable layerDrawable = new LayerDrawable(array);
+
+        layerDrawable.setHotspotBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
+        Rect outRect = new Rect();
+        layerDrawable.getHotspotBounds(outRect);
+        assertTrue(bounds.equals(outRect));
+    }
+
+    public void testGetHotspotBounds() {
+        Rect bounds = new Rect(10, 15, 100, 150);
+        MockDrawable mockDrawable1 = new MockDrawable();
+        MockDrawable mockDrawable2 = new MockDrawable();
+        Drawable[] array = new Drawable[] { mockDrawable1, mockDrawable2 };
+        LayerDrawable layerDrawable = new LayerDrawable(array);
+
+        layerDrawable.setHotspotBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
+        Rect outRect = new Rect();
+        layerDrawable.getHotspotBounds(outRect);
+        assertTrue(bounds.equals(outRect));
+    }
+
     public void testSetAlpha() {
         MockDrawable mockDrawable1 = new MockDrawable();
         MockDrawable mockDrawable2 = new MockDrawable();
@@ -776,6 +815,8 @@
 
         private int mOpacity = PixelFormat.OPAQUE;
 
+        private boolean mDither = false;
+
         Rect mPadding = null;
 
         public MockDrawable() {
@@ -816,9 +857,15 @@
 
         @Override
         public void setDither(boolean dither) {
+            mDither = dither;
             mCalledSetDither = true;
         }
 
+        @Override
+        public boolean getDither() {
+            return mDither;
+        }
+
         public boolean hasCalledSetDither() {
             return mCalledSetDither;
         }
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/NinePatchDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/NinePatchDrawableTest.java
index 39ed55c..94c189a 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/NinePatchDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/NinePatchDrawableTest.java
@@ -16,6 +16,7 @@
 
 package android.graphics.drawable.cts;
 
+import android.graphics.drawable.BitmapDrawable;
 import com.android.cts.graphics.R;
 
 import org.xmlpull.v1.XmlPullParser;
@@ -45,6 +46,7 @@
 import android.util.Xml;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 public class NinePatchDrawableTest extends InstrumentationTestCase {
     private static final int MIN_CHUNK_SIZE = 32;
@@ -200,6 +202,37 @@
         assertTrue(mNinePatchDrawable.getPaint().isDither());
     }
 
+    public void testGetDither() {
+        mNinePatchDrawable.setDither(false);
+        assertFalse(mNinePatchDrawable.getDither());
+        assertEquals(mNinePatchDrawable.getDither(), mNinePatchDrawable.getPaint().isDither());
+
+        mNinePatchDrawable.setDither(true);
+        assertTrue(mNinePatchDrawable.getDither());
+        assertEquals(mNinePatchDrawable.getDither(), mNinePatchDrawable.getPaint().isDither());
+    }
+
+    public void testSetFilterBitmap() {
+        mNinePatchDrawable.setFilterBitmap(false);
+        assertFalse(mNinePatchDrawable.getPaint().isFilterBitmap());
+
+        mNinePatchDrawable.setFilterBitmap(true);
+        assertTrue(mNinePatchDrawable.getPaint().isFilterBitmap());
+    }
+
+    public void testIsFilterBitmap() {
+        mNinePatchDrawable.setFilterBitmap(false);
+        assertFalse(mNinePatchDrawable.isFilterBitmap());
+        assertEquals(mNinePatchDrawable.isFilterBitmap(),
+                mNinePatchDrawable.getPaint().isFilterBitmap());
+
+
+        mNinePatchDrawable.setFilterBitmap(true);
+        assertTrue(mNinePatchDrawable.isFilterBitmap());
+        assertEquals(mNinePatchDrawable.isFilterBitmap(),
+                mNinePatchDrawable.getPaint().isFilterBitmap());
+    }
+
     public void testGetPaint() {
         Paint paint = mNinePatchDrawable.getPaint();
         assertNotNull(paint);
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/ShapeDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/ShapeDrawableTest.java
index b77139a..f39bdbe 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/ShapeDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/ShapeDrawableTest.java
@@ -333,6 +333,18 @@
         assertFalse(shapeDrawable.getPaint().isDither());
     }
 
+    public void testGetDither() {
+        ShapeDrawable shapeDrawable = new ShapeDrawable();
+
+        shapeDrawable.setDither(true);
+        assertTrue(shapeDrawable.getDither());
+        assertEquals(shapeDrawable.getDither(), shapeDrawable.getPaint().isDither());
+
+        shapeDrawable.setDither(false);
+        assertFalse(shapeDrawable.getDither());
+        assertEquals(shapeDrawable.getDither(), shapeDrawable.getPaint().isDither());
+    }
+
     public void testMutate() {
         // How to load a ShapeDrawable from resources.
     }