1 /* 2 * Copyright (C) 2014 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 package android.uirendering.cts.testclasses; 17 18 import android.graphics.Point; 19 import com.android.cts.uirendering.R; 20 21 import android.graphics.Canvas; 22 import android.graphics.Color; 23 import android.graphics.Rect; 24 import android.test.suitebuilder.annotation.SmallTest; 25 import android.uirendering.cts.bitmapcomparers.BitmapComparer; 26 import android.uirendering.cts.bitmapcomparers.MSSIMComparer; 27 import android.uirendering.cts.bitmapverifiers.RectVerifier; 28 import android.uirendering.cts.testinfrastructure.ActivityTestBase; 29 import android.uirendering.cts.testinfrastructure.CanvasClient; 30 import android.uirendering.cts.testinfrastructure.ViewInitializer; 31 import android.view.View; 32 33 public class InfrastructureTests extends ActivityTestBase { 34 35 @SmallTest testScreenshot()36 public void testScreenshot() { 37 for (int i = 0 ; i < 500 ; i ++) { 38 takeScreenshot(new Point()); 39 System.gc(); 40 } 41 } 42 43 /** 44 * Ensure that both render paths are producing independent output. We do this 45 * by verifying that two paths that should render differently *do* render 46 * differently. 47 */ 48 @SmallTest testRenderSpecIsolation()49 public void testRenderSpecIsolation() { 50 CanvasClient canvasClient = new CanvasClient() { 51 @Override 52 public void draw(Canvas canvas, int width, int height) { 53 canvas.drawColor(canvas.isHardwareAccelerated() ? Color.BLACK : Color.WHITE); 54 } 55 }; 56 BitmapComparer inverseComparer = new BitmapComparer() { 57 @Override 58 public boolean verifySame(int[] ideal, int[] given, int offset, int stride, int width, 59 int height) { 60 61 // Return true if the images aren't even 10% similar. They should be completely 62 // different, since they should both be completely different colors. 63 final float threshold = 0.1f; 64 return !(new MSSIMComparer(threshold)).verifySame(ideal, given, offset, stride, 65 width, height); 66 } 67 }; 68 createTest() 69 .addCanvasClient(canvasClient) 70 .runWithComparer(inverseComparer); 71 } 72 73 @SmallTest testViewInitializer()74 public void testViewInitializer() { 75 final Rect clipRect = new Rect(0, 0, 50, 50); 76 ViewInitializer viewInitializer = new ViewInitializer() { 77 @Override 78 public void initializeView(View view) { 79 view.setClipBounds(clipRect); 80 } 81 }; 82 createTest() 83 .addLayout(R.layout.simple_red_layout, viewInitializer) 84 .runWithVerifier(new RectVerifier(Color.WHITE, Color.RED, clipRect)); 85 } 86 } 87