OSDN Git Service

[AWARE] Add unit test - fix hashing bug
authorEtan Cohen <etancohen@google.com>
Sat, 6 Apr 2019 17:21:37 +0000 (10:21 -0700)
committerEtan Cohen <etancohen@google.com>
Sun, 7 Apr 2019 05:28:35 +0000 (22:28 -0700)
Adding unit tests to verify hashing code uncovered a bug (hashing
arrays) - fixed.

Bug: 130051430
Test: atest android.net.wifi
Test: atest com.android.server.wifi
Test: ACTS ThroughputTest:test_iperf_single_ndp_aware_only_ib
Change-Id: I4c654dd656b4bd1bce8077c73c66f458d103bc86

wifi/java/android/net/wifi/aware/PublishConfig.java
wifi/java/android/net/wifi/aware/SubscribeConfig.java
wifi/java/android/net/wifi/aware/WifiAwareManager.java
wifi/tests/src/android/net/wifi/aware/WifiAwareManagerTest.java

index f0c7967..1886b7e 100644 (file)
@@ -172,8 +172,9 @@ public final class PublishConfig implements Parcelable {
 
     @Override
     public int hashCode() {
-        return Objects.hash(mServiceName, mServiceSpecificInfo, mMatchFilter, mPublishType, mTtlSec,
-                mEnableTerminateNotification, mEnableRanging);
+        return Objects.hash(Arrays.hashCode(mServiceName), Arrays.hashCode(mServiceSpecificInfo),
+                Arrays.hashCode(mMatchFilter), mPublishType, mTtlSec, mEnableTerminateNotification,
+                mEnableRanging);
     }
 
     /**
index f477490..f0f7581 100644 (file)
@@ -205,8 +205,10 @@ public final class SubscribeConfig implements Parcelable {
 
     @Override
     public int hashCode() {
-        int result = Objects.hash(mServiceName, mServiceSpecificInfo, mMatchFilter, mSubscribeType,
-                mTtlSec, mEnableTerminateNotification, mMinDistanceMmSet, mMaxDistanceMmSet);
+        int result = Objects.hash(Arrays.hashCode(mServiceName),
+                Arrays.hashCode(mServiceSpecificInfo), Arrays.hashCode(mMatchFilter),
+                mSubscribeType, mTtlSec, mEnableTerminateNotification, mMinDistanceMmSet,
+                mMaxDistanceMmSet);
 
         if (mMinDistanceMmSet) {
             result = Objects.hash(result, mMinDistanceMm);
index c9b0b12..41a412b 100644 (file)
@@ -406,7 +406,7 @@ public class WifiAwareManager {
 
         if (!WifiAwareUtils.isLegacyVersion(mContext, Build.VERSION_CODES.Q)) {
             throw new UnsupportedOperationException(
-                    "API not deprecated - use WifiAwareNetworkSpecifier.Builder");
+                    "API deprecated - use WifiAwareNetworkSpecifier.Builder");
         }
 
         if (role != WIFI_AWARE_DATA_PATH_ROLE_INITIATOR
index 905540e..52bb284 100644 (file)
@@ -709,6 +709,7 @@ public class WifiAwareManagerTest {
         ConfigRequest rereadConfigRequest = ConfigRequest.CREATOR.createFromParcel(parcelR);
 
         assertEquals(configRequest, rereadConfigRequest);
+        assertEquals(configRequest.hashCode(), rereadConfigRequest.hashCode());
     }
 
     /*
@@ -801,6 +802,7 @@ public class WifiAwareManagerTest {
         SubscribeConfig rereadSubscribeConfig = SubscribeConfig.CREATOR.createFromParcel(parcelR);
 
         assertEquals(subscribeConfig, rereadSubscribeConfig);
+        assertEquals(subscribeConfig.hashCode(), rereadSubscribeConfig.hashCode());
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -892,6 +894,7 @@ public class WifiAwareManagerTest {
         PublishConfig rereadPublishConfig = PublishConfig.CREATOR.createFromParcel(parcelR);
 
         assertEquals(publishConfig, rereadPublishConfig);
+        assertEquals(publishConfig.hashCode(), rereadPublishConfig.hashCode());
     }
 
     @Test(expected = IllegalArgumentException.class)