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.content.Context; 20import android.graphics.Color; 21import android.graphics.drawable.ColorDrawable; 22import android.graphics.drawable.Drawable; 23import android.test.AndroidTestCase; 24import android.test.suitebuilder.annotation.SmallTest; 25import android.view.View; 26 27import com.android.setupwizardlib.view.Illustration; 28 29public class IllustrationTest extends AndroidTestCase { 30 31 @SmallTest 32 public void testWillDraw() { 33 final Illustration illustration = new Illustration(getContext()); 34 assertFalse("The illustration needs to be drawn", illustration.willNotDraw()); 35 } 36 37 @SmallTest 38 public void testAspectRatio() { 39 final Context context = getContext(); 40 // Force the context to be xhdpi 41 context.getResources().getDisplayMetrics().density = 2.0f; 42 43 final Illustration illustration = new Illustration(context); 44 illustration.setAspectRatio(3.0f); 45 final Drawable backgroundDrawable = new ColorDrawable(Color.RED); 46 final Drawable illustrationDrawable = new ColorDrawable(Color.BLUE); 47 illustration.setBackgroundDrawable(backgroundDrawable); 48 illustration.setIllustration(illustrationDrawable); 49 50 illustration.measure(View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY), 51 View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 52 // (300px / 3) round down to nearest mod (8dp = 16px) = 96px 53 assertEquals("Top padding should be 96", 96, illustration.getPaddingTop()); 54 } 55} 56