Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2017 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 com.android.setupwizardlib.view;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 import static org.robolectric.RuntimeEnvironment.application;
     21 
     22 import android.view.View;
     23 import android.view.View.MeasureSpec;
     24 
     25 import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner;
     26 
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 import org.robolectric.Robolectric;
     30 import org.robolectric.annotation.Config;
     31 
     32 @RunWith(SuwLibRobolectricTestRunner.class)
     33 @Config(sdk = {Config.OLDEST_SDK, Config.NEWEST_SDK})
     34 public class FillContentLayoutTest {
     35 
     36     @Test
     37     public void testMeasureMinSize() {
     38         FillContentLayout layout = new FillContentLayout(
     39                 application,
     40                 Robolectric.buildAttributeSet()
     41                         .addAttribute(android.R.attr.minWidth, "123dp")
     42                         .addAttribute(android.R.attr.minHeight, "123dp")
     43                         .build());
     44         layout.measure(
     45                 MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
     46                 MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
     47 
     48         assertEquals(123, layout.getMeasuredWidth());
     49         assertEquals(123, layout.getMeasuredHeight());
     50     }
     51 
     52     @Test
     53     public void testMeasureChildIsSmallerThanMaxSize() {
     54         View child = new View(application);
     55         FillContentLayout layout = new FillContentLayout(
     56                 application,
     57                 Robolectric.buildAttributeSet()
     58                         .addAttribute(android.R.attr.maxWidth, "123dp")
     59                         .addAttribute(android.R.attr.maxHeight, "123dp")
     60                         .build());
     61         layout.addView(child);
     62         layout.measure(
     63                 MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY),
     64                 MeasureSpec.makeMeasureSpec(300, MeasureSpec.EXACTLY));
     65 
     66         assertEquals(123, child.getMeasuredWidth());
     67         assertEquals(123, child.getMeasuredHeight());
     68     }
     69 
     70     @Test
     71     public void testMeasureChildIsSmallerThanParent() {
     72         View child = new View(application);
     73         FillContentLayout layout = new FillContentLayout(
     74                 application,
     75                 Robolectric.buildAttributeSet()
     76                         .addAttribute(android.R.attr.maxWidth, "123dp")
     77                         .addAttribute(android.R.attr.maxHeight, "123dp")
     78                         .build());
     79         layout.addView(child);
     80         layout.measure(
     81                 MeasureSpec.makeMeasureSpec(88, MeasureSpec.EXACTLY),
     82                 MeasureSpec.makeMeasureSpec(88, MeasureSpec.EXACTLY));
     83 
     84         assertEquals(88, child.getMeasuredWidth());
     85         assertEquals(88, child.getMeasuredHeight());
     86     }
     87 }
     88