blob: 504a4eca29a2bf93681caed321fb681d5b7a6ad0 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Nguyen1d3165f2010-01-12 13:26:10 -080017package android.view;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.test.ActivityInstrumentationTestCase;
Tadashi G. Takaokab4470f22019-01-15 18:29:15 +090020
21import androidx.test.annotation.UiThreadTest;
22import androidx.test.filters.MediumTest;
23
24import com.android.frameworks.coretests.R;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26public class ViewStubTest extends ActivityInstrumentationTestCase<StubbedView> {
27 public ViewStubTest() {
Neal Nguyen1d3165f2010-01-12 13:26:10 -080028 super("com.android.frameworks.coretests", StubbedView.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029 }
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}