Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2012 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.preference2.cts;
     18 
     19 import 	android.content.res.Resources;
     20 import android.preference.SwitchPreference;
     21 import android.test.ActivityInstrumentationTestCase2;
     22 
     23 import android.preference2.cts.R;
     24 
     25 public class SwitchPreferenceTest
     26         extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> {
     27 
     28     private PreferenceFromCodeActivity mActivity;
     29     private SwitchPreference mSwitchPref;
     30     private Resources mResources;
     31 
     32     public SwitchPreferenceTest() {
     33         super(PreferenceFromCodeActivity.class);
     34     }
     35 
     36     @Override
     37     protected void setUp() throws Exception {
     38         super.setUp();
     39         mActivity = getActivity();
     40         mSwitchPref = (SwitchPreference) mActivity.findPreference(
     41                 "switch_preference");
     42         mResources = mActivity.getResources();
     43     }
     44 
     45     public void testGetTitle() {
     46         String title = (String) mSwitchPref.getTitle();
     47         String titleExp = mResources.getString(R.string.title_switch_preference);
     48         assertEquals(titleExp, title);
     49     }
     50 
     51     public void testGetSummary() {
     52         String summary = (String) mSwitchPref.getSummary();
     53         String summaryExp = mResources.getString(R.string.summary_switch_preference);
     54         assertEquals(summaryExp, summary);
     55     }
     56 
     57     public void testGetSummaryOn() {
     58         String summaryOn = (String) mSwitchPref.getSummaryOn();
     59         String summaryOnExp = mResources.getString(
     60                 R.string.summary_on_switch_preference);
     61         assertEquals(summaryOnExp, summaryOn);
     62     }
     63 
     64     public void testSummaryOff() {
     65         String summaryOff = (String) mSwitchPref.getSummaryOff();
     66         String summaryOffExp = mResources.getString(
     67                 R.string.summary_off_switch_preference);
     68         assertEquals(summaryOffExp, summaryOff);
     69     }
     70 
     71     public void testSetSwitchTextOff_One() throws Throwable {
     72         final CharSequence switchOff = "SwitchedOff";
     73         this.runTestOnUiThread(new Runnable() {
     74             public void run() {
     75                 mSwitchPref.setSwitchTextOff(switchOff);
     76             }
     77         });
     78         CharSequence switchOffExp = mSwitchPref.getSwitchTextOff();
     79         assertEquals(switchOffExp, switchOff);
     80     }
     81 
     82     public void testSetSwitchTextOff_Two() throws Throwable {
     83         final CharSequence switchOffExp = mResources.getString(
     84                 R.string.switchtext_off);
     85         CharSequence switchOff = mSwitchPref.getSwitchTextOff();
     86         assertEquals(switchOffExp, switchOff);
     87     }
     88 
     89     public void testSetSwitchTextOn_One() throws Throwable {
     90         final CharSequence switchOn = "SwitchedOff";
     91         this.runTestOnUiThread(new Runnable() {
     92             public void run() {
     93                 mSwitchPref.setSwitchTextOn(switchOn);
     94             }
     95         });
     96         CharSequence switchOnExp = mSwitchPref.getSwitchTextOn();
     97         assertEquals(switchOnExp, switchOn);
     98     }
     99 
    100     public void testSetSwitchTextOn_Two() throws Throwable {
    101         final CharSequence switchOnExp = mResources.getString(
    102                 R.string.switchtext_on);
    103 
    104         CharSequence switchOn = mSwitchPref.getSwitchTextOn();
    105         assertEquals(switchOnExp, switchOn);
    106     }
    107 }
    108