11e8fd1229a592e094929aa279482c7415954eedcMaurice Lam/*
21e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * Copyright (C) 2015 The Android Open Source Project
31e8fd1229a592e094929aa279482c7415954eedcMaurice Lam *
41e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
51e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * you may not use this file except in compliance with the License.
61e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * You may obtain a copy of the License at
71e8fd1229a592e094929aa279482c7415954eedcMaurice Lam *
81e8fd1229a592e094929aa279482c7415954eedcMaurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
91e8fd1229a592e094929aa279482c7415954eedcMaurice Lam *
101e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * Unless required by applicable law or agreed to in writing, software
111e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
121e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * See the License for the specific language governing permissions and
141e8fd1229a592e094929aa279482c7415954eedcMaurice Lam * limitations under the License.
151e8fd1229a592e094929aa279482c7415954eedcMaurice Lam */
161e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
171e8fd1229a592e094929aa279482c7415954eedcMaurice Lampackage com.android.setupwizardlib.test;
181e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
192614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertEquals;
202614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertFalse;
212614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam
2239619ac964ffe6b8737f2a128122bd3f84e75998Maurice Lamimport android.content.Context;
231e8fd1229a592e094929aa279482c7415954eedcMaurice Lamimport android.graphics.Color;
241e8fd1229a592e094929aa279482c7415954eedcMaurice Lamimport android.graphics.drawable.ColorDrawable;
251e8fd1229a592e094929aa279482c7415954eedcMaurice Lamimport android.graphics.drawable.Drawable;
262614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport android.support.test.InstrumentationRegistry;
272614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport android.support.test.filters.SmallTest;
282614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport android.support.test.runner.AndroidJUnit4;
291e8fd1229a592e094929aa279482c7415954eedcMaurice Lamimport android.view.View;
301e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
311e8fd1229a592e094929aa279482c7415954eedcMaurice Lamimport com.android.setupwizardlib.view.Illustration;
321e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
332614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport org.junit.Test;
342614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport org.junit.runner.RunWith;
352614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam
362614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam@RunWith(AndroidJUnit4.class)
372614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam@SmallTest
382614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lampublic class IllustrationTest {
391e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
402614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam    @Test
411e8fd1229a592e094929aa279482c7415954eedcMaurice Lam    public void testWillDraw() {
422614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam        final Illustration illustration = new Illustration(InstrumentationRegistry.getContext());
431e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        assertFalse("The illustration needs to be drawn", illustration.willNotDraw());
441e8fd1229a592e094929aa279482c7415954eedcMaurice Lam    }
451e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
462614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam    @Test
471e8fd1229a592e094929aa279482c7415954eedcMaurice Lam    public void testAspectRatio() {
482614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam        final Context context = InstrumentationRegistry.getContext();
4939619ac964ffe6b8737f2a128122bd3f84e75998Maurice Lam        // Force the context to be xhdpi
5039619ac964ffe6b8737f2a128122bd3f84e75998Maurice Lam        context.getResources().getDisplayMetrics().density = 2.0f;
5139619ac964ffe6b8737f2a128122bd3f84e75998Maurice Lam
5239619ac964ffe6b8737f2a128122bd3f84e75998Maurice Lam        final Illustration illustration = new Illustration(context);
531e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        illustration.setAspectRatio(3.0f);
541e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        final Drawable backgroundDrawable = new ColorDrawable(Color.RED);
551e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        final Drawable illustrationDrawable = new ColorDrawable(Color.BLUE);
561e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        illustration.setBackgroundDrawable(backgroundDrawable);
571e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        illustration.setIllustration(illustrationDrawable);
581e8fd1229a592e094929aa279482c7415954eedcMaurice Lam
591e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        illustration.measure(View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY),
601e8fd1229a592e094929aa279482c7415954eedcMaurice Lam                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
6139619ac964ffe6b8737f2a128122bd3f84e75998Maurice Lam        // (300px / 3) round down to nearest mod (8dp = 16px) = 96px
621e8fd1229a592e094929aa279482c7415954eedcMaurice Lam        assertEquals("Top padding should be 96", 96, illustration.getPaddingTop());
631e8fd1229a592e094929aa279482c7415954eedcMaurice Lam    }
641e8fd1229a592e094929aa279482c7415954eedcMaurice Lam}
65