• 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.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     /**
34      * Verifies copy constructor.
35      */
36     @Test
testCopyOperator()37     public void testCopyOperator() throws Exception {
38         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
39                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
40         int[] testSupported2Glist = {1, 2, 3, 4};
41         int[] testSupported5Glist = {36, 149};
42         int[] testSupported60Glist = {1, 2};
43         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
44         capability.setMaxSupportedClients(10);
45         capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist);
46         capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist);
47         capability.setSupportedChannelList(SoftApConfiguration.BAND_60GHZ, testSupported60Glist);
48 
49         SoftApCapability copiedCapability = new SoftApCapability(capability);
50 
51         assertEquals(capability, copiedCapability);
52         assertEquals(capability.hashCode(), copiedCapability.hashCode());
53     }
54 
55     /**
56      * Verifies parcel serialization/deserialization.
57      */
58     @Test
testParcelOperation()59     public void testParcelOperation() throws Exception {
60         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
61                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
62         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
63         capability.setMaxSupportedClients(10);
64         int[] testSupported2Glist = {1, 2, 3, 4};
65         int[] testSupported5Glist = {36, 149};
66         int[] testSupported60Glist = {1, 2};
67 
68         capability.setSupportedChannelList(SoftApConfiguration.BAND_2GHZ, testSupported2Glist);
69         capability.setSupportedChannelList(SoftApConfiguration.BAND_5GHZ, testSupported5Glist);
70         capability.setSupportedChannelList(SoftApConfiguration.BAND_60GHZ, testSupported60Glist);
71 
72         Parcel parcelW = Parcel.obtain();
73         capability.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         SoftApCapability fromParcel = SoftApCapability.CREATOR.createFromParcel(parcelR);
81 
82         assertEquals(capability, fromParcel);
83         assertEquals(capability.hashCode(), fromParcel.hashCode());
84     }
85 
86     @Test(expected = IllegalArgumentException.class)
testSetSupportedChannelListWithInvalidBand()87     public void testSetSupportedChannelListWithInvalidBand() {
88         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
89                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
90         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
91         capability.setSupportedChannelList(
92                 SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, new int[0]);
93 
94     }
95 
96     @Test(expected = IllegalArgumentException.class)
testGetSupportedChannelListWithInvalidBand()97     public void testGetSupportedChannelListWithInvalidBand() {
98         long testSoftApFeature = SoftApCapability.SOFTAP_FEATURE_CLIENT_FORCE_DISCONNECT
99                 | SoftApCapability.SOFTAP_FEATURE_ACS_OFFLOAD;
100         SoftApCapability capability = new SoftApCapability(testSoftApFeature);
101         capability.getSupportedChannelList(
102                 SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ);
103     }
104 }
105