IllustrationTest.java revision 1e8fd1229a592e094929aa279482c7415954eedc
1/* 2 * Copyright (C) 2015 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 17package com.android.setupwizardlib.test; 18 19import android.graphics.Color; 20import android.graphics.drawable.ColorDrawable; 21import android.graphics.drawable.Drawable; 22import android.test.AndroidTestCase; 23import android.test.suitebuilder.annotation.SmallTest; 24import android.view.View; 25 26import com.android.setupwizardlib.view.Illustration; 27 28public class IllustrationTest extends AndroidTestCase { 29 30 @SmallTest 31 public void testWillDraw() { 32 final Illustration illustration = new Illustration(getContext()); 33 assertFalse("The illustration needs to be drawn", illustration.willNotDraw()); 34 } 35 36 @SmallTest 37 public void testAspectRatio() { 38 final Illustration illustration = new Illustration(getContext()); 39 illustration.setAspectRatio(3.0f); 40 final Drawable backgroundDrawable = new ColorDrawable(Color.RED); 41 final Drawable illustrationDrawable = new ColorDrawable(Color.BLUE); 42 illustration.setBackgroundDrawable(backgroundDrawable); 43 illustration.setIllustration(illustrationDrawable); 44 45 illustration.measure(View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY), 46 View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 47 // (300 / 3) round down to nearest mod 8 = 96 48 assertEquals("Top padding should be 96", 96, illustration.getPaddingTop()); 49 } 50} 51