Loading wifi/tests/src/android/net/wifi/p2p/WifiP2pConfigTest.java +44 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 */ Loading Loading @@ -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); } } wifi/tests/src/android/net/wifi/p2p/WifiP2pDeviceListTest.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * 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()); } } wifi/tests/src/android/net/wifi/p2p/nsd/WifiP2pUpnpServiceInfoTest.java 0 → 100644 +80 −0 Original line number Diff line number Diff line /* * 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. } } } wifi/tests/src/android/net/wifi/p2p/nsd/WifiP2pUpnpServiceRequestTest.java 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * 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. } } } Loading
wifi/tests/src/android/net/wifi/p2p/WifiP2pConfigTest.java +44 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 */ Loading Loading @@ -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); } }
wifi/tests/src/android/net/wifi/p2p/WifiP2pDeviceListTest.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * 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()); } }
wifi/tests/src/android/net/wifi/p2p/nsd/WifiP2pUpnpServiceInfoTest.java 0 → 100644 +80 −0 Original line number Diff line number Diff line /* * 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. } } }
wifi/tests/src/android/net/wifi/p2p/nsd/WifiP2pUpnpServiceRequestTest.java 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * 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. } } }