Merge changes I7368f9b4,I7a6bec4f,I3eb9f7bc,I53d05702,I5cb6c9e0, ... into qt-dev
* changes: p2p: unit tests for WifiP2pWfdInfo p2p: unit tests for WifiP2pInfo p2p: unit tests for WifiP2pProvDiscEvent p2p: unit tests for WifiP2pDeviceList p2p: unit tests for WifiP2pConfig p2p: unit tests for P2P UPNP service discovery p2p: unit tests for P2P DNS SD service discovery p2p: unit tests for WifiP2pGroup p2p: unit tests for WifiP2pGroupList
This commit is contained in:
committed by
Android (Google) Code Review
commit
82ec520d1a
@@ -16,8 +16,11 @@
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -27,6 +30,8 @@ import org.junit.Test;
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pConfigTest {
|
||||
|
||||
private static final String DEVICE_ADDRESS = "aa:bb:cc:dd:ee:ff";
|
||||
/**
|
||||
* Check network name setter
|
||||
*/
|
||||
@@ -113,4 +118,43 @@ public class WifiP2pConfigTest {
|
||||
// expected exception.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
/*
|
||||
* Verify WifiP2pConfig basic operations
|
||||
*/
|
||||
public void testWifiP2pConfig() throws Exception {
|
||||
WifiP2pConfig config = new WifiP2pConfig();
|
||||
config.deviceAddress = DEVICE_ADDRESS;
|
||||
|
||||
WifiP2pConfig copiedConfig = new WifiP2pConfig(config);
|
||||
// no equals operator, use toString for comparison.
|
||||
assertEquals(config.toString(), copiedConfig.toString());
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
config.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
WifiP2pConfig configFromParcel = WifiP2pConfig.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
// no equals operator, use toString for comparison.
|
||||
assertEquals(config.toString(), configFromParcel.toString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
/*
|
||||
* Verify WifiP2pConfig invalidate API
|
||||
*/
|
||||
public void testInvalidate() throws Exception {
|
||||
WifiP2pConfig config = new WifiP2pConfig();
|
||||
config.deviceAddress = DEVICE_ADDRESS;
|
||||
config.invalidate();
|
||||
assertEquals("", config.deviceAddress);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.WifiP2pDeviceList}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pDeviceListTest {
|
||||
|
||||
private static final WifiP2pDevice TEST_DEVICE_1 = new WifiP2pDevice("aa:bb:cc:dd:ee:ff");
|
||||
private static final WifiP2pDevice TEST_DEVICE_2 = new WifiP2pDevice("aa:bb:cc:dd:ee:f1");
|
||||
private static final WifiP2pDevice TEST_DEVICE_3 = new WifiP2pDevice("11:22:33:44:55:66");
|
||||
private static final WifiP2pDevice TEST_DEVICE_4 = new WifiP2pDevice("a0:b0:c0:d0:e0:f0");
|
||||
|
||||
/**
|
||||
* Verify basic operations.
|
||||
*/
|
||||
@Test
|
||||
public void testListOperations() throws Exception {
|
||||
WifiP2pDeviceList list = new WifiP2pDeviceList();
|
||||
list.update(TEST_DEVICE_1);
|
||||
list.update(TEST_DEVICE_2);
|
||||
list.update(TEST_DEVICE_3);
|
||||
assertEquals(3, list.getDeviceList().size());
|
||||
|
||||
assertEquals(TEST_DEVICE_1, list.get(TEST_DEVICE_1.deviceAddress));
|
||||
assertEquals(null, list.get(TEST_DEVICE_4.deviceAddress));
|
||||
|
||||
list.remove(TEST_DEVICE_2.deviceAddress);
|
||||
assertEquals(null, list.get(TEST_DEVICE_2.deviceAddress));
|
||||
|
||||
list.remove(TEST_DEVICE_3);
|
||||
assertEquals(null, list.get(TEST_DEVICE_3.deviceAddress));
|
||||
|
||||
assertEquals(1, list.getDeviceList().size());
|
||||
|
||||
list.clear();
|
||||
assertEquals(0, list.getDeviceList().size());
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
list.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
WifiP2pDeviceList fromParcel = WifiP2pDeviceList.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
assertEquals(list.toString(), fromParcel.toString());
|
||||
}
|
||||
}
|
||||
115
wifi/tests/src/android/net/wifi/p2p/WifiP2pGroupListTest.java
Normal file
115
wifi/tests/src/android/net/wifi/p2p/WifiP2pGroupListTest.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.WifiP2pGroupList}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pGroupListTest {
|
||||
|
||||
private static final WifiP2pDevice TEST_GROUP_OWNER_1 = new WifiP2pDevice("aa:bb:cc:dd:ee:f0");
|
||||
private static final WifiP2pDevice TEST_GROUP_OWNER_2 = new WifiP2pDevice("aa:bb:cc:dd:ee:f1");
|
||||
private static final WifiP2pDevice TEST_GROUP_OWNER_3 = new WifiP2pDevice("aa:bb:cc:dd:ee:f2");
|
||||
private static final WifiP2pDevice TEST_GROUP_OWNER_OTHER =
|
||||
new WifiP2pDevice("aa:bb:cc:dd:ee:f3");
|
||||
|
||||
private WifiP2pGroup mTestGroup1;
|
||||
private WifiP2pGroup mTestGroup2;
|
||||
private WifiP2pGroup mTestGroup3;
|
||||
private WifiP2pGroup mTestGroup4;
|
||||
|
||||
private WifiP2pGroup createGroup(
|
||||
int networkId, String networkName,
|
||||
String passphrase, boolean isGo,
|
||||
WifiP2pDevice goDev) {
|
||||
WifiP2pGroup group = new WifiP2pGroup();
|
||||
group.setNetworkId(networkId);
|
||||
group.setNetworkName(networkName);
|
||||
group.setPassphrase(passphrase);
|
||||
group.setIsGroupOwner(isGo);
|
||||
group.setOwner(goDev);
|
||||
return group;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mTestGroup1 = createGroup(0, "testGroup1", "12345678", false, TEST_GROUP_OWNER_1);
|
||||
mTestGroup2 = createGroup(1, "testGroup2", "12345678", true, TEST_GROUP_OWNER_2);
|
||||
mTestGroup3 = createGroup(2, "testGroup3", "12345678", false, TEST_GROUP_OWNER_3);
|
||||
mTestGroup4 = createGroup(3, "testGroup4", "12345678", false, TEST_GROUP_OWNER_1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify basic operations.
|
||||
*/
|
||||
@Test
|
||||
public void testListOperations() throws Exception {
|
||||
WifiP2pGroupList list = new WifiP2pGroupList();
|
||||
list.add(mTestGroup1);
|
||||
list.add(mTestGroup2);
|
||||
list.add(mTestGroup3);
|
||||
list.add(mTestGroup4);
|
||||
assertEquals(4, list.getGroupList().size());
|
||||
|
||||
// in list
|
||||
assertEquals(mTestGroup2.getNetworkId(),
|
||||
list.getNetworkId(TEST_GROUP_OWNER_2.deviceAddress));
|
||||
assertEquals(TEST_GROUP_OWNER_2.deviceAddress,
|
||||
list.getOwnerAddr(mTestGroup2.getNetworkId()));
|
||||
// not in list
|
||||
assertEquals(-1, list.getNetworkId(TEST_GROUP_OWNER_OTHER.deviceAddress));
|
||||
// if there are groups with the same GO, return the first one found.
|
||||
assertEquals(mTestGroup1.getNetworkId(),
|
||||
list.getNetworkId(TEST_GROUP_OWNER_1.deviceAddress));
|
||||
// identify groups with the same GO, but different network names.
|
||||
assertEquals(mTestGroup4.getNetworkId(),
|
||||
list.getNetworkId(TEST_GROUP_OWNER_1.deviceAddress, "testGroup4"));
|
||||
|
||||
list.remove(mTestGroup3.getNetworkId());
|
||||
assertEquals(-1, list.getNetworkId(TEST_GROUP_OWNER_3.deviceAddress));
|
||||
assertFalse(list.contains(mTestGroup3.getNetworkId()));
|
||||
|
||||
assertEquals(3, list.getGroupList().size());
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
list.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
WifiP2pGroupList fromParcel = WifiP2pGroupList.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
assertEquals(list.toString(), fromParcel.toString());
|
||||
|
||||
list.clear();
|
||||
assertEquals(0, list.getGroupList().size());
|
||||
|
||||
}
|
||||
}
|
||||
92
wifi/tests/src/android/net/wifi/p2p/WifiP2pGroupTest.java
Normal file
92
wifi/tests/src/android/net/wifi/p2p/WifiP2pGroupTest.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.WifiP2pGroup}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pGroupTest {
|
||||
|
||||
private static final String INTERFACE = "p2p-p2p0-3";
|
||||
private static final int NETWORK_ID = 9;
|
||||
private static final String NETWORK_NAME = "DIRECT-xy-Hello";
|
||||
private static final String PASSPHRASE = "HelloWorld";
|
||||
private static final WifiP2pDevice GROUP_OWNER = new WifiP2pDevice("de:ad:be:ef:00:01");
|
||||
private static final int FREQUENCY = 5300;
|
||||
private static final WifiP2pDevice CLIENT_1 = new WifiP2pDevice("aa:bb:cc:dd:ee:01");
|
||||
private static final WifiP2pDevice CLIENT_2 = new WifiP2pDevice("aa:bb:cc:dd:ee:02");
|
||||
|
||||
/**
|
||||
* Verify setter/getter functions.
|
||||
*/
|
||||
@Test
|
||||
public void testSetterGetter() throws Exception {
|
||||
WifiP2pGroup group = new WifiP2pGroup();
|
||||
|
||||
group.setInterface(INTERFACE);
|
||||
group.setNetworkId(NETWORK_ID);
|
||||
group.setNetworkName(NETWORK_NAME);
|
||||
group.setPassphrase(PASSPHRASE);
|
||||
group.setIsGroupOwner(false);
|
||||
group.setOwner(GROUP_OWNER);
|
||||
group.setFrequency(FREQUENCY);
|
||||
group.addClient(CLIENT_1.deviceAddress);
|
||||
group.addClient(CLIENT_2);
|
||||
|
||||
assertEquals(INTERFACE, group.getInterface());
|
||||
assertEquals(NETWORK_ID, group.getNetworkId());
|
||||
assertEquals(NETWORK_NAME, group.getNetworkName());
|
||||
assertEquals(PASSPHRASE, group.getPassphrase());
|
||||
assertFalse(group.isGroupOwner());
|
||||
assertEquals(GROUP_OWNER, group.getOwner());
|
||||
assertEquals(FREQUENCY, group.getFrequency());
|
||||
|
||||
assertFalse(group.isClientListEmpty());
|
||||
assertTrue(group.contains(CLIENT_1));
|
||||
|
||||
assertEquals(2, group.getClientList().size());
|
||||
|
||||
group.removeClient(CLIENT_1);
|
||||
group.removeClient(CLIENT_2.deviceAddress);
|
||||
assertFalse(group.contains(CLIENT_1));
|
||||
assertTrue(group.isClientListEmpty());
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
group.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
WifiP2pGroup fromParcel = WifiP2pGroup.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
assertEquals(group.toString(), fromParcel.toString());
|
||||
|
||||
}
|
||||
}
|
||||
83
wifi/tests/src/android/net/wifi/p2p/WifiP2pInfoTest.java
Normal file
83
wifi/tests/src/android/net/wifi/p2p/WifiP2pInfoTest.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.WifiP2pInfo}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pInfoTest {
|
||||
|
||||
private InetAddress mGroupOnwerIpv4Address;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
byte[] ipv4 = {(byte) 192, (byte) 168, (byte) 49, (byte) 1};
|
||||
mGroupOnwerIpv4Address = InetAddress.getByAddress(ipv4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies copy constructor.
|
||||
*/
|
||||
@Test
|
||||
public void testCopyOperator() throws Exception {
|
||||
WifiP2pInfo info = new WifiP2pInfo();
|
||||
info.groupFormed = true;
|
||||
info.isGroupOwner = true;
|
||||
info.groupOwnerAddress = mGroupOnwerIpv4Address;
|
||||
|
||||
WifiP2pInfo copiedInfo = new WifiP2pInfo(info);
|
||||
|
||||
// no equals operator, use toString for data comparison.
|
||||
assertEquals(info.toString(), copiedInfo.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies parcel serialization/deserialization.
|
||||
*/
|
||||
@Test
|
||||
public void testParcelOperation() throws Exception {
|
||||
WifiP2pInfo info = new WifiP2pInfo();
|
||||
info.groupFormed = true;
|
||||
info.isGroupOwner = true;
|
||||
info.groupOwnerAddress = mGroupOnwerIpv4Address;
|
||||
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
info.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
WifiP2pInfo fromParcel = WifiP2pInfo.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
// no equals operator, use toString for data comparison.
|
||||
assertEquals(info.toString(), fromParcel.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.WifiP2pProvDiscEvent}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pProvDiscEventTest {
|
||||
|
||||
private static final String DEVICE_ADDRESS = "aa:bb:cc:dd:ee:ff";
|
||||
private static final String EVENT_PBC_REQ_STRING = "P2P-PROV-DISC-PBC-REQ";
|
||||
private static final String EVENT_PBC_RSP_STRING = "P2P-PROV-DISC-PBC-RESP";
|
||||
private static final String EVENT_ENTER_PIN_STRING = "P2P-PROV-DISC-ENTER-PIN";
|
||||
private static final String EVENT_SHOW_PIN_STRING = "P2P-PROV-DISC-SHOW-PIN";
|
||||
private static final String TEST_PIN = "44490607";
|
||||
|
||||
/**
|
||||
* Test parsing PBC request event.
|
||||
*/
|
||||
@Test
|
||||
public void testPbcReqEvent() throws Exception {
|
||||
WifiP2pProvDiscEvent event =
|
||||
new WifiP2pProvDiscEvent(EVENT_PBC_REQ_STRING + " " + DEVICE_ADDRESS);
|
||||
assertEquals(WifiP2pProvDiscEvent.PBC_REQ, event.event);
|
||||
assertEquals(DEVICE_ADDRESS, event.device.deviceAddress);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test parsing PBC response event.
|
||||
*/
|
||||
@Test
|
||||
public void testPbcRespEvent() throws Exception {
|
||||
WifiP2pProvDiscEvent event =
|
||||
new WifiP2pProvDiscEvent(EVENT_PBC_RSP_STRING + " " + DEVICE_ADDRESS);
|
||||
assertEquals(WifiP2pProvDiscEvent.PBC_RSP, event.event);
|
||||
assertEquals(DEVICE_ADDRESS, event.device.deviceAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing ENTER-PIN event.
|
||||
*/
|
||||
@Test
|
||||
public void testEnterPinEvent() throws Exception {
|
||||
WifiP2pProvDiscEvent event =
|
||||
new WifiP2pProvDiscEvent(EVENT_ENTER_PIN_STRING + " " + DEVICE_ADDRESS);
|
||||
assertEquals(WifiP2pProvDiscEvent.ENTER_PIN, event.event);
|
||||
assertEquals(DEVICE_ADDRESS, event.device.deviceAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing SHOW-PIN event.
|
||||
*/
|
||||
@Test
|
||||
public void testShowPinEvent() throws Exception {
|
||||
WifiP2pProvDiscEvent event =
|
||||
new WifiP2pProvDiscEvent(
|
||||
EVENT_SHOW_PIN_STRING + " " + DEVICE_ADDRESS + " " + TEST_PIN);
|
||||
assertEquals(WifiP2pProvDiscEvent.SHOW_PIN, event.event);
|
||||
assertEquals(DEVICE_ADDRESS, event.device.deviceAddress);
|
||||
assertEquals(TEST_PIN, event.pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing malformed input.
|
||||
*/
|
||||
@Test
|
||||
public void testMalformedInput() throws Exception {
|
||||
try {
|
||||
WifiP2pProvDiscEvent event = new WifiP2pProvDiscEvent("OneToken");
|
||||
fail("Should throw IllegalArgumentException exception.");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test parsing malformed event.
|
||||
*/
|
||||
@Test
|
||||
public void testMalformedEvent() throws Exception {
|
||||
try {
|
||||
WifiP2pProvDiscEvent event = new WifiP2pProvDiscEvent("XXX " + DEVICE_ADDRESS);
|
||||
fail("Should throw IllegalArgumentException exception.");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
}
|
||||
}
|
||||
110
wifi/tests/src/android/net/wifi/p2p/WifiP2pWfdInfoTest.java
Normal file
110
wifi/tests/src/android/net/wifi/p2p/WifiP2pWfdInfoTest.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.WifiP2pWfdInfo}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pWfdInfoTest {
|
||||
|
||||
private static final int TEST_CTRL_PORT = 9999;
|
||||
private static final int TEST_MAX_TPUT = 1024;
|
||||
|
||||
private WifiP2pWfdInfo mSourceInfo = new WifiP2pWfdInfo(
|
||||
0,
|
||||
TEST_CTRL_PORT,
|
||||
TEST_MAX_TPUT);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// initialize device info flags.
|
||||
mSourceInfo.setDeviceType(WifiP2pWfdInfo.WFD_SOURCE);
|
||||
mSourceInfo.setSessionAvailable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies setters/getters.
|
||||
*/
|
||||
@Test
|
||||
public void testSettersGetters() throws Exception {
|
||||
WifiP2pWfdInfo info = new WifiP2pWfdInfo();
|
||||
|
||||
info.setWfdEnabled(true);
|
||||
assertTrue(info.isWfdEnabled());
|
||||
|
||||
info.setDeviceType(WifiP2pWfdInfo.WFD_SOURCE);
|
||||
assertEquals(WifiP2pWfdInfo.WFD_SOURCE, info.getDeviceType());
|
||||
|
||||
info.setCoupledSinkSupportAtSource(true);
|
||||
assertTrue(info.isCoupledSinkSupportedAtSource());
|
||||
|
||||
info.setCoupledSinkSupportAtSink(true);
|
||||
assertTrue(info.isCoupledSinkSupportedAtSink());
|
||||
|
||||
info.setSessionAvailable(true);
|
||||
assertTrue(info.isSessionAvailable());
|
||||
|
||||
info.setControlPort(TEST_CTRL_PORT);
|
||||
assertEquals(TEST_CTRL_PORT, info.getControlPort());
|
||||
|
||||
info.setMaxThroughput(TEST_MAX_TPUT);
|
||||
assertEquals(TEST_MAX_TPUT, info.getMaxThroughput());
|
||||
|
||||
assertEquals("0018270f0400", info.getDeviceInfoHex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies copy constructor.
|
||||
*/
|
||||
@Test
|
||||
public void testCopyOperator() throws Exception {
|
||||
WifiP2pWfdInfo copiedInfo = new WifiP2pWfdInfo(mSourceInfo);
|
||||
|
||||
// no equals operator, use toString for data comparison.
|
||||
assertEquals(mSourceInfo.toString(), copiedInfo.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies parcel serialization/deserialization.
|
||||
*/
|
||||
@Test
|
||||
public void testParcelOperation() throws Exception {
|
||||
Parcel parcelW = Parcel.obtain();
|
||||
mSourceInfo.writeToParcel(parcelW, 0);
|
||||
byte[] bytes = parcelW.marshall();
|
||||
parcelW.recycle();
|
||||
|
||||
Parcel parcelR = Parcel.obtain();
|
||||
parcelR.unmarshall(bytes, 0, bytes.length);
|
||||
parcelR.setDataPosition(0);
|
||||
WifiP2pWfdInfo fromParcel = WifiP2pWfdInfo.CREATOR.createFromParcel(parcelR);
|
||||
|
||||
// no equals operator, use toString for data comparison.
|
||||
assertEquals(mSourceInfo.toString(), fromParcel.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p.nsd;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceInfo}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pDnsSdServiceInfoTest {
|
||||
|
||||
private static final String INSTANCE_NAME = "MyPrinter";
|
||||
private static final String SERVICE_TYPE = "_ipp._tcp";
|
||||
private static final String TXTRECORD_PROP_AVAILABLE = "available";
|
||||
private static final String TXTRECORD_PROP_AVAILABLE_VISABLE = "visable";
|
||||
|
||||
private Map<String, String> mTxtMap = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mTxtMap.put(TXTRECORD_PROP_AVAILABLE, TXTRECORD_PROP_AVAILABLE_VISABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify newInstance API
|
||||
*/
|
||||
@Test
|
||||
public void testNewInstance() throws Exception {
|
||||
WifiP2pDnsSdServiceInfo info = null;
|
||||
|
||||
// the least arguments
|
||||
info = WifiP2pDnsSdServiceInfo.newInstance(
|
||||
INSTANCE_NAME,
|
||||
SERVICE_TYPE,
|
||||
null);
|
||||
|
||||
// all arguments are given.
|
||||
info = WifiP2pDnsSdServiceInfo.newInstance(
|
||||
INSTANCE_NAME,
|
||||
SERVICE_TYPE,
|
||||
mTxtMap);
|
||||
|
||||
// failure case due to no instance name.
|
||||
try {
|
||||
info = WifiP2pDnsSdServiceInfo.newInstance(
|
||||
null,
|
||||
SERVICE_TYPE,
|
||||
null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
|
||||
// failure case due to no service type.
|
||||
try {
|
||||
info = WifiP2pDnsSdServiceInfo.newInstance(
|
||||
INSTANCE_NAME,
|
||||
null,
|
||||
null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p.nsd;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pDnsSdServiceRequestTest {
|
||||
|
||||
private static final String SERVICE_NAME = "MyPrinter";
|
||||
private static final String SERVICE_TYPE = "_ipp._tcp";
|
||||
|
||||
@Test
|
||||
public void testNewInstance() throws Exception {
|
||||
WifiP2pDnsSdServiceRequest request = null;
|
||||
|
||||
// default new instance
|
||||
request = WifiP2pDnsSdServiceRequest.newInstance();
|
||||
|
||||
// set service type
|
||||
request = WifiP2pDnsSdServiceRequest.newInstance(SERVICE_TYPE);
|
||||
|
||||
// set service type
|
||||
request = WifiP2pDnsSdServiceRequest.newInstance(SERVICE_NAME, SERVICE_TYPE);
|
||||
|
||||
// failure case due to null service type
|
||||
try {
|
||||
request = WifiP2pDnsSdServiceRequest.newInstance(null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
|
||||
// failure case due to null service name
|
||||
try {
|
||||
request = WifiP2pDnsSdServiceRequest.newInstance(SERVICE_NAME, null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
|
||||
// failure case due to null service type
|
||||
try {
|
||||
request = WifiP2pDnsSdServiceRequest.newInstance(null, SERVICE_TYPE);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p.nsd;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.nsd.WifiP2pUpnpServiceInfo}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pUpnpServiceInfoTest {
|
||||
|
||||
private static final String UUID = "6859dede-8574-59ab-9332-123456789012";
|
||||
private static final String DEVICE = "aa:bb:cc:dd:ee:ff";
|
||||
|
||||
private List<String> mServiceList = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mServiceList.add("urn:schemas-upnp-org:service:ContentDirectory:1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify newInstance API
|
||||
*/
|
||||
@Test
|
||||
public void testNewInstance() throws Exception {
|
||||
WifiP2pUpnpServiceInfo info = null;
|
||||
|
||||
// the least arguments
|
||||
info = WifiP2pUpnpServiceInfo.newInstance(
|
||||
UUID, DEVICE, null);
|
||||
|
||||
// all arguments are given.
|
||||
info = WifiP2pUpnpServiceInfo.newInstance(
|
||||
UUID, DEVICE, mServiceList);
|
||||
|
||||
// failure case due to no UUID.
|
||||
try {
|
||||
info = WifiP2pUpnpServiceInfo.newInstance(
|
||||
null, DEVICE, null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
|
||||
// failure case due to no device.
|
||||
try {
|
||||
info = WifiP2pUpnpServiceInfo.newInstance(
|
||||
UUID,
|
||||
null,
|
||||
null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.wifi.p2p.nsd;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test harness for {@link android.net.wifi.p2p.nsd.WifiP2pUpnpServiceRequest}
|
||||
*/
|
||||
@SmallTest
|
||||
public class WifiP2pUpnpServiceRequestTest {
|
||||
|
||||
@Test
|
||||
public void testNewInstance() throws Exception {
|
||||
WifiP2pUpnpServiceRequest request = null;
|
||||
|
||||
// Create a service discovery request to search all UPnP services.
|
||||
request = WifiP2pUpnpServiceRequest.newInstance();
|
||||
|
||||
// Create a service discovery request to search specified UPnP services.
|
||||
request = WifiP2pUpnpServiceRequest.newInstance("ssdp:all");
|
||||
|
||||
// failure case due to null target string
|
||||
try {
|
||||
request = WifiP2pUpnpServiceRequest.newInstance(null);
|
||||
fail("should throw IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected exception.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user