1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.graphics.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertTrue; 22 23 import android.graphics.Bitmap; 24 import android.graphics.BitmapShader; 25 import android.graphics.Color; 26 import android.graphics.Matrix; 27 import android.graphics.Shader; 28 import android.support.test.filters.SmallTest; 29 import android.support.test.runner.AndroidJUnit4; 30 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 @SmallTest 35 @RunWith(AndroidJUnit4.class) 36 public class ShaderTest { 37 @Test 38 public void testConstructor() { 39 new Shader(); 40 } 41 42 @Test 43 public void testAccessLocalMatrix() { 44 int width = 80; 45 int height = 120; 46 int[] color = new int[width * height]; 47 Bitmap bitmap = Bitmap.createBitmap(color, width, height, Bitmap.Config.RGB_565); 48 49 Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); 50 Matrix m = new Matrix(); 51 52 shader.setLocalMatrix(m); 53 assertFalse(shader.getLocalMatrix(m)); 54 55 shader.setLocalMatrix(null); 56 assertFalse(shader.getLocalMatrix(m)); 57 } 58 59 @Test 60 public void testMutateBaseObject() { 61 Shader shader = new Shader(); 62 shader.setLocalMatrix(null); 63 } 64 65 @Test 66 public void testGetSetLocalMatrix() { 67 Matrix skew10x20 = new Matrix(); 68 skew10x20.setSkew(10, 20); 69 70 Matrix scale2x3 = new Matrix(); 71 scale2x3.setScale(2, 3); 72 73 // setup shader 74 Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.RGB_565); 75 bitmap.eraseColor(Color.BLUE); 76 Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); 77 78 // get null 79 shader.setLocalMatrix(null); 80 Matrix paramMatrix = new Matrix(skew10x20); 81 assertFalse("shader should have no matrix set", shader.getLocalMatrix(paramMatrix)); 82 assertEquals("matrix param not modified when no matrix set", skew10x20, paramMatrix); 83 84 // get nonnull 85 shader.setLocalMatrix(scale2x3); 86 assertTrue("shader should have matrix set", shader.getLocalMatrix(paramMatrix)); 87 assertEquals("param matrix should be updated", scale2x3, paramMatrix); 88 } 89 90 @Test(expected = NullPointerException.class) 91 public void testGetWithNullParam() { 92 Shader shader = new Shader(); 93 Matrix matrix = new Matrix(); 94 matrix.setScale(10, 10); 95 shader.setLocalMatrix(matrix); 96 97 shader.getLocalMatrix(null); 98 } 99 } 100