Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2009 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.view.cts;
     18 
     19 import com.android.cts.stub.R;
     20 
     21 import dalvik.annotation.TestLevel;
     22 import dalvik.annotation.TestTargetClass;
     23 import dalvik.annotation.TestTargetNew;
     24 import dalvik.annotation.TestTargets;
     25 
     26 import android.app.Activity;
     27 import android.test.ActivityInstrumentationTestCase2;
     28 import android.test.UiThreadTest;
     29 import android.view.View;
     30 import android.widget.Button;
     31 import android.widget.EditText;
     32 import android.widget.TextView;
     33 
     34 @TestTargetClass(View.class)
     35 public class View_IdsTest extends ActivityInstrumentationTestCase2<UsingViewsStubActivity> {
     36     public View_IdsTest() {
     37         super("com.android.cts.stub", UsingViewsStubActivity.class);
     38     }
     39 
     40     @TestTargets({
     41         @TestTargetNew(
     42             level = TestLevel.COMPLETE,
     43             method = "setId",
     44             args = {int.class}
     45         ),
     46         @TestTargetNew(
     47             level = TestLevel.COMPLETE,
     48             method = "getId",
     49             args = {}
     50         )
     51     })
     52     @UiThreadTest
     53     public void testIds() {
     54         Activity activity = getActivity();
     55 
     56         EditText editText = (EditText) activity.findViewById(R.id.entry);
     57         Button buttonOk = (Button) activity.findViewById(R.id.ok);
     58         Button buttonCancel = (Button) activity.findViewById(R.id.cancel);
     59         TextView symbol = (TextView) activity.findViewById(R.id.symbolball);
     60         TextView warning = (TextView) activity.findViewById(R.id.warning);
     61 
     62         assertNotNull(editText);
     63         assertNotNull(buttonOk);
     64         assertNotNull(buttonCancel);
     65         assertNotNull(symbol);
     66         assertNotNull(warning);
     67 
     68         assertEquals(activity.getString(R.string.id_ok), buttonOk.getText().toString());
     69         assertEquals(activity.getString(R.string.id_cancel), buttonCancel.getText().toString());
     70 
     71         editText.setId(0x1111);
     72         assertEquals(0x1111, editText.getId());
     73         assertSame(editText, (EditText) activity.findViewById(0x1111));
     74 
     75         buttonCancel.setId(0x9999);
     76         assertEquals(0x9999, buttonCancel.getId());
     77         assertSame(buttonCancel, (Button) activity.findViewById(0x9999));
     78     }
     79 }
     80