summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2016-11-15 08:52:54 -0800
committerPeter Qiu <zqiu@google.com>2016-11-22 11:38:05 -0800
commitdc6361c58a4eb2e7dd931ffe1cc0fb5129f004c9 (patch)
treeb3acd1d3676392546252c1ca9f66f7c92dad9507 /tests
parent5cee8f82a0845ecf28a8543ed3e169f44646bd4b (diff)
hotspot2: maintain a copy of PasspointConfiguration in PasspointProvider
This avoids the Passpoint configuration maintained in PasspointProvider from being updated by others. Bug: 32714562 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I7101ae0c1bcf70585343e6da5608d7fe1267e689
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java
new file mode 100644
index 000000000..3ff01bc30
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2016 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 com.android.server.wifi.hotspot2;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import android.net.wifi.hotspot2.PasspointConfiguration;
+import android.net.wifi.hotspot2.pps.HomeSP;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.hotspot2.PasspointProvider}.
+ */
+@SmallTest
+public class PasspointProviderTest {
+ PasspointProvider mProvider;
+
+ /**
+ * Verify that the configuration associated with the provider is the same or not the same
+ * as the expected configuration.
+ *
+ * @param expectedConfig The expected configuration
+ * @param equals Flag indicating equality or inequality check
+ */
+ private void verifyInstalledConfig(PasspointConfiguration expectedConfig, boolean equals) {
+ PasspointConfiguration actualConfig = mProvider.getConfig();
+ if (equals) {
+ assertTrue(actualConfig.equals(expectedConfig));
+ } else {
+ assertFalse(actualConfig.equals(expectedConfig));
+ }
+ }
+
+ /**
+ * Verify that modification to the configuration used for creating PasspointProvider
+ * will not change the configuration stored inside the PasspointProvider.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void verifyModifyOriginalConfig() throws Exception {
+ // Create a dummy PasspointConfiguration.
+ PasspointConfiguration config = new PasspointConfiguration();
+ config.homeSp = new HomeSP();
+ config.homeSp.fqdn = "test1";
+ mProvider = new PasspointProvider(config);
+ verifyInstalledConfig(config, true);
+
+ // Modify the original configuration, the configuration maintained by the provider
+ // should be unchanged.
+ config.homeSp.fqdn = "test2";
+ verifyInstalledConfig(config, false);
+ }
+
+ /**
+ * Verify that modification to the configuration retrieved from the PasspointProvider
+ * will not change the configuration stored inside the PasspointProvider.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void verifyModifyRetrievedConfig() throws Exception {
+ // Create a dummy PasspointConfiguration.
+ PasspointConfiguration config = new PasspointConfiguration();
+ config.homeSp = new HomeSP();
+ config.homeSp.fqdn = "test1";
+ mProvider = new PasspointProvider(config);
+ verifyInstalledConfig(config, true);
+
+ // Modify the retrieved configuration, verify the configuration maintained by the
+ // provider should be unchanged.
+ PasspointConfiguration retrievedConfig = mProvider.getConfig();
+ retrievedConfig.homeSp.fqdn = "test2";
+ verifyInstalledConfig(retrievedConfig, false);
+ }
+}