Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82ec520d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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
parents f9fae95c 83448724
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -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);
    }

}
+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());
    }
}
+115 −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 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 −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 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 −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.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());
    }
}
Loading