• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.settings.wifi;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.spy;
22 
23 import android.content.Context;
24 import android.net.wifi.WifiConfiguration;
25 import android.os.Bundle;
26 
27 import com.android.settingslib.wifi.AccessPoint;
28 
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.RobolectricTestRunner;
32 import org.robolectric.RuntimeEnvironment;
33 
34 @RunWith(RobolectricTestRunner.class)
35 public class WifiUtilsTest {
36 
37     @Test
testSSID()38     public void testSSID() {
39         assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
40         assertThat(WifiUtils.isSSIDTooLong("☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎")).isTrue();
41 
42         assertThat(WifiUtils.isSSIDTooShort("123")).isFalse();
43         assertThat(WifiUtils.isSSIDTooShort("")).isTrue();
44     }
45 
46     @Test
testPassword()47     public void testPassword() {
48         final String longPassword = "123456789012345678901234567890"
49                 + "1234567890123456789012345678901234567890";
50         assertThat(WifiUtils.isHotspotWpa2PasswordValid("123")).isFalse();
51         assertThat(WifiUtils.isHotspotWpa2PasswordValid("12345678")).isTrue();
52         assertThat(WifiUtils.isHotspotWpa2PasswordValid("1234567890")).isTrue();
53         assertThat(WifiUtils.isHotspotWpa2PasswordValid(longPassword)).isFalse();
54         assertThat(WifiUtils.isHotspotWpa2PasswordValid("")).isFalse();
55         assertThat(WifiUtils.isHotspotWpa2PasswordValid("€¥£")).isFalse();
56     }
57 
58     @Test
getWifiConfigByAccessPoint_shouldReturnCorrectConfig()59     public void getWifiConfigByAccessPoint_shouldReturnCorrectConfig() {
60         String testSSID = "WifiUtilsTest";
61         Bundle bundle = new Bundle();
62         bundle.putString("key_ssid", testSSID);
63         Context context = spy(RuntimeEnvironment.application);
64         AccessPoint accessPoint = new AccessPoint(context, bundle);
65 
66         WifiConfiguration config = WifiUtils.getWifiConfig(accessPoint, null, null);
67 
68         assertThat(config).isNotNull();
69         assertThat(config.SSID).isEqualTo(AccessPoint.convertToQuotedString(testSSID));
70     }
71 
72     @Test(expected = IllegalArgumentException.class)
getWifiConfigWithNullInput_ThrowIllegalArgumentException()73     public void getWifiConfigWithNullInput_ThrowIllegalArgumentException() {
74         WifiConfiguration config = WifiUtils.getWifiConfig(null, null, null);
75     }
76 }
77