Home | History | Annotate | Download | only in unit
      1 /*
      2  * Copyright (C) 2010 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 com.android.connectivitymanagertest.unit;
     18 
     19 import android.content.Context;
     20 import android.net.wifi.WifiManager;
     21 import android.net.wifi.WifiConfiguration;
     22 import android.net.wifi.WifiConfiguration.KeyMgmt;
     23 
     24 import android.test.suitebuilder.annotation.LargeTest;
     25 import android.test.AndroidTestCase;
     26 
     27 import android.util.Log;
     28 
     29 /**
     30  * Test Wifi soft AP configuration
     31  */
     32 public class WifiSoftAPTest extends AndroidTestCase {
     33 
     34     private WifiManager mWifiManager;
     35     private WifiConfiguration mWifiConfig = null;
     36     private final String TAG = "WifiSoftAPTest";
     37     private final int DURATION = 10000;
     38 
     39     @Override
     40     protected void setUp() throws Exception {
     41         super.setUp();
     42         mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
     43         assertNotNull(mWifiManager);
     44         assertTrue(mWifiManager.setWifiApEnabled(null, true));
     45         mWifiConfig = mWifiManager.getWifiApConfiguration();
     46         if (mWifiConfig != null) {
     47             Log.v(TAG, "mWifiConfig is " + mWifiConfig.toString());
     48         } else {
     49             Log.v(TAG, "mWifiConfig is null.");
     50         }
     51     }
     52 
     53     @Override
     54     protected void tearDown() throws Exception {
     55         Log.v(TAG, "turn off wifi tethering");
     56         mWifiManager.setWifiApEnabled(null, false);
     57         super.tearDown();
     58     }
     59 
     60     // Test case 1: Test the soft AP SSID with letters
     61     @LargeTest
     62     public void testApSsidWithAlphabet() {
     63         WifiConfiguration config = new WifiConfiguration();
     64         config.SSID = "abcdefghijklmnopqrstuvwxyz";
     65         config.allowedKeyManagement.set(KeyMgmt.NONE);
     66         mWifiConfig = config;
     67         assertTrue(mWifiManager.setWifiApEnabled(mWifiConfig, true));
     68         try {
     69             Thread.sleep(DURATION);
     70         } catch (InterruptedException e) {
     71             Log.v(TAG, "exception " + e.getStackTrace());
     72             assertFalse(true);
     73         }
     74         assertNotNull(mWifiManager.getWifiApConfiguration());
     75         assertEquals("wifi AP state is not enabled", WifiManager.WIFI_AP_STATE_ENABLED,
     76                      mWifiManager.getWifiApState());
     77     }
     78 }
     79