OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / core / tests / coretests / src / android / widget / layout / linear / BaselineButtonsTest.java
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
17 package android.widget.layout.linear;
18
19 import android.app.Activity;
20 import android.test.ActivityInstrumentationTestCase;
21 import android.test.suitebuilder.annotation.MediumTest;
22 import android.view.View;
23 import android.widget.ImageButton;
24
25 import com.android.frameworks.coretests.R;
26 import android.widget.layout.linear.BaselineButtons;
27
28 public class BaselineButtonsTest extends ActivityInstrumentationTestCase<BaselineButtons> {
29     private View mCurrentTime;
30     private View mTotalTime;
31     private ImageButton mPrev;
32     private ImageButton mNext;
33     private ImageButton mPause;
34     private View mLayout;
35
36     public BaselineButtonsTest() {
37         super("com.android.frameworks.coretests", BaselineButtons.class);
38     }
39
40     @Override
41     protected void setUp() throws Exception {
42         super.setUp();
43
44         final Activity activity = getActivity();
45         mCurrentTime = activity.findViewById(R.id.currenttime);
46         mTotalTime = activity.findViewById(R.id.totaltime);
47         mPrev = (ImageButton) activity.findViewById(R.id.prev);
48         mNext = (ImageButton) activity.findViewById(R.id.next);
49         mPause = (ImageButton) activity.findViewById(R.id.pause);
50         mLayout = activity.findViewById(R.id.layout);
51     }
52
53     @MediumTest
54     public void testPreconditions() {
55         assertNotNull(mCurrentTime);    
56         assertNotNull(mTotalTime);  
57         assertNotNull(mPrev);  
58         assertNotNull(mNext);  
59         assertNotNull(mPause);  
60         assertNotNull(mLayout);  
61     }
62     
63     @MediumTest
64     public void testLayout() {
65         int pauseHeight =  Math.max(mPause.getDrawable().getIntrinsicHeight()
66                 + mPause.getPaddingTop() + mPause.getPaddingBottom(),
67                 mPause.getBackground().getMinimumHeight());
68         int prevHeight = Math.max(mPrev.getDrawable().getIntrinsicHeight() + mPrev.getPaddingTop()
69                 + mPrev.getPaddingBottom(),
70                 mPrev.getBackground().getMinimumHeight());
71         int nextHeight = Math.max(mNext.getDrawable().getIntrinsicHeight() + mNext.getPaddingTop()
72                 + mNext.getPaddingBottom(),
73                 mNext.getBackground().getMinimumHeight());
74         assertEquals("Layout incorrect height", pauseHeight, mLayout.getHeight()); 
75         assertEquals("Pause incorrect height", pauseHeight, mPause.getHeight()); 
76         assertEquals("Prev incorrect height", prevHeight, mPrev.getHeight()); 
77         assertEquals("Next incorrect height", nextHeight, mNext.getHeight()); 
78         assertEquals("Pause wrong top", 0, mPause.getTop()); 
79         assertEquals("Prev wrong top", (pauseHeight - prevHeight) / 2, mPrev.getTop());
80         assertEquals("Next wrong top", (pauseHeight - nextHeight) / 2, mNext.getTop());
81         assertEquals("CurrentTime wrong bottom",  pauseHeight, mCurrentTime.getBottom());
82         assertEquals("TotalTime wrong bottom",  pauseHeight, mTotalTime.getBottom());
83         assertTrue("CurrentTime too tall", mCurrentTime.getTop() > 0);
84         assertTrue("TotalTime too tall", mTotalTime.getTop() > 0);
85     }
86 }