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.p2p; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertTrue; 22 23 import android.os.Parcel; 24 25 import androidx.test.filters.SmallTest; 26 27 import org.junit.Test; 28 29 /** 30 * Unit test harness for {@link android.net.wifi.p2p.WifiP2pGroup} 31 */ 32 @SmallTest 33 public class WifiP2pGroupTest { 34 35 private static final String INTERFACE = "p2p-p2p0-3"; 36 private static final int NETWORK_ID = 9; 37 private static final String NETWORK_NAME = "DIRECT-xy-Hello"; 38 private static final String PASSPHRASE = "HelloWorld"; 39 private static final WifiP2pDevice GROUP_OWNER = new WifiP2pDevice("de:ad:be:ef:00:01"); 40 private static final int FREQUENCY = 5300; 41 private static final WifiP2pDevice CLIENT_1 = new WifiP2pDevice("aa:bb:cc:dd:ee:01"); 42 private static final WifiP2pDevice CLIENT_2 = new WifiP2pDevice("aa:bb:cc:dd:ee:02"); 43 44 /** 45 * Verify setter/getter functions. 46 */ 47 @Test testSetterGetter()48 public void testSetterGetter() throws Exception { 49 WifiP2pGroup group = new WifiP2pGroup(); 50 51 group.setInterface(INTERFACE); 52 group.setNetworkId(NETWORK_ID); 53 group.setNetworkName(NETWORK_NAME); 54 group.setPassphrase(PASSPHRASE); 55 group.setIsGroupOwner(false); 56 group.setOwner(GROUP_OWNER); 57 group.setFrequency(FREQUENCY); 58 group.addClient(CLIENT_1.deviceAddress); 59 group.addClient(CLIENT_2); 60 61 assertEquals(INTERFACE, group.getInterface()); 62 assertEquals(NETWORK_ID, group.getNetworkId()); 63 assertEquals(NETWORK_NAME, group.getNetworkName()); 64 assertEquals(PASSPHRASE, group.getPassphrase()); 65 assertFalse(group.isGroupOwner()); 66 assertEquals(GROUP_OWNER, group.getOwner()); 67 assertEquals(FREQUENCY, group.getFrequency()); 68 69 assertFalse(group.isClientListEmpty()); 70 assertTrue(group.contains(CLIENT_1)); 71 72 assertEquals(2, group.getClientList().size()); 73 74 group.removeClient(CLIENT_1); 75 group.removeClient(CLIENT_2.deviceAddress); 76 assertFalse(group.contains(CLIENT_1)); 77 assertTrue(group.isClientListEmpty()); 78 79 Parcel parcelW = Parcel.obtain(); 80 group.writeToParcel(parcelW, 0); 81 byte[] bytes = parcelW.marshall(); 82 parcelW.recycle(); 83 84 Parcel parcelR = Parcel.obtain(); 85 parcelR.unmarshall(bytes, 0, bytes.length); 86 parcelR.setDataPosition(0); 87 WifiP2pGroup fromParcel = WifiP2pGroup.CREATOR.createFromParcel(parcelR); 88 89 assertEquals(group.toString(), fromParcel.toString()); 90 91 } 92 } 93