• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.net.wifi;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.net.MacAddress;
22 import android.os.Parcel;
23 
24 import androidx.test.filters.SmallTest;
25 
26 import com.android.modules.utils.build.SdkLevel;
27 
28 import org.junit.Test;
29 
30 /**
31  * Unit tests for {@link android.net.wifi.SoftApInfo}.
32  */
33 @SmallTest
34 public class SoftApInfoTest {
35     private static final String TEST_AP_INSTANCE = "wlan1";
36     private static final int TEST_FREQUENCY = 2412;
37     private static final int TEST_BANDWIDTH = SoftApInfo.CHANNEL_WIDTH_20MHZ;
38     private static final int TEST_WIFI_STANDARD = ScanResult.WIFI_STANDARD_LEGACY;
39     private static final MacAddress TEST_AP_MAC = MacAddress.fromString("aa:bb:cc:dd:ee:ff");
40     private static final long TEST_SHUTDOWN_TIMEOUT_MILLIS = 100_000;
41     /**
42      * Verifies copy constructor.
43      */
44     @Test
testCopyOperator()45     public void testCopyOperator() throws Exception {
46         SoftApInfo info = new SoftApInfo();
47         info.setFrequency(TEST_FREQUENCY);
48         info.setBandwidth(TEST_BANDWIDTH);
49         info.setBssid(TEST_AP_MAC);
50         info.setWifiStandard(TEST_WIFI_STANDARD);
51         info.setApInstanceIdentifier(TEST_AP_INSTANCE);
52 
53 
54         SoftApInfo copiedInfo = new SoftApInfo(info);
55 
56         assertEquals(info, copiedInfo);
57         assertEquals(info.hashCode(), copiedInfo.hashCode());
58     }
59 
60     /**
61      * Verifies parcel serialization/deserialization.
62      */
63     @Test
testParcelOperation()64     public void testParcelOperation() throws Exception {
65         SoftApInfo info = new SoftApInfo();
66         info.setFrequency(TEST_FREQUENCY);
67         info.setBandwidth(TEST_BANDWIDTH);
68         info.setBssid(TEST_AP_MAC);
69         info.setWifiStandard(TEST_WIFI_STANDARD);
70         info.setApInstanceIdentifier(TEST_AP_INSTANCE);
71 
72         Parcel parcelW = Parcel.obtain();
73         info.writeToParcel(parcelW, 0);
74         byte[] bytes = parcelW.marshall();
75         parcelW.recycle();
76 
77         Parcel parcelR = Parcel.obtain();
78         parcelR.unmarshall(bytes, 0, bytes.length);
79         parcelR.setDataPosition(0);
80         SoftApInfo fromParcel = SoftApInfo.CREATOR.createFromParcel(parcelR);
81 
82         assertEquals(info, fromParcel);
83         assertEquals(info.hashCode(), fromParcel.hashCode());
84     }
85 
86 
87     /**
88      * Verifies the initial value same as expected.
89      */
90     @Test
testInitialValue()91     public void testInitialValue() throws Exception {
92         SoftApInfo info = new SoftApInfo();
93         assertEquals(info.getFrequency(), 0);
94         assertEquals(info.getBandwidth(), SoftApInfo.CHANNEL_WIDTH_INVALID);
95         if (SdkLevel.isAtLeastS()) {
96             assertEquals(info.getBssid(), null);
97             assertEquals(info.getWifiStandard(), ScanResult.WIFI_STANDARD_UNKNOWN);
98             assertEquals(info.getApInstanceIdentifier(), null);
99         }
100     }
101 
102     /**
103      * Verifies the set/get method same as expected.
104      */
105     @Test
testGetXXXAlignedWithSetXXX()106     public void testGetXXXAlignedWithSetXXX() throws Exception {
107         SoftApInfo info = new SoftApInfo();
108         info.setFrequency(TEST_FREQUENCY);
109         info.setBandwidth(TEST_BANDWIDTH);
110         info.setBssid(TEST_AP_MAC);
111         info.setWifiStandard(TEST_WIFI_STANDARD);
112         info.setApInstanceIdentifier(TEST_AP_INSTANCE);
113         info.setAutoShutdownTimeoutMillis(TEST_SHUTDOWN_TIMEOUT_MILLIS);
114         assertEquals(info.getFrequency(), TEST_FREQUENCY);
115         assertEquals(info.getBandwidth(), TEST_BANDWIDTH);
116         if (SdkLevel.isAtLeastS()) {
117             assertEquals(info.getBssid(), TEST_AP_MAC);
118             assertEquals(info.getWifiStandard(), TEST_WIFI_STANDARD);
119             assertEquals(info.getApInstanceIdentifier(), TEST_AP_INSTANCE);
120         }
121         assertEquals(info.getAutoShutdownTimeoutMillis(), TEST_SHUTDOWN_TIMEOUT_MILLIS);
122     }
123 
124 }
125