The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 17 | package android.view; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.test.ActivityInstrumentationTestCase; |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 20 | |
| 21 | import androidx.test.annotation.UiThreadTest; |
| 22 | import androidx.test.filters.MediumTest; |
| 23 | |
| 24 | import com.android.frameworks.coretests.R; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| 26 | public class ViewStubTest extends ActivityInstrumentationTestCase<StubbedView> { |
| 27 | public ViewStubTest() { |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 28 | super("com.android.frameworks.coretests", StubbedView.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | @Override |
| 32 | public void setUp() throws Exception { |
| 33 | super.setUp(); |
| 34 | } |
| 35 | |
| 36 | @MediumTest |
| 37 | public void testStubbed() throws Exception { |
| 38 | final StubbedView activity = getActivity(); |
| 39 | |
| 40 | final View stub = activity.findViewById(R.id.viewStub); |
| 41 | assertNotNull("The ViewStub does not exist", stub); |
| 42 | } |
| 43 | |
| 44 | @UiThreadTest |
| 45 | @MediumTest |
| 46 | public void testInflated() throws Exception { |
| 47 | final StubbedView activity = getActivity(); |
| 48 | |
| 49 | final ViewStub stub = (ViewStub) activity.findViewById(R.id.viewStub); |
| 50 | final View swapped = stub.inflate(); |
| 51 | |
| 52 | assertNotNull("The inflated view is null", swapped); |
| 53 | } |
| 54 | |
| 55 | @UiThreadTest |
| 56 | @MediumTest |
| 57 | public void testInflatedId() throws Exception { |
| 58 | final StubbedView activity = getActivity(); |
| 59 | |
| 60 | final ViewStub stub = (ViewStub) activity.findViewById(R.id.viewStubWithId); |
| 61 | final View swapped = stub.inflate(); |
| 62 | |
| 63 | assertNotNull("The inflated view is null", swapped); |
| 64 | assertTrue("The inflated view has no id", swapped.getId() != View.NO_ID); |
| 65 | assertTrue("The inflated view has the wrong id", swapped.getId() == R.id.stub_inflated); |
| 66 | } |
| 67 | |
| 68 | @UiThreadTest |
| 69 | @MediumTest |
| 70 | public void testInflatedLayoutParams() throws Exception { |
| 71 | final StubbedView activity = getActivity(); |
| 72 | |
| 73 | final ViewStub stub = (ViewStub) activity.findViewById(R.id.viewStubWithId); |
| 74 | final View swapped = stub.inflate(); |
| 75 | |
| 76 | assertNotNull("The inflated view is null", swapped); |
| 77 | |
| 78 | assertEquals("Both stub and inflated should same width", |
| 79 | stub.getLayoutParams().width, swapped.getLayoutParams().width); |
| 80 | assertEquals("Both stub and inflated should same height", |
| 81 | stub.getLayoutParams().height, swapped.getLayoutParams().height); |
| 82 | } |
| 83 | } |