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.os.Parcel;
22 
23 import androidx.test.filters.SmallTest;
24 
25 import org.junit.Test;
26 
27 /**
28  * Unit tests for {@link android.net.wifi.SoftApCapability}.
29  */
30 @SmallTest
31 public class SoftApCapabilityTest {
32 
33     private static final String DRIVER_COUNTRY_CODE = "US";
34 
35     /**
36      * Verifies copy constructor.
37      */
38     @Test
testCopyOperator()39     public void testCopyOperator() throws Exception {
40         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
41                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
42         int[] testSupported2Glist = {1, 2, 3, 4};
43         int[] testSupported5Glist = {36, 149};
44         int[] testSupported60Glist = {1, 2};
45         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
46         capability.setCountryCode(DRIVER_COUNTRY_CODE);
47         capability.setMaxSupportedClients(10);
48         capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist);
49         capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist);
50         capability.setSupportedChannelList(SoftApConfiguration.BAND_60GHZ, testSupported60Glist);
51 
52         SoftApCapability copiedCapability = new SoftApCapability(capability);
53 
54         assertEquals(capability, copiedCapability);
55         assertEquals(capability.hashCode(), copiedCapability.hashCode());
56     }
57 
58     /**
59      * Verifies parcel serialization/deserialization.
60      */
61     @Test
testParcelOperation()62     public void testParcelOperation() throws Exception {
63         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
64                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
65         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
66         capability.setMaxSupportedClients(10);
67         int[] testSupported2Glist = {1, 2, 3, 4};
68         int[] testSupported5Glist = {36, 149};
69         int[] testSupported60Glist = {1, 2};
70 
71         capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist);
72         capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist);
73         capability.setSupportedChannelList(SoftApConfiguration.BAND_60GHZ, testSupported60Glist);
74 
75         capability.setCountryCode(DRIVER_COUNTRY_CODE);
76 
77         Parcel parcelW = Parcel.obtain();
78         capability.writeToParcel(parcelW, 0);
79         byte[] bytes = parcelW.marshall();
80         parcelW.recycle();
81 
82         Parcel parcelR = Parcel.obtain();
83         parcelR.unmarshall(bytes, 0, bytes.length);
84         parcelR.setDataPosition(0);
85         SoftApCapability fromParcel = SoftApCapability.CREATOR.createFromParcel(parcelR);
86 
87         assertEquals(capability, fromParcel);
88         assertEquals(capability.hashCode(), fromParcel.hashCode());
89     }
90 
91     @Test(expected = IllegalArgumentException.class)
testSetSupportedChannelListWithInvalidBand()92     public void testSetSupportedChannelListWithInvalidBand() {
93         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
94                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
95         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
96         capability.setSupportedChannelList(
97                 SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, new int[0]);
98 
99     }
100 
101     @Test(expected = IllegalArgumentException.class)
testGetSupportedChannelListWithInvalidBand()102     public void testGetSupportedChannelListWithInvalidBand() {
103         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
104                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
105         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
106         capability.getSupportedChannelList(
107                 SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ);
108     }
109 }
110