1 package com.xtremelabs.robolectric.shadows; 2 3 import static org.junit.Assert.assertEquals; 4 5 import org.junit.Test; 6 import org.junit.runner.RunWith; 7 8 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 9 10 import android.view.View; 11 import android.view.View.MeasureSpec; 12 13 @RunWith(WithTestDefaultsRunner.class) 14 public class ViewMeasureSpecTest { 15 16 @Test testMode()17 public void testMode() throws Exception { 18 assertEquals(View.MeasureSpec.UNSPECIFIED, 19 MeasureSpec.getMode(MeasureSpec.makeMeasureSpec(512, View.MeasureSpec.UNSPECIFIED))); 20 assertEquals(View.MeasureSpec.EXACTLY, 21 MeasureSpec.getMode(MeasureSpec.makeMeasureSpec(600, View.MeasureSpec.EXACTLY))); 22 assertEquals(View.MeasureSpec.AT_MOST, 23 MeasureSpec.getMode(MeasureSpec.makeMeasureSpec(320, View.MeasureSpec.AT_MOST))); 24 } 25 26 @Test testSize()27 public void testSize() throws Exception { 28 assertEquals(512, 29 MeasureSpec.getSize(MeasureSpec.makeMeasureSpec(512, View.MeasureSpec.UNSPECIFIED))); 30 assertEquals(800, 31 MeasureSpec.getSize(MeasureSpec.makeMeasureSpec(800, View.MeasureSpec.EXACTLY))); 32 assertEquals(1280, 33 MeasureSpec.getSize(MeasureSpec.makeMeasureSpec(1280, View.MeasureSpec.AT_MOST))); 34 } 35 36 @Test testToString()37 public void testToString() throws Exception { 38 assertEquals("MeasureSpec: UNSPECIFIED 512", 39 MeasureSpec.toString(MeasureSpec.makeMeasureSpec(512, View.MeasureSpec.UNSPECIFIED))); 40 assertEquals("MeasureSpec: EXACTLY 480", 41 MeasureSpec.toString(MeasureSpec.makeMeasureSpec(480, View.MeasureSpec.EXACTLY))); 42 assertEquals("MeasureSpec: AT_MOST 960", 43 MeasureSpec.toString(MeasureSpec.makeMeasureSpec(960, View.MeasureSpec.AT_MOST))); 44 } 45 46 } 47