diff options
author | Roshan Pius <rpius@google.com> | 2020-11-23 08:11:08 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-12-23 00:19:17 -0800 |
commit | 3653444d0256c9c5fc560bb269f302281a32d749 (patch) | |
tree | 37d5a6ea579e1c69e70c49eb822540cb31ea9201 /wifi/tests/src | |
parent | 6c5626edfc621e190408101e95c225549afa9943 (diff) |
WifiInfo: Add equals implementation
This is needed for connectivity to compare TransportInfo instances.
Bug: 162602799
Test: atest android.net.wifi
Change-Id: I215b769339f68b76a1b2fa15f66c4527d184b696
Merged-In: I215b769339f68b76a1b2fa15f66c4527d184b696
Diffstat (limited to 'wifi/tests/src')
-rw-r--r-- | wifi/tests/src/android/net/wifi/WifiInfoTest.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/wifi/tests/src/android/net/wifi/WifiInfoTest.java b/wifi/tests/src/android/net/wifi/WifiInfoTest.java index 311bbc41b8fe..9787cc05ea24 100644 --- a/wifi/tests/src/android/net/wifi/WifiInfoTest.java +++ b/wifi/tests/src/android/net/wifi/WifiInfoTest.java @@ -17,6 +17,7 @@ package android.net.wifi; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; @@ -25,6 +26,8 @@ import android.os.Parcel; import androidx.test.filters.SmallTest; +import com.android.modules.utils.build.SdkLevel; + import org.junit.Test; import java.nio.charset.StandardCharsets; @@ -148,4 +151,82 @@ public class WifiInfoTest { assertEquals(TEST_RSSI, info2.getRssi()); assertEquals(TEST_NETWORK_ID2, info2.getNetworkId()); } + + @Test + public void testWifiInfoEquals() throws Exception { + WifiInfo.Builder builder = new WifiInfo.Builder() + .setSsid(TEST_SSID.getBytes(StandardCharsets.UTF_8)) + .setBssid(TEST_BSSID) + .setRssi(TEST_RSSI) + .setNetworkId(TEST_NETWORK_ID); + + WifiInfo info1 = builder.build(); + WifiInfo info2 = builder.build(); + if (SdkLevel.isAtLeastS()) { + assertEquals(info1, info2); + } else { + assertNotEquals(info1, info2); + } + + info1.setTrusted(false); + // Same behavior pre-S & post-S. + assertNotEquals(info1, info2); + + info2.setTrusted(false); + if (SdkLevel.isAtLeastS()) { + assertEquals(info1, info2); + } else { + assertNotEquals(info1, info2); + } + + info1.setSSID(WifiSsid.createFromHex(null)); + // Same behavior pre-S & post-S. + assertNotEquals(info1, info2); + + info2.setSSID(WifiSsid.createFromHex(null)); + if (SdkLevel.isAtLeastS()) { + assertEquals(info1, info2); + } else { + assertNotEquals(info1, info2); + } + } + + @Test + public void testWifiInfoHashcode() throws Exception { + WifiInfo.Builder builder = new WifiInfo.Builder() + .setSsid(TEST_SSID.getBytes(StandardCharsets.UTF_8)) + .setBssid(TEST_BSSID) + .setRssi(TEST_RSSI) + .setNetworkId(TEST_NETWORK_ID); + + WifiInfo info1 = builder.build(); + WifiInfo info2 = builder.build(); + if (SdkLevel.isAtLeastS()) { + assertEquals(info1.hashCode(), info2.hashCode()); + } else { + assertNotEquals(info1.hashCode(), info2.hashCode()); + } + + info1.setTrusted(false); + // Same behavior pre-S & post-S. + assertNotEquals(info1.hashCode(), info2.hashCode()); + + info2.setTrusted(false); + if (SdkLevel.isAtLeastS()) { + assertEquals(info1.hashCode(), info2.hashCode()); + } else { + assertNotEquals(info1.hashCode(), info2.hashCode()); + } + + info1.setSSID(WifiSsid.createFromHex(null)); + // Same behavior pre-S & post-S. + assertNotEquals(info1.hashCode(), info2.hashCode()); + + info2.setSSID(WifiSsid.createFromHex(null)); + if (SdkLevel.isAtLeastS()) { + assertEquals(info1.hashCode(), info2.hashCode()); + } else { + assertNotEquals(info1.hashCode(), info2.hashCode()); + } + } } |