WifiManagerTest: Add CTS tests for WifiMigration builders

Bug: 150236894
Test: atest android.net.wifi.cts.WifiManagerTest
Change-Id: I8dd6049960baddbf5d6d237792af2f1bdcf0227c
This commit is contained in:
Roshan Pius
2020-03-02 09:13:20 -08:00
parent 1cd3aa88cb
commit 10dbe0d272
2 changed files with 108 additions and 2 deletions

View File

@@ -16,12 +16,12 @@
package android.net.wifi.cts;
import static com.google.common.truth.Truth.assertWithMessage;
import static android.net.NetworkCapabilitiesProto.TRANSPORT_WIFI;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import static android.net.wifi.WifiManager.TrafficStateCallback.DATA_ACTIVITY_INOUT;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.assertNotEquals;
import android.app.UiAutomation;

View File

@@ -0,0 +1,106 @@
/*
* Copyright (C) 2020 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.cts;
import static org.junit.Assert.assertNotNull;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiMigration;
import android.test.AndroidTestCase;
import java.util.Arrays;
import java.util.List;
public class WifiMigrationTest extends AndroidTestCase {
private static final String TEST_SSID_UNQUOTED = "testSsid1";
@Override
protected void setUp() throws Exception {
super.setUp();
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
return;
}
}
@Override
protected void tearDown() throws Exception {
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
super.tearDown();
return;
}
super.tearDown();
}
/**
* Tests {@link android.net.wifi.WifiMigration.ConfigStoreMigrationData} class.
*/
public void testWifiMigrationConfigStoreDataBuilder() throws Exception {
WifiConfiguration savedNetwork1 = new WifiConfiguration();
savedNetwork1.SSID = "\"test1\"";
WifiConfiguration savedNetwork2 = new WifiConfiguration();
savedNetwork1.SSID = "\"test2\"";
List<WifiConfiguration> savedNetworks = Arrays.asList(savedNetwork1, savedNetwork2);
SoftApConfiguration softApConfiguration = new SoftApConfiguration.Builder()
.setSsid("\"test3\"")
.build();
WifiMigration.ConfigStoreMigrationData migrationData =
new WifiMigration.ConfigStoreMigrationData.Builder()
.setUserSavedNetworkConfigurations(savedNetworks)
.setUserSoftApConfiguration(softApConfiguration)
.build();
assertNotNull(migrationData);
assertEquals(savedNetworks.size(),
migrationData.getUserSavedNetworkConfigurations().size());
assertEquals(savedNetwork1.SSID,
migrationData.getUserSavedNetworkConfigurations().get(0).SSID);
assertEquals(savedNetwork2.SSID,
migrationData.getUserSavedNetworkConfigurations().get(1).SSID);
assertEquals(softApConfiguration.getSsid(),
migrationData.getUserSoftApConfiguration().getSsid());
}
/**
* Tests {@link android.net.wifi.WifiMigration.ConfigStoreMigrationData} class.
*/
public void testWifiMigrationSettingsDataBuilder() throws Exception {
WifiMigration.SettingsMigrationData migrationData =
new WifiMigration.SettingsMigrationData.Builder()
.setScanAlwaysAvailable(true)
.setP2pFactoryResetPending(true)
.setScanThrottleEnabled(true)
.setSoftApTimeoutEnabled(true)
.setWakeUpEnabled(true)
.setVerboseLoggingEnabled(true)
.setP2pDeviceName(TEST_SSID_UNQUOTED)
.build();
assertNotNull(migrationData);
assertTrue(migrationData.isScanAlwaysAvailable());
assertTrue(migrationData.isP2pFactoryResetPending());
assertTrue(migrationData.isScanThrottleEnabled());
assertTrue(migrationData.isSoftApTimeoutEnabled());
assertTrue(migrationData.isWakeUpEnabled());
assertTrue(migrationData.isVerboseLoggingEnabled());
assertEquals(TEST_SSID_UNQUOTED, migrationData.getP2pDeviceName());
}
}