1/* 2 * Copyright (C) 2007 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 android.view; 18 19import android.view.StubbedView; 20import com.android.frameworks.coretests.R; 21 22import android.test.ActivityInstrumentationTestCase; 23import android.test.suitebuilder.annotation.MediumTest; 24import android.test.UiThreadTest; 25import android.view.View; 26import android.view.ViewStub; 27 28public class ViewStubTest extends ActivityInstrumentationTestCase<StubbedView> { 29 public ViewStubTest() { 30 super("com.android.frameworks.coretests", StubbedView.class); 31 } 32 33 @Override 34 public void setUp() throws Exception { 35 super.setUp(); 36 } 37 38 @MediumTest 39 public void testStubbed() throws Exception { 40 final StubbedView activity = getActivity(); 41 42 final View stub = activity.findViewById(R.id.viewStub); 43 assertNotNull("The ViewStub does not exist", stub); 44 } 45 46 @UiThreadTest 47 @MediumTest 48 public void testInflated() throws Exception { 49 final StubbedView activity = getActivity(); 50 51 final ViewStub stub = (ViewStub) activity.findViewById(R.id.viewStub); 52 final View swapped = stub.inflate(); 53 54 assertNotNull("The inflated view is null", swapped); 55 } 56 57 @UiThreadTest 58 @MediumTest 59 public void testInflatedId() throws Exception { 60 final StubbedView activity = getActivity(); 61 62 final ViewStub stub = (ViewStub) activity.findViewById(R.id.viewStubWithId); 63 final View swapped = stub.inflate(); 64 65 assertNotNull("The inflated view is null", swapped); 66 assertTrue("The inflated view has no id", swapped.getId() != View.NO_ID); 67 assertTrue("The inflated view has the wrong id", swapped.getId() == R.id.stub_inflated); 68 } 69 70 @UiThreadTest 71 @MediumTest 72 public void testInflatedLayoutParams() throws Exception { 73 final StubbedView activity = getActivity(); 74 75 final ViewStub stub = (ViewStub) activity.findViewById(R.id.viewStubWithId); 76 final View swapped = stub.inflate(); 77 78 assertNotNull("The inflated view is null", swapped); 79 80 assertEquals("Both stub and inflated should same width", 81 stub.getLayoutParams().width, swapped.getLayoutParams().width); 82 assertEquals("Both stub and inflated should same height", 83 stub.getLayoutParams().height, swapped.getLayoutParams().height); 84 } 85} 86